Skip to content

Instantly share code, notes, and snippets.

View gdiggs's full-sized avatar

Gordon Diggs gdiggs

View GitHub Profile
@gdiggs
gdiggs / test_response_speed.rb
Created September 16, 2013 20:22
Test response speed (somewhat poorly)
#!/usr/bin/env ruby
# Given a URL, hit it a bunch of times and record the time it takes
# please dont use this for DDOS
TRIALS = 100
url = ARGV[0]
if !url
@gdiggs
gdiggs / gist:6485207
Created September 8, 2013 14:42
Spent Grain Bread

Spent Grain Bread

From http://www.michiganbeerblog.net/2011/11/spent-grain-bread.html

If you are a home brewer and are interested in how to put some of that spent grain to good use, I highly recommend trying this recipe. It took about 30 hours from start to finish, but man, was the end result worth the wait. The tender inside of the bread makes it great for sandwiches or spreads, and the sweet and malty spent grain really shines. If you are not a home brewer, find a friend that is, and go ask them for some of their spent grain. Seriously. Right now.

Note that you can freeze spent grain, and then thaw it out again before using in this recipe. It’s best to bring it up to room temperature before you start baking.

Sponge:

@gdiggs
gdiggs / gist:5518491
Created May 4, 2013 19:34
Monte Carlo Tests to Calculate Pi in Go
package main
import (
"flag"
"fmt"
"math/rand"
"sync"
"time"
)
// based on http://stackoverflow.com/a/12313690/1198757
var styleSheets = document.styleSheets,
totalStyleSheets = styleSheets.length,
maxIESelectors = 4095;
for (var j = 0; j < totalStyleSheets; j++){
var styleSheet = styleSheets[j],
rules = styleSheet.cssRules,
totalRulesInStylesheet = rules.length,
@gdiggs
gdiggs / bacon_toffee.md
Created November 11, 2012 18:29
Bacon Toffee

Bacon Toffee

Ingredients

  • 1 pound Thick Sliced Bacon
  • 1 cup Almonds, Roughly Chopped
  • 1 cup Butter
  • 1 cup Granulated Sugar
@gdiggs
gdiggs / timelapse.rb
Created July 1, 2012 04:43
ruby timelapse script
#!/usr/bin/env ruby
# Before running this, do `brew install imagesnap`
#
# Takes a photo every 30 seconds and saves it. Good for doing timelapses!
while true do
file = "~/snaps/#{Time.now.to_i}.jpg"
puts "Taking photo at #{Time.now}"
system "imagesnap -q -w 3 #{file}"
puts "waiting 30 seconds..."
@gdiggs
gdiggs / proof.md
Created April 17, 2012 13:55
Proof of @mrb's music tastes

It is given that @mrb prefers the inverse of c &amp;&amp; s &amp;&amp; n &amp;&amp; !y. To calculate his musical preference regarding combinations of the set g = {c, s, n, y}, we apply DeMorgan's law to c &amp;&amp; s &amp;&amp; n &amp;&amp; !y, producing: !c || !s || !n || y. This implies that @mrb will be happy given the presence of y in any combination, but if y is not present, neither can c, s, or n.

@gdiggs
gdiggs / loading.md
Created April 3, 2012 04:17
DataMapper lazy-loading examples

So, in the app, I do something like this:

  Item.all(:order => sort).select { |item| item.to_s.downcase.include? search.to_s.downcase }

Where sort is an array of fields to order by. By default (with lazy-loading enabled), the query output from DataMapper looks like the following (on a table of 8601 rows):

   ~ (0.142849) SELECT "id", "created_at", "updated_at" FROM "items" ORDER BY "artist", "title", "year", "label", "format"
@gdiggs
gdiggs / array_move.rb
Created January 6, 2012 19:46
Adding/moving item to the front of an array
x = 1
a = [2, 1, 4, 3]
[x] + (a - [x]) #=> [1, 2, 4, 3]
@gdiggs
gdiggs / gist:1243043
Created September 26, 2011 18:57
sick playlist
Name Artist Album Track Number
Downstairs Religious Knives The Door 1
Basement Watch Religious Knives The Door 2
On a Drive Religious Knives The Door 3
The Storm Religious Knives The Door 4
Major Score Religious Knives The Door 5
Decisions Are Made Religious Knives The Door 6
Cirrus Minor Pink Floyd More 1
The Nile Song Pink Floyd More 2
Crying Song Pink Floyd More 3