Skip to content

Instantly share code, notes, and snippets.

View jsanders's full-sized avatar

James Sanders jsanders

View GitHub Profile
@jsanders
jsanders / rescuable_exception.rb
Created October 31, 2012 17:16
Rescuable Exception
# Taken from a comment on http://www.mikeperham.com/2012/03/03/the-perils-of-rescue-exception/
module RescuableException
def self.===(exception)
case exception
# Catch when the user hits ^C (Interrupt < SignalException), and assume
# that they just wanted to stop the in-progress command (just like bash etc.)
when Interrupt
true
@jsanders
jsanders / spies_on_class_method_spec.rb
Created August 30, 2012 15:17
Test case for gimme class method spies
require 'spec_helper'
module Gimme
class ChairFactory
def self.build
raise RuntimeError.new "unimplemented feature"
end
def self.destroy
@jsanders
jsanders / shared_examples_for_active_model.rb
Created August 28, 2012 17:04
Rspec shared examples for ActiveModel lint
shared_examples "ActiveModel" do
class BeBoolean
def matches?(it)
@it = it
it.kind_of?(TrueClass) || it.kind_of?(FalseClass)
end
def failure_message
"expected #{@it} to be either true or false"
end
# in .bash_profile
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
# in .bashrc
PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting
@jsanders
jsanders / echod.go
Created July 23, 2012 16:18
Simple echo server in Go
package main
import (
"fmt"
"net"
"os"
"bufio"
)
func printBanner() {
@jsanders
jsanders / echod.c
Created July 22, 2012 04:15
Echo server with connection migration
#include <stdlib.h>
#include <netinet/in.h>
#include <sys/un.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#define MAX_CONNECTIONS 5
#define BUFSIZE 1024
#define SOCKPATH "/tmp/migrate.sock"
@jsanders
jsanders / echod.c
Created July 19, 2012 04:57
Simple echo server
#include <stdlib.h>
#include <netinet/in.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#define MAX_CONNECTIONS 5
#define BUFSIZE 1024
typedef struct {
@jsanders
jsanders / README.md
Created June 21, 2012 21:10 — forked from thinkerbot/README.md
Find and remove old git branches

Description

Find and delete old git branches that are no longer needed.

Usage

Clone the repo and add to your path (just for ease of use):

@jsanders
jsanders / Gemfile
Created May 8, 2012 17:28
Issue #589 on defunkt/resque
source 'https://rubygems.org'
gem 'resque', '1.20.0'
gem 'rake'
@jsanders
jsanders / lcg.dasm
Created April 11, 2012 19:22
Very simple linear congruential PRNG in dasm
; Puts "random" numbers in X, Y, and Z
SET A, 0x1232
JSR rand
SET X, A
JSR rand
SET Y, A
JSR rand
SET Z, A
SET PC, break