Skip to content

Instantly share code, notes, and snippets.

View miikka's full-sized avatar

Miikka Koskinen miikka

View GitHub Profile
#!/bin/sh
xsel | xmessage -buttons ok:2,not:0 -file - -timeout 4
if [ $? -eq 2 ]; then
xsel | pk notes -s
fi
@miikka
miikka / Simple.hs
Created August 24, 2010 19:07
Simple Haskell Twitter OAuth example
{-# LANGUAGE PackageImports #-}
{-
You need to register your Twitter application at <http://dev.twitter.com/>
to get the consumer key and secret needed for OAuth. When connecting to
Twitter for the first time, do this:
let consumer = Consumer "consumer key" "consumer secret"
token <- authenticate
@miikka
miikka / snap-helloworld.cabal
Created October 5, 2010 13:16
Snap project template.
Name: snap-helloworld
Version: 0.1
Category: Web
Build-type: Simple
Cabal-version: >=1.6
Executable snap-helloworld
HS-Source-dirs: src
Main-is: Main.hs
Other-modules:
@miikka
miikka / Main.hs
Created November 8, 2010 15:12
Haddock breaks when a module uses quasiquotes.
{-# LANGUAGE QuasiQuotes #-}
import Quasi
f [$qq|test|] = True
f _ = False
main = do
print [$qq|test|]
print $ f [$qq|test|]
# A min-heap.
type
TNode[T] = tuple[priority: int, data: T]
TBinHeap[T] = object
heap: seq[TNode[T]]
last: int
PBinHeap[T] = ref TBinHeap[T]
@miikka
miikka / Sass.hs
Created February 20, 2011 14:11
Hakyll + Sass
module Sass (sass) where
import Control.Monad.IO.Class (liftIO)
import Text.Hakyll.File (makeDirectories, toDestination)
import Text.Hakyll.HakyllAction (HakyllAction(..), runHakyllActionIfNeeded)
import Text.Hakyll.HakyllMonad (Hakyll)
import System.FilePath (replaceExtension)
import System.Process (readProcess)
@miikka
miikka / facecrop.py
Created April 7, 2012 20:00
Create a thumbnail of a face photo.
#!/usr/bin/python
# A small script to create a square thumbnail out of a picture of a human face.
# Written by Miikka Koskinen (http://miikka.me/) on 2012-04-07.
# Based on:
# http://recursive-design.com/blog/2010/12/14/face-detection-with-osx-and-python/
import cv
import sys
@miikka
miikka / my_popen.c
Created October 2, 2012 15:00
Capturing the output of an external program in C
#include <stdio.h>
#include <unistd.h>
int my_popen(char *cmd, FILE *handles[2]) {
/* Naming convention: the child's input and output */
int input[2];
int output[2];
pipe(input);
pipe(output);
function eval_(foo) {
return eval(foo);
}
eval_("var quux = 1");
eval_("console.log(quux)");
#include <ctime>
#include <iostream>
int main(int argc, char**argv)
{
std::time_t start = std::time(NULL);
while (std::time(NULL) - start < 10) {
std::cout << "piip!" << std::endl;
sleep(1);