Category: Code Snippet

  • Git How-To: Squash commits in one line

    Adding this here in case I need to refer to it in the future. git reset –soft HEAD~3 && git commit Where ~3 means squashing last 3 commits into one.

  • Selenium: How to assert a WebElement that doesn’t exist

    ,

    Just in case you need to assert that a WebElement doesn’t exist, here’s a code snippet that you can use. Java public int isElementPresent(String xpath) {     return  driver.findElements(By.xpath(xpath)).size(); } Cucumber @Then("^I expect to see the link On the page$") public void iExpectToSeeTheLinkOnThePage() {     assertTrue(demoPage.isElementPresent() > 1); }

  • Java: One-liner check if you have the JCE Unlimited Strength Jurisdiction Policy

    ,

    In case you installed the the “stronger” Java Crytography Extension, you can check with: $JAVA_HOME/bin/jrunscript -e 'print (javax.crypto.Cipher.getMaxAllowedKeyLength("RC5") >= 256);'

  • 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…

  • 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;…

  • 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…