How-to: Git Rebase

Adding here for my own purposes, but may be helpful to others. This rebases to master (or whatever branch) and then squashes all your commits into one commit! Sexy. 🙂


> git fetch --all
> git checkout [master]
> git pull
> git checkout [working branch name]
> git merge-base HEAD [master] 
> git reset --soft [hash] e.g.: 43e87200b8375fc5eba022ced353ab2917f2a746
> git status
> git commit -a -m "NOTES"
> git rebase [master]

Note: Only needed if conflicts between branch commit and master
> git add .
> git status
> git rebase --continue

> git diff origin/[working branch name]
> git push -f origin [working branch name]

Java code snippet: Enumeration to return String value

I probably should be adding this kind of stuff on GitHub, but I’m lazy. 🙂


public enum TokenType {

    TICKET("ticket"),
    UNKNOWN("unknown");

    private String tokenType;

    TokenType(String tokenType) {
        this.tokenType = tokenType;
    }

    public String getTokenType() {
        return tokenType;
    }

    public boolean isTicket() {
        return this == TICKET;
    }

    public boolean isValidType() {
        return this == TICKET;
    }

    public static TokenType getByTokenType(String tokenType) {
        String safeTokenType = (tokenType != null) ? tokenType.toLowerCase().trim() : "";

        for (TokenType tt : values()) {
            if (tt.getTokenType().equals(safeTokenType)) {
                return tt;
            }
        }

        return UNKNOWN;
    }

    public boolean isUnknown() {
        return this == UNKNOWN;
    }
}

Bash script to check health checks of multiple servers

I had to check over 20 servers to verify they were updated with a new build. The servers had a health check page that had this information along with whether the server was up-and-running. I wrote this quick-and-dirty bash script to do just that. 

for i in jetson1 jetson4; do for j in {1..10}; do curl -igX GET "http://app$j.tpa.$i.coresys.tmcs:8080/health/heartbeat"; done; done | grep -E '1.4.37' | grep -E "Overall Status: Success" | wc -l<br>

Hope this helps someone. Cheers!

My custom bash prompt

I wanted more information in my bash prompt, such as date/time and the directory I was in.  Here’s what it looks like:

bash_prompt

And this is what I added in my ~/.bash_profile:


PS1='${debian_chroot:+($debian_chroot)}\d \T &gt; \[$(tput sgr0)\]\[\033[01;32m\]\u@\h\[\033[00m\] : \[\033[01;34m\]\w\[\033[00m\]\n\$ '

Run source ~/.bash_profile and enjoy. 🙂

BTW, there’s also a website that you can use to create your own: http://bashrcgenerator.com/.