Skip to content

Instantly share code, notes, and snippets.

@mharju
mharju / gist:4533567
Created January 14, 2013 21:15
No. There was no doubly linked list implementation that I could have used ;)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct buffer_t {
void *data;
int length;
struct buffer_t* next;
struct buffer_t* prev;
@mharju
mharju / quote.py
Created December 21, 2012 11:37
Birthday greeter generator. Useful for giving good birthday greetings on Facebook
# -*- encoding: utf-8 -*-
from BeautifulSoup import BeautifulSoup
from random import sample, choice
import httplib2
import sys
import pickle
import os.path
class Quotes(object):
@mharju
mharju / gist:4329895
Created December 18, 2012 17:17
Ghastly images in Processing
void setup()
{
size(1000, 500);
verts = new ArrayList<Vertex>();
for(int i=0;i<50;i++) {
verts.add(new Vertex(random(75, 150)));
}
background(bg);
}
@mharju
mharju / gist:4094920
Created November 17, 2012 11:03
method to transform number strings to finnish
# -*- coding: utf-8
numbers = (u'nolla',u'yksi',u'kaksi',u'kolme',u'neljä',u'viisi',u'kuusi',u'seitsemän',u'kahdeksan',u'yhdeksän',u'kymmenen')
suffixes = ((u'toista',u'kymmentä'), (u'sata',u'sataa'))
exponents = ((u'',u''), (u'tuhat',u'tuhatta'), (u'miljoona','miljoonaa'))
def ones(n, s):
if s == 0 or n == 1:
return u''
return numbers[s]
@mharju
mharju / gist:3805082
Created September 29, 2012 20:17
Unknown pleasures album cover visualization for Processing. This is the version in http://www.youtube.com/watch?v=nYOh_laT4_Q
import ddf.minim.*;
import ddf.minim.signals.*;
import ddf.minim.analysis.*;
import ddf.minim.effects.*;
Minim minim;
AudioPlayer player;
AudioInput input;
FFT fft;
@mharju
mharju / gist:3486133
Created August 27, 2012 06:13
Code duplication and complexity
/*
The most trivial implementation of what I need. Introduces code
duplication and can become a hassle to maintain if more and more
data sources are introduced.
What would be the best approach to keep the code organization as
simple as possible but on the other hand keep the clarity of this
two data source example?
When should a programmer "feel the pain" of code duplication?
@mharju
mharju / gist:3324018
Created August 11, 2012 11:53
Testing quil
(use 'quil.core)
(def draw-state (atom :draw))
(defn setup []
(background 11 11 11)
(smooth))
(defn my-random [min max]
(let [delta (- max min)]
@mharju
mharju / gist:3200531
Created July 29, 2012 17:41
Is this good?
(defmacro play-chord
[ts notes]
(let [note-on (map #(list 'sampled-piano %) (eval notes))]
`(at ~ts ~@note-on)))
(play-chord (+ 1000 (now)) (chord :A4 :major7))
; expands to
(overtone.live/at
(+ 1000 (now))
@mharju
mharju / gist:3181751
Created July 26, 2012 12:26
Prime number sieve
(defn multiple-of [number divisor] (and (not (= number divisor))
(= (mod number divisor) 0)))
(defn not-multiples-or-1 [numbers divisor]
(filter (fn [n]
(and
(not (= n 1))
(not (multiple-of n divisor)))) numbers))
(defn primes-in-decreasing-seq [n] (reduce not-multiples-or-1 n (range 2 (Math/sqrt (first n)))))
from functools import wraps
def db(selector):
def _funcall(function):
@wraps(function)
def _wrapper(row):
got_args = {
'primary': { '1': ('baba', 15), '2': ('gaga', 16) },
'secondary': { '1': ('foo', 17), '2': ('bar', 18) },
}