Skip to content

Instantly share code, notes, and snippets.

View jsanders's full-sized avatar

James Sanders jsanders

View GitHub Profile
@jsanders
jsanders / gist:2149607
Created March 21, 2012 17:09
String building benchmark
[11:00] ~ $ ruby str_benchmark.rb
user system total real
interp 1.370000 2.020000 3.390000 ( 3.392649)
arrayjoin 0.030000 0.000000 0.030000 ( 0.029942)
concat 0.020000 0.000000 0.020000 ( 0.023137)
plusequals 1.560000 0.720000 2.280000 ( 2.269754)
user system total real
concat 0.020000 0.000000 0.020000 ( 0.020088)
interp 1.780000 2.090000 3.870000 ( 3.870043)
arrayjoin 0.020000 0.000000 0.020000 ( 0.021839)
@jsanders
jsanders / string_building_benchmark.rb
Created March 21, 2012 17:11
String building benchmark code
require 'benchmark'
TIMES = 100_000
strategies = [
[ 'plusequals', proc { str = ""; TIMES.times { str += 'a' } } ],
[ 'interp', proc { str = ""; TIMES.times { str = "#{str}a" } } ],
[ 'concat', proc { str = ""; TIMES.times { str << "a" } } ],
[ 'arrayjoin', proc { ary = []; TIMES.times { ary << 'a' }; str = ary.join } ] ]
@jsanders
jsanders / go.md
Created March 30, 2012 03:47
Newton's method go vs. ruby comparison
package main

import("fmt"; "math")

func Sqrt(x float64) (z float64) {
  z, delta := 1.0, 1.0

  for delta > 1e-4 {
    z0 := z
@jsanders
jsanders / elsif.rb
Created April 2, 2012 16:30
Prettier (?) elsif
puts case true
when true == false
"nope"
when false == true
"also nope"
when [ :a ].empty?
"nope as well"
when nil.nil?
"yep!"
when false.nil?
@jsanders
jsanders / xml.rs
Created April 4, 2012 02:13
Rust deserialize XML first crack
use std;
import io::reader_util;
enum node {
tag_node({
name: str,
attributes: [attribute],
children: [node]
}),
@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
@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 / 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 / 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 / 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"