Skip to content

Instantly share code, notes, and snippets.

@mharju
mharju / outrun.clj
Last active Aug 29, 2015
Solution to the newest Reaktor FastTrack. Mathematically elegant, code-wise maybe not so :)
View outrun.clj
; A solution to the latest http://reaktor.fi/careers/fast_track/
;
; Calculates recursively the maximum path function
; S(i,j) = W(i,j) + max { S(i-1, j-1), S(i-1, j) }
;
; Solution to the problem is just finding
; M = max { S(N, i) }, 1 <= i <= N (using 1-based indexing)
;
; then prints out the solution from the given node as an HTML table.
@mharju
mharju / waves.glsl
Created Jun 30, 2014
GLSL shader test
View waves.glsl
void main(void)
{
vec2 n = 2.0 * (gl_FragCoord.xy / iResolution.xy) - 1.0;
vec2 uv = vec2(0,0);
float theta = iGlobalTime * 0.2;
uv.x = cos(theta) * n.x + sin(theta) * n.y;
uv.y = -sin(theta) * n.x + cos(theta) * n.y;
vec4 v = texture2D(iChannel0, vec2(0.0,iChannelTime[0]));
@mharju
mharju / pairs.clj
Last active Aug 29, 2015
Yet another fasttrack solution
View pairs.clj
(ns pairs.core
(:require [clojure.string :as str]
[clojure.math.combinatorics :as combo]))
(def letters (map identity "pairs"))
(defn name->counts [name]
(reduce
(fn [acc value]
(if-not (nil? value)
View gist:466339
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define QUESTIONS_FILE "hello.txt"
#define BUFFER_SIZE 255
#define OPTSEPARATOR ';'
#define QUESTIONSEPARATOR '\n'
struct option_t
View gist:549324
00000000 00 03 00 00 00 01 00 0b 2f 31 2f 6f 6e 52 65 73 /1/onRes
00000010 75 6c 74 00 04 6e 75 6c 6c 00 00 00 00 11 0a 07 ult null
00000020 3b 66 6c 65 78 2e 6d 65 73 73 61 67 69 6e 67 2e ;flex.messaging.
00000030 69 6f 2e 4f 62 6a 65 63 74 50 72 6f 78 79 0a 81 io.ObjectProxy
00000040 03 55 66 6c 65 78 2e 6d 65 73 73 61 67 69 6e 67 Uflex.messaging
00000050 2e 6d 65 73 73 61 67 65 73 2e 41 63 6b 6e 6f 77 .messages.Acknow
00000060 6c 65 64 67 65 4d 65 73 73 61 67 65 09 62 6f 64 ledgeMessage bod
00000070 79 11 63 6c 69 65 6e 74 49 64 1b 63 6f 72 72 65 y clientId corre
00000080 6c 61 74 69 6f 6e 49 64 17 64 65 73 74 69 6e 61 lationId destina
00000090 74 69 6f 6e 0f 68 65 61 64 65 72 73 13 6d 65 73 tion headers mes
View gist:549314
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" initialize="init()">
<mx:Script>
<![CDATA[
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
private function init() : void
{
core.addEventListener(ResultEvent.RESULT,
function(e:ResultEvent):void{ trace("Result: "+e.result); });
View el purkka.py
elif isinstance(field, models.ForeignKey) and\
field.rel.limit_choices_to:
key = field.rel.get_related_field().name
choices = field.rel.limit_choices_to
info.choices = list()
for choice in field.rel.to._default_manager.filter(**choices).values():
info.choices.append( (choice[key], unicode(choice.values()[0]),) )
info.shortName = '%s_id' % info.shortName
info.fullName = '%s_id' % info.fullName
@mharju
mharju / choice_game.py
Created Dec 19, 2010
Tässä vähän tämmöstä pikaista testiä! :)
View choice_game.py
from itertools import chain
import random
def shift(cards, shift):
return [ cards[(i - shift) % len(cards)] for i in range(0, len(cards) ) ]
def shuffle(cards, m):
return [ [ card for pos, card in enumerate(chain(*cards)) if pos % m == p ] for p in range(0, m) ]
def shift_amt(position, m, n):
View just_an_idea.js
var application = Sammy.Bundle('#element',
{
'base': my_app.base, // A Sammy.Application in its own right
'add-event': my_app.add_event // So is this
},
function() {
// Rules how to change states. Can be triggered by binding or routing?
this.get('#/add', function() {
this.setApplication('add-event');
@mharju
mharju / salaclip.sh
Created Apr 3, 2011
A function to include in your .zshrc to copy passwords to OS X clipboard from Sala
View salaclip.sh
SALADIR=~/.sala
function _sala_all {
(cd $SALADIR && find . | cut -d'/' -f 2,3 | grep '/' | grep -v '.git' | xargs)
}
function _salacomp {
reply=(`_sala_all`)
}
compctl -K _salacomp sc
function sc {