<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Shobhit Puri</title>
    <description>The latest articles on DEV Community by Shobhit Puri (@shobhit).</description>
    <link>https://dev.to/shobhit</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F831%2Fjfk_JwOa.jpg</url>
      <title>DEV Community: Shobhit Puri</title>
      <link>https://dev.to/shobhit</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/shobhit"/>
    <language>en</language>
    <item>
      <title>How to write your own git commands like "git refresh"?</title>
      <dc:creator>Shobhit Puri</dc:creator>
      <pubDate>Fri, 06 Oct 2017 04:29:34 +0000</pubDate>
      <link>https://dev.to/shobhit/git-refresh-4hn</link>
      <guid>https://dev.to/shobhit/git-refresh-4hn</guid>
      <description>&lt;h3&gt;
  
  
  &lt;strong&gt;Quick Summary&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Do you use git version control? If you are in Software Development, I'm sure you have used it at some point. Can you think of any actions that you perform using git many times a day? For example, I update my local code with remote master many times a day. This can involve a few steps each time. In this post, I will show you how you can write your own custom &lt;code&gt;git&lt;/code&gt; commands, in two simple steps. You'll be able to then club many git commands as one. At the end of the post, there is a link to a GitHub repository. There you can find many ready-to-use custom git commands like &lt;code&gt;git refresh&lt;/code&gt; and &lt;code&gt;git switch&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Introduction&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;As engineers, we have an inbuilt desire to simplify and automate tasks. While others might call it laziness, the aim is to reduce the effort involved in doing mundane tasks. Let us apply that to git actions and take an example of &lt;code&gt;git refresh&lt;/code&gt;. During development, you often reach a stage that you would like to remember. When that happens, it is a good idea to commit the changes and push the code to your remote branch. Before creating a commit, it is customary to update your local branch with remote base branch. This helps to avoid any conflicts when making a pull request. In big teams, the remote branch gets updated quite often causing your local branch to lag behind. So this step becomes even more necessary as teams grow in size. For doing the above task of updating the local with remote master, on an average you'd do the following six steps:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   # Stash the changes in the current branch
   git stash
   # Checkout master branch 
   git checkout master
   # Pull from remote master and rebase
   git pull --rebase origin master
   # Go back to the previous branch where you were working
   git checkout current-branch
   # Update current local branch from the local master
   git rebase master
   # Apply the stashed changes
   git stash apply
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;For a task that you perform many times a day, "There is got to be a better way. And there is Kevin!"&lt;/p&gt;

&lt;p&gt;
  &lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fug4d6int3hqrrcc6atkq.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fug4d6int3hqrrcc6atkq.gif" width="600" height="480"&gt;&lt;/a&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Creating Custom Command&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;For our example of &lt;code&gt;git refresh&lt;/code&gt;, we need to tell &lt;code&gt;git&lt;/code&gt; to update our current branch from remote master.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1&lt;/strong&gt;: Create a file called &lt;code&gt;git-refresh&lt;/code&gt;. Save the the file in a folder at &lt;code&gt;/Users/user/Documents/gitScripts&lt;/code&gt;. Write the following in the &lt;code&gt;git-refresh&lt;/code&gt; file. The comments explain the steps:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/bin/sh

# Check if params are enough to go ahead.
remoteBranch=$1
test -z "$remoteBranch" &amp;amp;&amp;amp; echo "ERROR: Please provide the source remote branch." 1&amp;gt;&amp;amp;2 &amp;amp;&amp;amp; exit 1

# Find which is your current branch
if currentBranch=$(git symbolic-ref --short -q HEAD)
then
    echo On branch "$currentBranch"
    echo "Pulling updates from the remote branch $remoteBranch ..."

    # Stash current changes
    git stash
    # Checkout remote branch from where you want to update. 
    git checkout "$remoteBranch"
    # Pull the branch to update it
    git pull --rebase origin "$remoteBranch"
    # Checkout current branch which you were on before.
    git checkout "$currentBranch"
    # Rebase the changes
    git rebase "$remoteBranch"
    # Apply the stashed changes
    git stash apply

    echo "Updated the $currentBranch with changes from $remoteBranch"
