Skip to content

Instantly share code, notes, and snippets.

View warmwaffles's full-sized avatar
🛠️
Code Wrestling

Matthew Johnston warmwaffles

🛠️
Code Wrestling
View GitHub Profile
@warmwaffles
warmwaffles / example.rb
Last active August 29, 2015 13:57
Hash Presenter demonstration
class SomePresenter < HashPresenter
present 'author', :author
present 'something', :something
present 'foo', :foo
def baz
"#{self.author} is #{self.something}"
end
end
#include <assert.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
enum type {
NIL,
#!/bin/bash
echo "REMOVING MERGED BRANCHES..."
git branch --merged | grep -v "\*" | grep -v "master" | xargs -n 1 git branch -d
echo "PRUNING REMOTE BRANCHES..."
git remote | xargs -n 1 git remote prune
echo "CLEANING...AGGRESSIVE LIKE..."
git gc --aggressive
#!/bin/bash
#
# Useful for switching between java 1.6, 1.7, 1.8 etc...
#
export JAVA_HOME=$(/usr/libexec/java_home -v 1.7)
setjdk() {
export JAVA_HOME=$(/usr/libexec/java_home -v $1)
}

Keybase proof

I hereby claim:

  • I am warmwaffles on github.
  • I am warmwaffles (https://keybase.io/warmwaffles) on keybase.
  • I have a public key whose fingerprint is CD94 A497 63BF BACD 96D7 8004 FD9B BCAD 4196 AEB7

To claim this, I am signing this object:

# Use this when you need to figure out what is being required and where
def require(*args)
puts "\e[1;31m[required]\e[0m %s => \e[0;36m%s\e[0m" % [caller.first, args.first]
super
end
def load(*args)
puts "\e[1;31m[loaded]\e[0m %s => \e[0;36m%s\e[0m" % [caller.first, args.first]
super
@warmwaffles
warmwaffles / time_benchmark.rb
Created June 4, 2014 22:27
Benchmark of the ruby Time class.
require 'time'
require 'benchmark'
max = (ARGV.shift || 100000).to_i
puts "# of iterations = #{max}"
Benchmark::bm(20) do |x|
x.report("Time.parse") do
(0..max).each do

Fix the Home and End keys on Mac OS X (Mountain Lion)

source: http://mwholt.blogspot.com/2012/09/fix-home-and-end-keys-on-mac-os-x.html

If you use a keyboard that's not designed specifically for Macs, you probably are familiar with the annoying mapping of the Home and End keys: they scroll to the beginning or end of an entire document, with no regard to the cursor's location.

Fortunately it's an easy fix. (Note: This works for native Cocoa apps only, not

require 'json'
class Pagination
attr_reader :limit, :offset, :total
def initialize(options={})
@limit = options[:per_page] ? options[:per_page] : options[:limit]
@offset = options[:page] ? (options[:page] * @limit) : options[:offset]
@total = options[:total_entries] ? options[:total_entries] : options[:total]
end