Skip to content

Instantly share code, notes, and snippets.

@gja
gja / plot-yourkit-heap.gnuplot
Created June 26, 2014 10:13
Plot a Yourkit Memory Heap CSV
#! /usr/bin/env gnuplot
set terminal png size 1024,768 font "/Library/Fonts/Arial.ttf" 12
set output "output.png"
set style line 1 lt 1 lw 2 pt 7 pi -1 ps 1.5
set pointintervalbox 3
set datafile separator ','
@gja
gja / scheme.hs
Created April 9, 2014 20:32
Scheme Interpreter in Haskell
import Text.ParserCombinators.Parsec
import Text.Parsec.Char
import Data.List.Split (chunksOf)
data Exp = IntExp Integer
| SymExp String
| SExp [Exp]
deriving (Show)
data Val = IntVal Integer
@gja
gja / nil_class.rb
Created November 30, 2013 04:33
Nil punting ruby
class NilClass
include Enumerable
def [](index)
self
end
def merge(hash)
hash.dup
end
@gja
gja / swap.c
Created April 16, 2013 07:38
Swap two numbers. Thought process behind this: You aren't able to store data in any new variables, so the only option available to you is the stack.
// Assume a < b
void swap(int &a, int &b)
{
if(a < b) {
a++;
swap(a, b);
b--;
}
}
@gja
gja / Delay Send.applescript
Last active December 14, 2015 10:10
Mail.app: Send file in 5 seconds. This script minimizes the current message, waits for five seconds, and then opens the message and sends the mail out. If you unminimize the app, then the mail is also cancelled.
on run {input, parameters}
tell application "Mail"
set theWindow to front window
set miniaturized of theWindow to true
end tell
set question to display dialog "Sending Mail" buttons {"Send Now", "Stop"} default button 2 giving up after 12
set answer to button returned of question
tell application "System Events"
@gja
gja / and_different.rb
Created July 7, 2012 08:54
Ruby Similar Constructs
x = true and false
puts x # print out true
x = true && false
puts x # print out false
@gja
gja / 6define.js
Created June 30, 2012 09:02
Eight Simple Rules of Javascript
for(i = 0; i < 5; i++) {
var times = i; // need to save this in our closure
String.prototype["alert" + i] = function() {
alert(this + times);
}
};
"foobar".alert3()
@gja
gja / bank.rb
Created June 30, 2012 04:23
Proxy Pattern blog post
class Bank
def bank_balance(account_number)
42
end
end
bank = Bank.new
p bank.bank_balance("1234567") # ---> Gives me 42
@gja
gja / foobar.bash
Created December 6, 2011 06:22
Do a gem install or apt get install on command not found
function command_not_found_handle() {
gem install "$@" || sudo apt-get install "$@";
}