Skip to content

Instantly share code, notes, and snippets.

View pjones's full-sized avatar
🏠
Working from home

Peter J. Jones pjones

🏠
Working from home
View GitHub Profile
@pjones
pjones / macenv.rb
Created February 22, 2012 20:36
Create an env file for Mac OS GUI applications
#!/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">
(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))))
#!/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
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)
@pjones
pjones / class_counter.rb
Created May 26, 2015 19:28
Counting classes created with `Class.new`
#!/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 (*)
#!/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 / convert.rb
Last active August 29, 2015 14:26
Read a tab-separated file generated by PasswordSafe and use the pass(1) tool to record new passwords.
#!/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).
#
@pjones
pjones / sno.rb
Created November 18, 2015 19:54
The new safe navigation operator in Ruby 2.3
#!/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.
#
let
pkgs = import <nixpkgs> {};
stdenv = pkgs.stdenv;
mysql = pkgs.mysql55;
in rec {
cltc-claims = stdenv.mkDerivation rec {
name = "cltc-claims";
version = "0.0";
src = ./.;
services.compton = {
enable = true;
package = pkgs.compton-git;
fade = true;
fadeDelta = 5;
activeOpacity = "1.0";
inactiveOpacity = "0.92";
menuOpacity = "1.0";
shadow = false;
extraOptions = ''