Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Peter J. Jones pjones

🏠
Working from home
View GitHub Profile
View default.nix
let
pkgs = import <nixpkgs> {};
stdenv = pkgs.stdenv;
mysql = pkgs.mysql55;
in rec {
cltc-claims = stdenv.mkDerivation rec {
name = "cltc-claims";
version = "0.0";
src = ./.;
@pjones
pjones / sno.rb
Created Nov 18, 2015
The new safe navigation operator in Ruby 2.3
View sno.rb
#!/usr/bin/env ruby
################################################################################
#
# Watch out for the unusual argument evaluation rules with the new
# safe navigation operator in Ruby 2.3.
#
# It short circuits just like the logic operators. This is different
# than how the `try' method works in ActiveSupport.
#
@pjones
pjones / convert.rb
Last active Aug 29, 2015
Read a tab-separated file generated by PasswordSafe and use the pass(1) tool to record new passwords.
View convert.rb
#!/usr/bin/env ruby
################################################################################
# Read a tab-separated file generated by PasswordSafe and use the
# pass(1) tool to record new passwords.
#
# To use this script:
#
# 1. Create and mount an encrypted disk image (cryptsetup).
#
View hsbuild.sh
#!/bin/sh -e
################################################################################
# This is a simple wrapper around cabal to build Haskell projects.
echo $NIX_GHC
################################################################################
# Keep cabal from being affected by local configuration.
export HOME="$(mktemp -d)"
@pjones
pjones / class_counter.rb
Created May 26, 2015
Counting classes created with `Class.new`
View class_counter.rb
#!/usr/bin/env ruby
# Don't use this in production!
module ClassCounter
def self.extended (klass)
$stderr.puts("Injecting hacked `new' into `#{klass}'")
klass.instance_exec {@klass_count = 0}
end
def new (*)
View version.rb
class Version
attr_reader(:major, :minor, :patch)
def initialize (version)
@major, @minor, @patch =
version.split('.').map(&:to_i)
end
def <=> (other)
return nil unless other.is_a?(Version)
View whatisthere.sh
#!/bin/sh
whatisthere () {
for dir in `echo $PATH | sed 's/:/ /g'`; do
for file in $dir/*; do
base=`basename $file`
desc=`whatis $base 2>&1`
[ $? -eq 0 ] && echo $desc
done
done
View org-conf.el
(defun pjones:org-goto (&optional alternative-interface)
"My version of `org-goto' that first widens the buffer (if
narrowed), jumps to the correct heading via `org-goto', then
narrows it again if necessary."
(interactive "P")
(let ((point-size (save-restriction (- (point-max) (point-min))))
(buff-size (buffer-size)))
(widen)
(org-goto alternative-interface)
(if (/= buff-size point-size) (org-narrow-to-subtree))))
@pjones
pjones / macenv.rb
Created Feb 22, 2012
Create an env file for Mac OS GUI applications
View macenv.rb
#!/usr/bin/env ruby
PASS_THROUGH = %w(PATH MANPATH EDITOR)
DIRECTORY = File.expand_path('~/.MacOSX')
FILENAME = File.join(DIRECTORY, 'environment.plist')
Dir.mkdir(DIRECTORY) unless File.exist?(DIRECTORY)
HEADER = <<EOT
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">