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 / 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
@warmwaffles
warmwaffles / m
Last active August 29, 2015 14:05
Minitest runner without a lot of cruft
#!/usr/bin/env ruby
# Put in ~/bin as ~/bin/m and make it executable
$LOAD_PATH.unshift('lib', 'spec', 'test')
ARGV.each do |path|
if File.directory?(path)
dir = path.gsub(/\/+\Z/, '')
Dir.glob("#{dir}/**/*_{spec,test}.rb").each { |f| load(f) }
@warmwaffles
warmwaffles / unicorn.rb
Last active August 29, 2015 14:05
Do you need a way to run unicorn like you would with webrick?
require 'fileutils'
APP_PATH = FileUtils.pwd()
APP_PID_PATH = 'tmp/pids/unicorn.pid'
APP_PORT = ENV['PORT']
APP_SOCKET = "/tmp/unicorn_#{APP_PORT}.sock"
working_directory(APP_PATH)
listen(APP_SOCKET, :backlog => 64)
@warmwaffles
warmwaffles / kanye_ipsum.md
Created September 17, 2014 01:06
For when you need quick filler text

The problem I have with the paparazzi is if they’re right in front of you and you’re like, “Can you please not take a picture of me?” And they’re like, “Dude I’m not really taking a picture,” and they just keep on doing it like they’re talking to me like I’m stupid and stuff, and then, with arm sprints, I’m going to grab the camera, that just happens, and you don’t expect that to happen with a celebrity, cause you think they’re like a museum animal and stuff, but it’s like, don’t shoot the animals, then, maybe, I don’t know.

I feel like if a rapper disses me, they're just trying to get a rise out of me and get me to play in their field to find some way that they can beat me. I feel

# Signs a URI with your appSID and Key.
# * :url describes the URL to sign
# * :appSID holds the appSID value
# * :key holds the key value
def self.sign(url, AppSID, AppKey)
url = URI.escape(url)
parsedURL = URI.parse(url)
urlToSign =''
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout>
<Pattern>[%thread] [%-5level] [%logger{1}] - %msg%n</Pattern>
</PatternLayout>
</Console>
<File name="Application" fileName="logs/app.log">
<PatternLayout>
// Original Source: http://pastes.archbsd.net/graphitemaster/50_loc_avl_bsearch_tree
// http://www.reddit.com/r/tinycode/comments/2ouzo9/50_loc_avl_binary_search_tree_in_c/
#include <stdlib.h>
#define H(C,N) ((C)->c[N] ? (C)->c[N]->h : 0)
typedef struct node_s {
int k;
int h;
struct node_s *c[2];