Skip to content

Instantly share code, notes, and snippets.

View raimohanska's full-sized avatar

Juha Paananen raimohanska

View GitHub Profile
@raimohanska
raimohanska / rue.coffee
Created February 7, 2014 11:18
testing bacon.bus
Bacon=require("baconjs")
s = Bacon.later(1000, "hello")
b = new Bacon.Bus()
b.plug(s)
b.log()
@raimohanska
raimohanska / .gitconfig
Created February 12, 2014 14:07
My .gitconfig
[user]
name = Juha Paananen
email = juha.paananen@gmail.com
[color]
ui = auto
diff = true
[alias]
st = status
stp = status --porcelain
br = branch
@raimohanska
raimohanska / waitForAngular.js
Created July 18, 2014 12:26
Wait until angularjs is done with processing its stuff
waitForAngular = function(el, angular, callback) {
try {
angular.element(el).injector().get('$browser').notifyWhenNoOutstandingRequests(callback);
} catch (e) {
callback(e);
}
};
@raimohanska
raimohanska / depth.js
Last active August 29, 2015 14:15
depth.js
#! /usr/bin/env node
var fs = require("fs")
var files = process.argv.slice(2)
if (!files.length) {
console.log("USAGE: depth.js file1 [file2 ...]")
}
files.forEach(function(filename) {
var object = JSON.parse(fs.readFileSync(filename))
console.log(filename, depth(object, ""))
function depth(object, path) {
@raimohanska
raimohanska / ByteStringHelper.hs
Created November 8, 2011 08:29
Haskell Data.ByteString <-> String conversion helper
module ByteStringHelper where
import Data.ByteString as B
import Data.String
unpack :: B.ByteString -> String
unpack = read . show
pack :: String -> B.ByteString
pack = read . show
@raimohanska
raimohanska / Transactional.hs
Created November 11, 2011 08:05
A simple Monad for Transactional actions
module Transactional(Transactional, Connection, transactionally, getConnection) where
data Connection = Connection
data Transactional a = Transactional (Connection -> IO a)
instance Monad Transactional where
(>>=) op toNext = Transactional $ \conn -> perform conn op >>= perform conn . toNext
return a = Transactional $ return . const a
getConnection :: Transactional Connection
@raimohanska
raimohanska / Authenticator.java
Created November 11, 2011 11:22
Android Google Authentication integration
import android.accounts.Account;
import android.accounts.AccountManager;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
@raimohanska
raimohanska / AesonTest.hs
Created December 2, 2011 20:53
Data.Aeson.Generic examples with Strings
{-# LANGUAGE OverloadedStrings, DeriveDataTypeable, NoMonomorphismRestriction #-}
module AesonTest where
import qualified Data.Aeson.Generic as A
import qualified Data.ByteString.Lazy as L8
import Data.Data
import Data.Typeable
import Codec.Binary.UTF8.String as U8
import Data.Maybe
@raimohanska
raimohanska / XmlClean.hs
Created December 12, 2011 12:46
Clean whitespace from XML
import Text.Regex.XMLSchema.String(match, sed)
clean :: String -> String
clean = sed (const "><") ">\\s*<" . trim
where trim = dropWhile whitespace . reverse . dropWhile whitespace . reverse
whitespace c = match "\\s" [c]
@raimohanska
raimohanska / Cache.scala
Created December 15, 2011 11:55
My first Scala cache
package com.karma.cache
import collection.immutable.HashMap
trait Cache[K, V] {
def get(key : K, fetch : (K => V)) : V
}
class NoCache[K, V] extends Cache[K, V] {
def get(key : K, fetch : (K => V)) : V = fetch(key)