Skip to content

Instantly share code, notes, and snippets.

@gabrielbauman
gabrielbauman / gist:5689446
Created June 1, 2013 06:07
A Maven profile that detects when the build is running on Heroku.
<profile>
<id>heroku</id>
<activation>
<activeByDefault>false</activeByDefault>
<property>
<name>env.HOME</name>
<value>/app</value>
</property>
</activation>
<!-- Do Heroku-specific stuff here -->
@gabrielbauman
gabrielbauman / litecoin_balance
Created December 12, 2013 21:22
Quick, dumb script that outputs the balance of a Litecoin address.
#!/bin/sh
#
# Check the balance of a Litecoin address by querying explorer.litecoin.net.
# Drop this into /usr/local/bin and make it executable.
# Needs curl.
#
# Helpful? LWSHbKEHT18WX93zrSjBhc1AnxC4UCmbCt
if [ "$#" -ne 1 ]; then echo "Usage: litecoin_balance LTC_ADDRESS"; exit 1; fi;
@gabrielbauman
gabrielbauman / update_unblockus.sh
Created March 10, 2014 08:31
Run this whenever your IP changes to tell unblock.us about your new address. Fixes weird Netflix "internal errors", the Roku android app not signing in properly, and other glitchiness.
#!/bin/bash
# Set this to the email address you use with unblock.us.
UNBLOCKUS_EMAIL="[email protected]"
curl \
--url http://check.unblock-us.com/ \
--form "validated=1&email=${UNBLOCKUS_EMAIL}&rid=0" \
--user-agent "Mozilla/5.0 (X11; Linux x86_64; rv:27.0) Gecko/20100101 Fi27.0" -q \
&> /dev/null
@gabrielbauman
gabrielbauman / OpenshiftHaproxyFilter.java
Created May 16, 2014 13:58
Openshift's haproxy hits '/' every 2 seconds with a null user agent to see if your scalable app is up. If "/" does not respond with a 200 OK, haproxy marks the server as down even if it's actually up. This filter generates an empty 200 OK when it detects a haproxy ping..
package com.gabrielbauman.gists;
import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebFilter(urlPatterns = "/")
public class OpenshiftHaproxyFilter implements Filter {
@gabrielbauman
gabrielbauman / CardType.java
Last active December 13, 2023 04:21
A Java enum representing credit card types (Visa, Mastercard etc) that can detect card type from a credit card number.
package com.gabrielbauman.gist;
import java.util.regex.Pattern;
public enum CardType {
UNKNOWN,
VISA("^4[0-9]{12}(?:[0-9]{3}){0,2}$"),
MASTERCARD("^(?:5[1-5]|2(?!2([01]|20)|7(2[1-9]|3))[2-7])\\d{14}$"),
AMERICAN_EXPRESS("^3[47][0-9]{13}$"),

Keybase proof

I hereby claim:

  • I am GabrielBauman on github.
  • I am gabrielbauman (https://keybase.io/gabrielbauman) on keybase.
  • I have a public key whose fingerprint is 85C7 1A0E E159 9F31 F7BF 9142 A868 647F BD24 2F13

To claim this, I am signing this object:

@gabrielbauman
gabrielbauman / README.md
Created November 15, 2017 23:53 — forked from aldur/README.md
OnePlusRoot

Root OnePlus5 without unlocking the bootloader

Gain adb root.

$ adb shell am start -n com.android.engineeringmode/.qualcomm.DiagEnabled --es "code" "angela"

Download Magisk-v14.0 and extract it somewhere. Download MagiskManager.

@gabrielbauman
gabrielbauman / EnumStateMachine.java
Created July 10, 2019 21:49
A very simple (but useful) method of getting basic finite state machine behaviour using a Java enum.
package com.gabrielbauman.gist;
import java.util.Arrays;
/**
* A very simple (but useful) method of getting basic finite state machine behaviour using a Java enum.
*
* <code>
* EnumStateMachine state = NEUTRAL;
* state = state.transitionTo(FIRST);
@gabrielbauman
gabrielbauman / Dockerfile
Last active October 18, 2024 21:09
Multi-stage docker build for Java/Maven apps
# Cache maven dependencies as an intermediate docker image
# (This only happens when pom.xml changes or you clear your docker image cache)
FROM maven:3-adoptopenjdk-15 as dependencies
COPY pom.xml /build/
WORKDIR /build/
RUN mvn --batch-mode dependency:go-offline dependency:resolve-plugins
# Build the app using Maven and the cached dependencies
# (This only happens when your source code changes or you clear your docker image cache)
# Should work offline, but https://issues.apache.org/jira/browse/MDEP-82
#!/bin/bash
# Drop this script in /usr/local/bin and run it with sudo to install/update to the latest maven. Keeps older versions around just in case.
# Works for me on Ubuntu, YMMV.
set -e
# Make sure we can write to /opt
if [ ! -w "/opt" ]; then
echo "/opt is not writeable. Try using sudo!"