else
    echo ERROR: Cannot find the current branch!
fi
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Step 2&lt;/strong&gt;: Add the directory path to your environment &lt;code&gt;PATH&lt;/code&gt;. For Linux/Mac, you can edit your &lt;code&gt;bash_profile&lt;/code&gt;. Add following line in the beginning:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    #!/bin/bash
    # For git commands
    export PATH=$PATH:/Users/user/Documents/gitScripts
    # Other existing export statements.
    # End of file
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;code&gt;source&lt;/code&gt; the file to apply the changes:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    source ~/.bash_profile
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;And... done!&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Usage&lt;/strong&gt;
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git refresh master&lt;br&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  &lt;strong&gt;GitHub Repository&lt;/strong&gt;&lt;br&gt;
&lt;/h3&gt;

&lt;p&gt;Please find the scripts for custom commands in the following git repository. &lt;a href="https://github.com/shobhitpuri/git-refresh" rel="noopener noreferrer"&gt;https://github.com/shobhitpuri/git-refresh&lt;/a&gt;. Sample custom commands include &lt;code&gt;git refresh&lt;/code&gt;, &lt;code&gt;git switch&lt;/code&gt; and &lt;code&gt;git pushremote&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;You can create your own commands by following the above steps. Create a new file &lt;code&gt;git-yourcommand&lt;/code&gt; and write the commands in the shell script. You can pass the params as required. Feel free to write your feedback and let me know what awesome custom commands have you created.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;This post was first published on &lt;a href="http://www.shobhitpuri.com" rel="noopener noreferrer"&gt;shobhitpuri.com&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>git</category>
      <category>github</category>
      <category>beginners</category>
      <category>bash</category>
    </item>
    <item>
      <title>How to change the text and theme of Google's Sign-In button on Android?</title>
      <dc:creator>Shobhit Puri</dc:creator>
      <pubDate>Thu, 05 Oct 2017 10:32:20 +0000</pubDate>
      <link>https://dev.to/shobhit/how-to-change-text-and-theme-of-google-sign-in-button-android-6bf</link>
      <guid>https://dev.to/shobhit/how-to-change-text-and-theme-of-google-sign-in-button-android-6bf</guid>
      <description>&lt;h3&gt;
  
  
  Quick Summary
&lt;/h3&gt;

&lt;p&gt;In this post, I will show you how to change the text on Google's Sign-In button using standard &lt;code&gt;android:text&lt;/code&gt; attribute, which is missing from the Google's &lt;a href="https://developers.google.com/android/reference/com/google/android/gms/common/SignInButton" rel="noopener noreferrer"&gt;SignInButton&lt;/a&gt;. I'll also show you, how you can switch between dark and light button themes. At the end of the post, a ready to use small Android library is included along with a sample application to try the same. &lt;/p&gt;

&lt;h3&gt;
  
  
  Requirements
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Android Studio with SDK installed.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;minSdkVersion&lt;/code&gt; supported is &lt;code&gt;16&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Introduction
&lt;/h3&gt;

&lt;p&gt;Do you want to provide localization for the Google Sign-In button? Maybe you want to change the default "Sign In" text to "Sign in with Google". Or you want switch between "Sign in with Google" and "Sign up with Google" text based on whether it is a sign-in or sign-up flow. As you might already know, to set the text on an Android &lt;code&gt;Button&lt;/code&gt;, you can use &lt;code&gt;android:text="{string}"&lt;/code&gt; attribute in your layout XML. If you want to do the same for Google Sign-In, this attribute is not available. On Stackoverflow, there are obviously many questions like &lt;a href="https://stackoverflow.com/questions/18040815/can-i-edit-the-text-of-sign-in-button-on-google" rel="noopener noreferrer"&gt;Can I edit the text of sign in button on Google?&lt;/a&gt;, which have been asked for this problem. Most of the existing answers were hacks at the time of writing. &lt;/p&gt;

