Skip to content

Instantly share code, notes, and snippets.

View ggilder's full-sized avatar

Gabriel Gilder ggilder

View GitHub Profile
@ggilder
ggilder / large_int_subtraction.js
Created April 16, 2012 00:04
Javascript subtracting from large integers
function LargeInt(str){
this.length = 0;
if (str){
Array.prototype.push.apply(this, String(str).split(''));
}
}
LargeInt.prototype = {
splice: Array.prototype.splice,
minus: function(subtrahend){
subtrahend = new LargeInt(subtrahend);
class Node
attr_accessor :next, :data
def push(str)
n = Node.new
n.data = str
node = self
next_node = nil
while node.next
@ggilder
ggilder / fizz.rb
Created June 8, 2012 05:14
Fizzbuzz bitwise math
messages = [nil, "Fizz", "Buzz", "FizzBuzz"]
acc = 810092048
(1..100).each do |i|
c = acc & 3
puts messages[c] || i
acc = acc >> 2 | c << 28
end
# Explanation
#
@ggilder
ggilder / ruby_koan_greed.rb
Created July 24, 2012 05:25
Ruby Koans - Greed
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
# Greed is a dice game where you roll up to five dice to accumulate
# points. The following "score" function will be used to calculate the
# score of a single roll of the dice.
#
# A greed roll is scored as follows:
#
# * A set of three ones is 1000 points
#
@ggilder
ggilder / linked_stack.rb
Created August 1, 2012 07:03
Linked List Ruby implementation
require 'minitest/autorun'
class LinkedStack
class ElementNotFound < RuntimeError; end
attr_reader :head
def empty?
@head == nil
end
@ggilder
ggilder / linked_stack.js
Created August 1, 2012 07:29
Linked List Javascript implementation (node.js)
var assert = require('assert');
var LinkedStack = (function(){
function Item(data){
this.data = data;
this.next = null;
}
Item.prototype = {
tail: function(){
@ggilder
ggilder / dropbox_empty_files.sh
Created October 27, 2012 21:31
Check for files affected by Dropbox bug
#!/usr/bin/env bash
# Dropbox apparently has a potential bug where files can be zeroed out.
# Description here:
# http://konklone.com/post/dropbox-bug-can-permanently-lose-your-files
#
# The script in that article to detect zero-byte files is pretty naive about
# files that normally would be zero bytes, so here's an improved version that
# ignores some common cases:
# - Mac OS icons
@ggilder
ggilder / log.txt
Created December 15, 2012 19:16
Demo of default command with commander
→ ./tester.rb
initialized with .
Compile called
→ ./tester.rb --dir .
initialized with .
Compile called
→ ./tester.rb deploy
initialized with .
Deploy called
→ ./tester.rb deploy --dir .
@ggilder
ggilder / selecta.go
Created July 30, 2014 07:45
selecta (go)
package main
import (
"bufio"
"fmt"
"io"
"os"
"os/exec"
)
@ggilder
ggilder / test_connection_pool.rb
Last active August 29, 2015 14:13
Test connection_pool with Timeout interrupts
#!/usr/bin/env ruby
# Uncomment & fix the following line to test against a local checkout of connection_pool
# $LOAD_PATH.unshift '/Users/gabriel/oss/connection_pool/lib'
require 'redis'
require 'connection_pool'
require 'timeout'
pool = ConnectionPool.new(size: 5, timeout: 5) do