Skip to content

Instantly share code, notes, and snippets.

@tomasos
tomasos / presentation.clj
Created March 11, 2015 11:16
Overtone presentation
;; Tomas Osland
;; tomas.osland@knowit.no
;; @tomasosland
;; Welcome to this presentation about functional music. In this lightning talk we
;; will construct a drum machine and make som beats, play the piano, and experiment with synthesizers.
;; Start overtone.cid
(ns overtone.examples.timing.one-bar-sequencer
function generateGrid() {
console.time('generate grid');
var grid = [];
for(var i = 0; i < 10; i++) {
grid[i] = [];
for(var j = 0; j < 10; j++){
grid[i][j] = {color: 'white'};
}
}
@tomasos
tomasos / gist:cc9b7c877751b01c95e8
Last active August 29, 2015 14:10
prime num generator
function exists(prev, num) {
return prev.indexOf(num) > -1;
}
function primeNumber(number, prev) {
var res = true;
for(var i = 2; i < Math.sqrt(number); i++) {
if((number % i) == 0) {
return false;
@tomasos
tomasos / gist:1647d7d1ad8e3b0b93d2
Created December 1, 2014 14:02
Find numbers that are palindrome in both base 8 and base 10
function palindrome(number) {
n = number;
rev = 0;
while (number > 0)
{
dig = number % 10;
rev = rev * 10 + dig;
number = Math.floor(number / 10);
}
@tomasos
tomasos / gist:8620223
Created January 25, 2014 17:36
calc hours worked
;; calc hours worked
(defun time-to-decimal (time)
(+ (floor time) (/ (* 100 (- time (floor time))) 60)))
(defun calc-hours-worked ()
(interactive)
(setq line (buffer-substring-no-properties (line-beginning-position) (line-end-position)))
(string-match "[0-9]\\{2\\}\.[0-9]\\{2\\}" line)
(setq start (string-to-number (match-string 0 line)))
(string-match "[0-9]\\{2\\}\.[0-9]\\{2\\}" line 5)