&lt;p&gt;Follow along as I show you how you can use a very small library, created using &lt;a href="https://developers.google.com/identity/sign-in/android/custom-button" rel="noopener noreferrer"&gt;Google's recommended way to customize the SignInButton&lt;/a&gt;, that will enable you to use &lt;code&gt;android:text&lt;/code&gt; attribute to set any text on the button. The library also enables you to change the theme of the button to light or dark easily.&lt;/p&gt;

&lt;h3&gt;
  
  
  Usage
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Add the following to your &lt;code&gt;app&lt;/code&gt; module level &lt;code&gt;build.gradle&lt;/code&gt; file:&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dependencies {
    implementation 'com.github.shobhitpuri:custom-google-signin-button:2.0.0'
}
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Also, add the following in the top-level build.gradle file:&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;allprojects {
    repositories {
        google()
        maven { url "https://jitpack.io" }
        mavenCentral()
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;In your XML Layout, have the following:&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;RelativeLayout
    ...
    xmlns:app="http://schemas.android.com/apk/res-auto"&amp;gt;

    &amp;lt;com.shobhitpuri.custombuttons.GoogleSignInButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:text="@string/google_sign_up"
        app:isDarkTheme="true" /&amp;gt;
&amp;lt;/RelativeLayout&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Library Options
&lt;/h3&gt;

&lt;p&gt;If you notice the XML, there are two attributes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;app:isDarkTheme="{Boolean}"&lt;/code&gt; : This is to enable you to switch between the light (gray-white) theme and the dark (blue) theme for the button. The library handles changing the text color, background color and color change on button press based on Google's recommended guidelines.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;android:text="{string}"&lt;/code&gt;: This sets the text on the custom button.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Light Theme&lt;/th&gt;
&lt;th&gt;Dark Theme&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fheyd592litwz1a3ix6cf.png" alt="Google Sign-In Light" width="750" height="310"&gt;&lt;/td&gt;
&lt;td&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fciu1o0hzn2gfrobe5o3m.png" alt="Google Sign-In Dark" width="745" height="310"&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  Why a library?
&lt;/h3&gt;

&lt;p&gt;"Why create a library for this? Aren't there already tons of libraries already?", you would say. This library was result of the issues I faced when trying to set text on the &lt;code&gt;SignInButton&lt;/code&gt;. I don't like using hacks and since you are here, this far in the article, I would assume you don't either. If the underlying implementation of Google's &lt;code&gt;SignInButton&lt;/code&gt; changes, the hack would break. The ideal Google recommended solution from the documentation is to create a custom button as mentioned on &lt;a href="https://developers.google.com/identity/sign-in/android/custom-button" rel="noopener noreferrer"&gt;Customizing the Sign-In Button.&lt;/a&gt; It specifies the &lt;a href="https://developers.google.com/identity/branding-guidelines#sign-in-button" rel="noopener noreferrer"&gt;branding guidelines&lt;/a&gt; which includes using custom icons and images for the button, setting specific text size, paddings and other do's and don'ts for the logo.&lt;/p&gt;

&lt;p&gt;As you can see the ideal solution involves some extra work. Instead of creating a custom button just for my usage, I wanted to write some re-usable code, which I can drag and drop in any of my projects and it would work out of the box. That's why I decided to create a small 3.93 KB library, so that anyone facing this issue need not spend time implementing a custom solution and can get the custom Google Sign-In button working in no time.&lt;/p&gt;

&lt;h3&gt;
  
  
  Source Code and Sample Android Application
&lt;/h3&gt;

&lt;p&gt;You can find the implementation of the library and a sample Android application that is using the library here: &lt;a href="https://github.com/shobhitpuri/custom-google-signin-button" rel="noopener noreferrer"&gt;&lt;/a&gt;&lt;a href="https://github.com/shobhitpuri/custom-google-signin-button" rel="noopener noreferrer"&gt;https://github.com/shobhitpuri/custom-google-signin-button&lt;/a&gt;. Feel free to give any feedback on the article or library. If you come across any issues, you are more than welcome to create an issue or open a pull request.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Note: The images used in this article are trademark of Google. They have been just used for instructional purposes.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>ui</category>
      <category>development</category>
      <category>library</category>
      <category>android</category>
    </item>
  </channel>
</rss>
