Skip to content

Instantly share code, notes, and snippets.

View bjjb's full-sized avatar

JJ Buckley bjjb

View GitHub Profile
@bjjb
bjjb / parmexp.sh
Last active March 9, 2018 19:32
Shows what result the `%`, `%%`, `#` and `##` modifiers will have on a shell parameter. I am constantly in need of this.
#!/bin/sh
# This program shows the result of applying the % and # shell parameter
# expansion modifiers to a parameter, for those who are constantly looking it
# up.
x=${1:?Usage: parmexp <parameter>}
echo "(hash dot star) ‥‥‥‥‥‥‥‥....... $x \${x#.*} → ${x#.*}"
echo "(hash hash dot star) .......... $x \${x##.*} → ${x##.*}"
echo "(percent dot star) ............ $x \${x%.*} → ${x%.*}"
@bjjb
bjjb / incrt.go
Last active March 14, 2017 23:09
An incrementing http client RoundTripper
import (
"bytes"
"fmt"
"io/ioutil"
"net/http"
"testing"
)
type incrt byte
@bjjb
bjjb / tmux
Last active October 30, 2015 15:36
tmux script for a web-app project
#!/usr/bin/env sh
name="My Cool Web App Project"
serve="npm start"
watch="node_modules/.bin/cake watch"
serve="npm start"
tmux has-session -t "$name"
if [ $? != 0 ]
then
@bjjb
bjjb / cfddns
Created January 20, 2015 23:40
#!/usr/bin/env python3
"""
Script to update this host's DNS entry on Cloudflare. Silently succeeds.
It requires you to have set the environment variables:
- CLOUDFLARE_API_KEY
- CLOUDFLARE_EMAIL
- CLOUDFLARE_HOSTNAME
# Example of using
require 'sqlite3'
require 'active_record'
ActiveRecord::Base.establish_connection("sqlite3::memory:")
conn = ActiveRecord::Base.connection
conn.create_table :users do |t|
t.string :name
end
conn.create_table :user_matches do |t|
t.references :sender
@bjjb
bjjb / fplookup.pl
Last active August 29, 2015 14:06
Program for looking up metadata for audio files
#!/usr/bin/env perl -CS
# Look up metadata for a tracks. Uses fpcalc, which comes with AcoustID
# Chromaprint (bitbucket.org/acoustid/chromaprint), the AcoustID web service,
# and the Musicbrainz web service.
#
# Run it with no arguments for help.
#
# For each file, it prints:
# * the filename
# * the result "score" (how likely a match it is, 0-1)
@bjjb
bjjb / profiler.rb
Created April 10, 2014 13:22
Object profiing, can be enabled/disabled with `kill -27 <pid>` (Ruby 2.1.1 version)
begin
require 'objspace'
trap("PROF") do
if $__PROFILING__
GC.start
filename = Time.now.strftime("objects-%Y%m%d%H%S.json")
@bjjb
bjjb / pb2list
Created February 19, 2014 16:25
#! /usr/bin/env perl
# Takes input like
# 1
# 2
# 3
# and outputs
# (1, 2, 3)
#
# Useful for converting a single column of SQL IDs to a list that you can use
@bjjb
bjjb / cdnjs
Created January 16, 2014 15:16
Lets you enter the name of a JavaScript library on the command-line, and prints out the library's contents, having fetched it from cdnjs.com. `cdnjs backbone.js`, for example, or `cdnjs jquery > jquery.js` to save it.
#! /usr/bin/env perl
# A simple command-line utility for finding and retrieving JavaScript libraries
# from cdnjs.com
use strict;
use warnings;
use LWP::Simple;
my $lib = shift or die "No script entered on the command-line!";
@bjjb
bjjb / vagrant.rb
Last active November 1, 2018 16:23
A Capistrano 3.x Vagrant stage. Place into config/deploy/vagrant.rb, and deploy to the Vagrant box as if it were a production VM.
# Capistrano 3.x Vagrant stage
# config/deploy/vagrant.rb
set :stage, :vagrant
set :rails_env, "production"
vagrant_ssh_config = `vagrant ssh-config`.split("\n")[1..-1].map(&:strip).inject({}) do |m, s|
k, v = s.split(/\s/, 2).map(&:strip); m[k] = v; m
end