Skip to content

Instantly share code, notes, and snippets.

View bjjb's full-sized avatar

JJ Buckley bjjb

View GitHub Profile
@bjjb
bjjb / powmaker.sh
Last active December 15, 2015 09:08
Shell command to generate a [.pow](http://pow.cx) link for every file in a project directory (provided they have a config.ru)
cd ~/.pow
for f in ~/Projects/*; do [[ -e $f/config.ru ]] && ln -s $f `basename $f`; done
@bjjb
bjjb / dummy.rb
Last active December 17, 2015 02:09
A dummy ActiveRecord "application"
# A dummy ActiveRecord application, useful for playing around with ActiveRecord,
# or for writing tests. Makes a Sqlite3 database in memory.
#
# Creates the following tables:
#
# - products
# - users
# - taggings
# - tags
# - categories
@bjjb
bjjb / blogeen.rake
Created October 21, 2013 02:57
A simple static website generator
# A very simple Rakefile for generating static sites. It's essentially Hobix,
# but probably simpler. Every page of the site is a YAML file. The YAML file
# gets compiled into a HTML file with the same basename. The content can be
# wrapped in a layout.
require 'rake/clean'
require 'open-uri'
require 'yaml'
require 'erb'
YML = FileList['**/*.yml'].exclude(/^[_.]/)
@bjjb
bjjb / provision
Created November 21, 2013 05:00
A bash script for quickly setting up NginX, PostreSQL, ruby, thin, and an app user on a Debian-like system
#!/bin/bash
# Provisioning script for an Ubuntu server to run a PostgreSQL server, NginX,
# and a Rack application behind a thin server, which can be deployed with
# Capistrano.
#
# This script needs to be run as root
#
# When it's run, you will still need to add your deploy users to the group, so
# that they can actually act on behalf of the named application user. And,
# obviously, they will need an account into which they can SSH, so you'll need
@bjjb
bjjb / feedme
Created November 21, 2013 19:11
A Ruby-script to react to RSS feeds
#!/usr/bin/env ruby -ws
require 'open-uri'
require 'nokogiri'
require 'yaml'
require 'pathname'
require 'ostruct'
require 'pp'
require 'forwardable'
require 'minitest/unit'
@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
@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 / 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 / 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 / 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)