Skip to content

Instantly share code, notes, and snippets.

@ctford
ctford / at_all.clj
Created March 11, 2012 20:44
A short piano piece in Overtone
(ns overtunes.songs.at-all
(:use
[overtone.live :only [at now]]
[overtone.inst.sampled-piano :only [sampled-piano]]))
(defn bpm [beats-per-minute]
(let [start (now)
ms-per-minute (* 60 1000)
ms-per-beat (/ ms-per-minute beats-per-minute)]
#(+ start (* ms-per-beat %))))
@ctford
ctford / row-row-row-your-boat.clj
Created June 5, 2012 19:59
Row, row, row your boat!
(ns overtunes.songs.row-row-row-your-boat
(:use
[overtone.live]))
(definst harpsichord [freq 440]
(let [duration 1]
(*
(line:kr 1 1 duration FREE)
(pluck (* (white-noise) (env-gen (perc 0.001 5) :action FREE))
1 1 (/ 1 freq) (* duration 2) 0.25))))
@ctford
ctford / neo_loading.rb
Created June 10, 2012 16:23 — forked from mneedham/neo_loading.rb
Loading stuff into neo via the batch API
# So the problem is inserting data into neo using the batch API. So we have a bunch of people and we want to put them into the graph and also
# add to to the index so that we can search for them.
# The way the batch API works is that you can refer to previous commands by referencing their index in the list of commands (zero indexed)
# e.g. if I want to reference the person added in the first command I would reference that node as {0}
# You should be able to see how that works in the code below.
neo_people_to_load =
[{ :name => "Mark Needham", :id => 1 },
{ :name => "Jenn Smith", :id => 2 },
{ :name => "Chris Ford", :id => 3 }]
(definst bell# [frequency 440 duration 4.0]
(let [harmonic-decay [1.0 0.5 0.25 0.125]
partials (map-indexed
(fn [harmonic proportion]
(let [envelope (env-gen (perc 0.01 (* duration proportion)))
overtone (* (inc harmonic) frequency)]
(* envelope proportion (sin-osc overtone))))
harmonic-decay)]
(detect-silence (first partials) :action FREE)
partials))
@ctford
ctford / gist:3072824
Created July 8, 2012 21:11
Reduced bell
(definst bell# [frequency 440 duration 4.0]
(let [harmonic-decay [1.0 0.5 0.25 0.125]
ring (reduce + (map-indexed
(fn [harmonic proportion]
(let [envelope (env-gen (perc 0.01 (* duration proportion)))
overtone (* (inc harmonic) frequency)]
(* envelope proportion (sin-osc overtone))))
harmonic-decay))]
(detect-silence ring :action FREE)
ring))
@ctford
ctford / gist:3156530
Created July 21, 2012 17:45
Phantom fundamental
(definst bell [frequency 300 duration 20.0 h0 1.0 h1 0.5 h2 0.4 h3 0.25 h4 0.20 h5 0.125]
(let [harmonic-decay [h0 h1 h2 h3 h4 h5]
proportional-partial
(fn [harmonic proportion]
(let [envelope (env-gen (perc 0.01 (* duration proportion)))
overtone (* (inc harmonic) frequency)]
(* envelope proportion (sin-osc overtone))))
partials (map-indexed proportional-partial harmonic-decay)
whole (mix partials)]
(detect-silence whole :action FREE)
@ctford
ctford / anarchy.clj
Created September 5, 2012 10:43
Simple system for plural dispatch
(ns anarchy.core)
(def plurality {})
(defmacro defplural [method resolver]
`(def ~method (fn ~method [& args#] (~resolver (plurality ~method) args#))))
(defmacro defimplementation [method implementation]
`(def plurality (update-in plurality [~method] #(conj % ~implementation))))
### Week 01 ###
0.upto(10) { |i|
print " " * (10 - i)
puts "*" * (2 * i + 1)
}
9.downto(0) { |i|
print " " * (10 - i)
puts "*" * (2 * i + 1)
@ctford
ctford / week04.rb
Last active December 14, 2015 09:28
Week 4, Girl-geek Kampala
# Hashes connect keys to values:
companies = {"third_floor" => "ThoughtWorks",
"fourth_floor" => "Outbox"}
#> companies["third_floor"]
# You can use hashes to create a complex thing with multiple parts:
john =
{"first_name" => "John",
"second_name" => "Smith",
@ctford
ctford / so_far.rb
Created March 2, 2013 09:10
Here's a quick run through of everything we've covered so far...
# First, you need to install ruby. This will be different for Windows, Linux and Mac.
# You're probably best googling instructions for your operating system.
#
# Once you've got it installed, there are two ways of running ruby code:
#
# 1) Type "irb" on your command-line, and start typing in expressions that
# will be immediately evaluated.
# 2) Save some ruby in a file ending with .rb, and then run it with the ruby
# command, e.g. "ruby my_code.rb". This will run everything in the file
# at once.