Skip to content

Instantly share code, notes, and snippets.

@davidoram
davidoram / convert-card-number-to-barcode.rb
Created February 26, 2024 22:15
Convert a FlyBuys card number to a barcode
View convert-card-number-to-barcode.rb
#!/usr/bin/env ruby
# Convert a FlyBuys card number to a barcode
def get_check_sum_from_thirteen_digit_code(card_number)
evens = 0
odds = 0
# Loop over all characters
card_number.chars.each_with_index do |character, index|
# Don't include the last character - 1
@davidoram
davidoram / main.go
Created October 6, 2022 00:53
Load test HTTP server with 'golang.org/x/time/rate' rate limiter
View main.go
package main
/*
Run via `go run main.go`
Test via `curl -i localhost:4000`
Load test via https://github.com/rakyll/hey
hey -n 500000 -c 50 -q 166 -m GET http://localhost:4000
Summary:
@davidoram
davidoram / server.go
Created March 3, 2022 02:33
Go server with ngrok
View server.go
package main
//
// Run the server
// go run server.go
//
// Expose via ngrok
// ngrok http 8080
//
//
View github_check_branch.sh
#/bin/bash
#
# Assumes you have run 'github_get_all.sh' to get the latest git repos for your org
#
# Note:This script will ONLY work reliably if you have run 'github_get_all.sh on an empty
# directory, so that all repos are freashly cloned and clean
#
# Iterate over all the github repos under the cwd, for each reports if
# branch1 is behind branch2
#
@davidoram
davidoram / github_get_all.sh
Last active November 11, 2018 23:50
Clone all github repositories for en organisation (git clone or git fetch --all)
View github_get_all.sh
#/bin/bash
#
# Checkout all repos, or brings branches up to date for an Org
#
read -d '' helptxt <<- "HELP_MSG"
Checkout all repos for a github organisation \\n
\\n
Usage:\\n
\\n
@davidoram
davidoram / schemaspy.sh
Last active May 31, 2018 01:44
Run dockerised schemaspy against a postgres database
View schemaspy.sh
#!/bin/bash
#
# - Run dockerised schemaspy against a postgres db
# - write the output to a host directory
# - Opens the generated website in your broswer
#
# Assumes you have already got the schemaspy docker image eg: `docker pull schemaspy/schemaspy:snapshot`
#
set -e
@davidoram
davidoram / unix-socket-to-tcp.sh
Created May 22, 2018 03:43
Create a UNIX socket connected to a TCP socket. Useful for connecting a rails app to a postgres instance that has been dockerized
View unix-socket-to-tcp.sh
#!/bin/bash
set -e
if [ $# -ne 3 ]; then
echo "Usage:"
echo ""
echo " `basename $0` <unix socket file> <host> <listen port>"
echo ""
echo "For example:"
View gist:ad5771f568b2e51db95828713f765765
VAGRANT_LOG=info vagrant init ubuntu/trusty64
INFO global: Vagrant version: 1.8.5
INFO global: Ruby version: 2.2.3
INFO global: RubyGems version: 2.4.5.1
INFO global: VAGRANT_LOG="info"
INFO global: VAGRANT_EXECUTABLE="/opt/vagrant/embedded/gems/gems/vagrant-1.8.5/bin/vagrant"
INFO global: VAGRANT_OLD_ENV_VAGRANT_LOG="info"
INFO global: VAGRANT_OLD_ENV_TERM="xterm-256color"
INFO global: VAGRANT_OLD_ENV_SSH_AUTH_SOCK="/private/tmp/com.apple.launchd.Kfz21yAIM0/Listeners"
INFO global: VAGRANT_OLD_ENV_LOGNAME="davidoram"
@davidoram
davidoram / gist:4eff788c3037d0ca358d
Created March 6, 2016 22:45
Snippet to find Sidekiq workers in the Retry queue, of a given worker type
View gist:4eff788c3037d0ca358d
query = Sidekiq::RetrySet.new
callbacks = query.select {|j| j.klass == 'CallbackNotificationWorker' }
@davidoram
davidoram / gist:4c9b1d2648e3e3ed5182
Created January 27, 2016 03:30
Print FB callstck in a method - drop this code in a method
View gist:4c9b1d2648e3e3ed5182
puts " -- > called blah_blah_method"
puts caller.select{ |f| f =~ /flybuys/ }