Skip to content

Instantly share code, notes, and snippets.

require 'rest_client'
require 'json'
class HomeController < ApplicationController
def initialize
@queries = {:lines =>
"SELECT *
WHERE
@jennifersmith
jennifersmith / gist:1034716
Created June 19, 2011 20:36
Create mysql user
CREATE USER 'monty'@'localhost' IDENTIFIED BY 'some_pass';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'monty'@'localhost'
-> WITH GRANT OPTION;
@jennifersmith
jennifersmith / gist:1035439
Created June 20, 2011 10:57
Setting max print length clojure repl
(set! *print-length* 200)
@jennifersmith
jennifersmith / gist:1050765
Created June 28, 2011 08:54
Comparison of long string generation
require 'benchmark'
lengths = [10, 100 , 1000, 10000, 100000, 1000000]
Benchmark.bm do |x|
lengths.each do |length|
x.report("Length = #{length}\t\t\t") {(0...length.to_i).map{ ('a'..'z').to_a[rand(26)] }}
x.report("Same without rand = #{length}\t\t\t") {(0...length.to_i).map{ ('a'..'z').to_a[1] }}
x.report("Fixed characters Length = #{length}\t\t\t") {"x" * length}
end
end
(doseq [i [1 2 3 4]] (print i))
@jennifersmith
jennifersmith / run_metrics.bat
Created July 19, 2011 19:22
Running the VS 'powertool' metrics
"c:\Program Files\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\Metrics.exe" /f:*.dll /f:*.exe /o:metrics.xml /d:dependencies
@jennifersmith
jennifersmith / gist:1210406
Created September 12, 2011 01:20
clojure facebook graph api
(with-facebook-auth @facebook-auth-token (client/get [:me :friends] {:extract :data})) :
@jennifersmith
jennifersmith / gist:1456771
Created December 10, 2011 22:32
Really really basic test runner :)
(defmacro check [ code expected]
`(if (= ~code ~expected)
(do
(println "Success: " '~code " does indeed equal " ~expected ) true )
(do
(println "FAIL: " '~code " does not sadly equal " ~expected ) false )))
(check (+ 4 1) 4) ;; FAIL: (+ 4 1) does not sadly equal 4
(check (range 4) 4) ;; Success: (range 4) does indeed equal [0 1 2 3]
@jennifersmith
jennifersmith / bells.clj
Created December 12, 2011 14:08
Cheesy Holiday Music and bell synthesis example
(ns overtone-xmas.bells
( :use [overtone.live]
[overtone.sc.machinery.defcgen]))
;;http://computermusicresource.com/Simple.bell.tutorial.html
(def dull-partials
[
0.56
@jennifersmith
jennifersmith / gist:1551277
Created January 2, 2012 16:21
Triangle and organ cornet stop
(defcgen triangle-osc [freq phase {:default 0.0} harmonics {:default 40}]
(:ar (let
[
harmonic-numbers (take harmonics (iterate (partial + 2) 1))
cosines (set (map #(- (* 4 %) 1) (range 1 harmonics))) ;; every 4n -1 is
;; there a better way?!
]
(klang [
(map #(* freq %) harmonic-numbers ) ;; harmonics
(map #(/ 1.0 (* % %)) harmonic-numbers) ;; inverse square ampl