Skip to content

Instantly share code, notes, and snippets.

View josefdlange's full-sized avatar
🌱

Joey Lange josefdlange

🌱
View GitHub Profile
@josefdlange
josefdlange / tests.sh
Last active December 10, 2015 23:41
Show an OS X Notification when tests are complete
#!/bin/bash
# Run your tests and throw the return code into a variable.
RESULT=$(python -m tests.__init__ $1)
# Only if osascript exists (AKA only on OS X)
if type "osascript" > /dev/null; then
SUCCESS="Successful"
MESSAGE="All Tests Complete"
# This is a pretty lazy way to do mosh tunnelling, but it works.
mosh user@host.that.is.public.com -- mosh user2@host.that.is.private.com
# You can also do the internal session as SSH, since that connection is probably pretty solid and not subject to broken pipes.
mosh user@host.that.is.public.com -- ssh user2@host.that.is.private.com
@josefdlange
josefdlange / hook.rb
Created May 12, 2016 18:11 — forked from asimihsan/hook.rb
Hook for letsencrypt.sh to do DNS challenges
#!/usr/bin/env ruby
require 'aws-sdk'
require 'pry'
require 'awesome_print'
# ------------------------------------------------------------------------------
# Credentials
# ------------------------------------------------------------------------------
# pick up AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY by default from
@josefdlange
josefdlange / use_editor.py
Created May 17, 2016 15:50
Edit Python variable in $EDITOR, useful for modification of large data structure files in the middle of a CLI.
import os, sys, tempfile
def use_editor(text):
"""
Write out text to a temp file, instruct the system to open it in an editor,
and when control is returned to us, re-open that temp file and return its contents.
"""
tmp = tempfile.NamedTemporaryFile(delete=False)
tmp.write(text)
tmp.seek(0)
// This is _definitely_ my own implementation of rangeCheck and no one else's. Definitely not infringing on anything.
private static void rangeCheck(int arrayLen, int fromIndex, int toIndex) {
if (fromIndex > toIndex)
throw new IllegalArgumentException("fromIndex(" + fromIndex +") > toIndex(" + toIndex+")");
if (fromIndex < 0)
throw new ArrayIndexOutOfBoundsException(fromIndex);
if (toIndex > arrayLen)
throw new ArrayIndexOutOfBoundsException(toIndex);
}
@josefdlange
josefdlange / .bashrc
Created May 24, 2016 21:19
Manners Shell (bash only)
# Get bash-preexec first:
# curl https://raw.githubusercontent.com/rcaloras/bash-preexec/master/bash-preexec.sh -o ~/.bash-preexec.sh
source ~/.bash-preexec.sh
preexec() {
python ~/.please.py
}
@josefdlange
josefdlange / jerkins-check.py
Last active May 30, 2016 03:12
Simple script to pull Jenkins build status
#!/usr/bin/env python
"""
This script is pretty specific to my use case but perhaps someone else might find it useful.
I have two Jenkins jobs, and that's what this script supports displaying:
1) Build on every commit to my `development` branch of my project,
2) Build on every PR to the `development` branch (using https://wiki.jenkins-ci.org/display/JENKINS/GitHub+pull+request+builder+plugin)
Requirements:
@josefdlange
josefdlange / # gcc - 2016-06-20_12-39-26.txt
Created June 20, 2016 17:59
gcc on Mac OS X 10.12 - Homebrew build logs
Homebrew build logs for gcc on Mac OS X 10.12
Build date: 2016-06-20 12:39:26
@josefdlange
josefdlange / # libspatialite - 2016-06-20_13-04-40.txt
Created June 20, 2016 18:23
libspatialite on Mac OS X 10.12 - Homebrew build logs
Homebrew build logs for libspatialite on Mac OS X 10.12
Build date: 2016-06-20 13:04:40
@josefdlange
josefdlange / alpha2_guesser.py
Created June 24, 2016 19:38
Naive Country ISO3166 Alpha2 Resolver/Guesser
import difflib
import pycountry
def baseline_country(country_input, default="US"):
"""
Given a string input, return a two-character ISO3166 code.
"""
try:
if country_input and len(country_input) > 0:
if len(country_input) == 3: # Let's find the alpha2 for this probably-alpha3. Are there 3-letter countries?