Skip to content

Instantly share code, notes, and snippets.

View jsok's full-sized avatar

Jonathan Sokolowski jsok

  • Sydney, Australia
  • 15:21 (UTC +11:00)
View GitHub Profile
@jsok
jsok / buildid-at-commit.sh
Created January 25, 2022 04:36
Go Build ID at a particular commit
#!/usr/bin/env bash
# Shows the build id (as reported by "go list" and "go tool buildid") of a package at a given git ref.
COMMIT=${1?Error: supply a commit}
PACKAGE=${2?Error: supply a package}
git checkout --detach "${COMMIT}" >/dev/null 2>&1
go build -o tmp "${PACKAGE}" >/dev/null 2>&1
echo -n "go tool buildid: "
go tool buildid tmp
@jsok
jsok / latency.sh
Last active October 19, 2015 10:39
Latency script
#!/bin/sh
for url in $(cat input.txt);do curl -s -o /dev/null -w '{"url": "%{url_effective}", "status": "%{http_code}", latency": "%{time_total}"}\n' $url; done | jq -s '.'
@jsok
jsok / clone.sh
Created September 14, 2015 00:31
Clone all repositories of an organisation
#!/bin/bash
set -e
# Usage:
# ORG=MyOrg OAUTH_TOKEN=token ./clone.sh
SSH_FILTER=".[] | .ssh_url"
REPOS=$(curl -s -H "Authorization: token ${OAUTH_TOKEN}" https://api.github.com/orgs/$ORG/repos | jq -r "$SSH_FILTER")
for repo in $REPOS; do
@jsok
jsok / limited.go
Created May 15, 2015 02:18
backoff: Limit the number of attempts using cenkalti/backoff
import "github.com/cenkalti/backoff"
type limitedAttempts struct {
limit int
attempts int
strategy backoff.BackOff
}
func NewLimitedAttempts(limit int, strategy backoff.BackOff) *limitedAttempts {
return &limitedAttempts{limit: limit, strategy: strategy}
@jsok
jsok / example.js
Created March 11, 2015 01:08
Protractor and deferred-angular-bootstrap load support
browser.get('/').then(function() {
return browser.waitForDeferredAngular();
});
@jsok
jsok / boto-dots.py
Created February 11, 2015 01:05
Using boto.s3.bucket when your bucket name as dot(s) in it
import logging
import socket, ssl
import re
import boto
from boto.s3.connection import S3Connection, OrdinaryCallingFormat
from boto.https_connection import CertValidatingHTTPSConnection
logging.basicConfig(level=logging.WARNING)
@jsok
jsok / phantom.py
Created March 12, 2014 06:42
Use PhantomJS and Python Selenium bindings to take screenshots of websites.
import StringIO
from selenium import webdriver
from PIL import Image
# Install instructions
#
# npm install phantomjs
# sudo apt-get install libjpeg-dev
# pip install selenium pillow
@jsok
jsok / alembic_minimum_revision.py
Created March 28, 2013 11:00
Python unittest decorator to skip tests is Alembic script revision criteria is not met.
from unittest import skipUnless
from alembic.config import Config
from alembic.script import ScriptDirectory
"""
Usage:
@minimum_revision_satisfied("5aa2dfb6e6a8")
def test_database_function(self):
pass
@jsok
jsok / locale_hack.py
Created February 3, 2013 06:03
A little hack to switch locales and override some locale conventions temporarily.
# Store the current locale
default_loc = locale.getlocale()
# Swap to some foreign locale, e.g. German
locale.setlocale(locale.LC_ALL, 'de_DE')
# Define a new localeconv() with some overrides
# see http://docs.python.org/2/library/locale.html#locale.localeconv
def _temp_localeconv(lc=locale.localeconv()):
lc.update({'decimal_point': ',', 'thousands_sep': '.'})
@jsok
jsok / README.md
Created December 7, 2012 12:50
factory_boy Sequence customisation

factory_boy Sequence

factory_boy allows you to define attributes as sequences, e.g.:

class MyFactory(factory.Factory):
    id = factory.Sequence(lambda n: "ID%s" % n)

By default, the sequence type is a str.