Skip to content

Instantly share code, notes, and snippets.

Avatar

Gordon Diggs gdiggs

View GitHub Profile
@gdiggs
gdiggs / current_track.scpt
Created Jul 28, 2011
Get current track and link in Spotify
View current_track.scpt
tell application "Spotify"
set track_name to name of current track
set track_artist to artist of current track
set track_album to album of current track
set track_id to id of current track
end tell
set AppleScript's text item delimiters to ":"
set track_id to third text item of track_id
set AppleScript's text item delimiters to {""}
@gdiggs
gdiggs / ecco.sh
Created Jul 30, 2011
Ecco the dolphin!
View ecco.sh
#!/bin/bash
if [ -z "$1" ]
then
message="eeee eeee!"
else
message="$1"
fi
View gist:1243043
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
@gdiggs
gdiggs / array_move.rb
Created Jan 6, 2012
Adding/moving item to the front of an array
View array_move.rb
x = 1
a = [2, 1, 4, 3]
[x] + (a - [x]) #=> [1, 2, 4, 3]
@gdiggs
gdiggs / loading.md
Created Apr 3, 2012
DataMapper lazy-loading examples
View loading.md

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 / proof.md
Created Apr 17, 2012
Proof of @mrb's music tastes
View proof.md

It is given that @mrb prefers the inverse of c && s && n && !y. To calculate his musical preference regarding combinations of the set g = {c, s, n, y}, we apply DeMorgan's law to c && s && n && !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 / timelapse.rb
Created Jul 1, 2012
ruby timelapse script
View timelapse.rb
#!/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..."
View bacon_toffee.md

Bacon Toffee

From Tasty Kitchen

Ingredients

  • 1 pound Thick Sliced Bacon
  • 1 cup Almonds, Roughly Chopped
  • 1 cup Butter
  • 1 cup Granulated Sugar
View stylesheets.js
// 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 / gist:5518491
Created May 4, 2013
Monte Carlo Tests to Calculate Pi in Go
View gist:5518491
package main
import (
"flag"
"fmt"
"math/rand"
"sync"
"time"
)
You can’t perform that action at this time.