This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Recursively diff two hashes, showing only the differing values. | |
# By Henrik Nyh <http://henrik.nyh.se> 2009-07-14 under the MIT license. | |
# | |
# Example: | |
# | |
# a = { | |
# "same" => "same", | |
# "diff" => "a", | |
# "only a" => "a", | |
# "nest" => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'sinatra/base' | |
require 'rack/flash' | |
require 'warden' | |
require 'slim' | |
require 'sequel' | |
require 'sqlite3' | |
DB = Sequel.sqlite | |
DB.create_table :users do | |
primary_key :id |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: utf-8 | |
require 'rubygems' | |
require 'builder' | |
svg_doctype = [ | |
:DOCTYPE, | |
:svg, | |
:PUBLIC, | |
"-//W3C//DTD SVG 1.1//EN", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('a.reveal').click(function(event) { | |
event.preventDefault(); | |
var $div = $('<div>').addClass('reveal-modal').appendTo('body'), | |
$this = $(this); | |
$.get($this.attr('href'), function(data) { | |
return $div.empty().html(data).append('<a class="close-reveal-modal">×</a>').reveal(); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# requires socksify gem | |
require "socksify" | |
require 'socksify/http' | |
# use w/ OAuth2 like OAuth2::Client.new(id, secret, connection_opts: { proxy: 'socks://127.0.0.1:9050' }) | |
class Faraday::Adapter::NetHttp | |
def net_http_class(env) | |
if proxy = env[:request][:proxy] | |
if proxy[:uri].scheme == 'socks' | |
Net::HTTP::SOCKSProxy(proxy[:uri].host, proxy[:uri].port) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe "Shopping Cart Requests" do | |
let!(:user) { Fabricate(:user) } | |
before(:each) do | |
login_user_post("admin", "admin") | |
end | |
context "when I visit the shopping cart" do | |
it " show the logged in users' cart items " do | |
#Test stuff |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# test_for == N / 5 -- approximate array average case? | |
{:benchmark_iterations=>10000, :class=>Array, :test_for=>5, :num_rewrites=>1, :col_size=>10, :num_reads=>10} | |
0.140000 0.000000 0.140000 ( 0.141915) | |
{:benchmark_iterations=>10000, :class=>Set, :test_for=>5, :num_rewrites=>1, :col_size=>10, :num_reads=>10} | |
0.190000 0.010000 0.200000 ( 0.198503) | |
---- | |
{:benchmark_iterations=>10000, :class=>Array, :test_for=>50, :num_rewrites=>1, :col_size=>100, :num_reads=>10} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns workbook.dec-tree) | |
;; An example drawn from: | |
;; http://www.doc.ic.ac.uk/~sgc/teaching/pre2012/v231/lecture11.html | |
(defn log2 | |
"log2(x), log2(0) = 0" | |
[x] | |
(if (= x 0) 0 (/ (Math/log x) (Math/log 2)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Converts a learnt decision tree produced by | |
;; https://gist.github.com/jackrusher/4971531 | |
;; into a core.match program. A nice way to convert a set of data points into a | |
;; readable set of rules. I haven't looked at the code, but I assume core.match | |
;; compiles the rules into a decision tree. | |
(defn tree-to-match-clauses [t p] | |
(let [children (keys t)] | |
(if (keyword? (first children)) | |
(conj p (first (vals t))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ brew install -v mp3wrap ffmpeg id3lib | |
$ mp3wrap tmp.mp3 1.mp3 2.mp3 3.mp3 .... | |
$ ffmpeg -i tmp_MP3WRAP.mp3 -acodec copy all.mp3 && rm tmp_MP3WRAP.mp3 | |
$ id3cp 1.mp3 all.mp3 |
OlderNewer