Skip to content

Instantly share code, notes, and snippets.

View rethab's full-sized avatar
🏠
Working from home

rethab

🏠
Working from home
View GitHub Profile
@rethab
rethab / gist:5187689
Created March 18, 2013 14:51
Maybe inside IO Monad / MaybeT example
import Control.Monad (guard)
import Control.Monad.Trans.Maybe (MaybeT(..), runMaybeT)
import Control.Monad.Error
import Data.Char
readBoth :: IO (Maybe String)
readBoth = runMaybeT $ do a <- funA2
funB2 a
@rethab
rethab / lookuptables
Last active December 15, 2015 05:08
On-Demand values of Lookup-Tables.
/**
* This function generates elements of lookup tables. It is assumed that we
* have two dimensional lookup tables with x and y axis each ranging from 0
* to n (exclusive). For n, this means there are n^n^n possible
* permutations. <br />
* Example table (n = 3, perm = 1)
*
* <pre>
* y
* 0 1 2
public static void main(String[] args) {
int n = 3;
int elems = (int) Math.pow(Math.pow(n, n), n);
Set<String> perms = new HashSet<String>(elems);
for(int perm = 0; perm < elems; perm++) {
String num = "";
for (int x = 0; x < 3; x++) {
for (int y = 0; y < 3; y++) {
num = SmartMapper.lookup(x, y, perm, n) + num;
}
@rethab
rethab / pre-commit
Created May 27, 2014 12:05
Commit Hook: make sure no unwanted content gets commited
#!/bin/sh
#
SEARCH_DIRS="application/ library/COP/"
declare -a names=("Zend_Debug" "var_dump" "die(")
for UNWANTED_CONTENT in "${names[@]}"
do
if git grep $UNWANTED_CONTENT $SEARCH_DIRS > /dev/null 2>&1
then
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <mqueue.h>
#include <pthread.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <assert.h>
#include <errno.h>
@rethab
rethab / cryptocipher-example.hs
Created July 4, 2014 09:29
cryptocipher en-/decryption example
-- contrived from the example in the cryptocipher API
module Main where
import Crypto.Cipher
import qualified Data.ByteString as BS
import qualified Data.ByteString.Char8 as CBS
main = do
let ctx = initAES256 key
@rethab
rethab / grouper.hs
Last active August 29, 2015 14:10
group values of list of key values pairs
{-# LANGUAGE RecordWildCards #-}
import Control.Arrow (second)
import Control.Applicative ((<$>), (<*>))
import Data.List (groupBy, genericLength)
import System.Console.GetOpt (ArgDescr(..), ArgOrder(..))
import System.Console.GetOpt (OptDescr(..), getOpt, usageInfo)
import System.IO (hPutStrLn, stderr)
import System.Environment (getArgs)
import System.Exit (exitFailure)
@rethab
rethab / php-android-todo.php
Last active August 29, 2015 14:15
simple android todo app in php
<?php
// droid is coming from testnow.php
// all this app can do. corresponding functions are
// named do_XXX where XXX is the action
$actions = array('create', 'list', 'done', 'exit');
// database as array. read when started, saved on exit.
$data = null;
@rethab
rethab / WithFancyApp.scala
Last active January 23, 2016 06:01
Enhanced WithApplication class to test Play 2.4 applications with dependency injection using
/**
* Provides Messages implicit and the default Guice-Container
* into the context for testing Play 2.4 applications.
*
* Sample:
*
* "use the overridden bindigs" in new WithFancyApp(
* lang = Lang("en", "US"),
* overrideModules = Seq(bind[MyInterface].to[MyImplementation])
* ) {
@rethab
rethab / CancellableFuture.scala
Created June 16, 2016 07:41
Await.result doesn't cancel Futures on timeout
import java.util.concurrent.TimeUnit
import scala.concurrent.duration.Duration
import scala.concurrent.{Await, Future}
/**
* Test if Futures are cancelled once the duration of
* the await has timed out.
*
* This demonstrates, that even after the 'Await.result'