Skip to content

Instantly share code, notes, and snippets.

@carlohamalainen
carlohamalainen / corrector.hs
Last active December 27, 2015 08:59
bitwise fiddling in Haskell
{-
Response to http://lists.samba.org/archive/linux/2013-November/032604.html
and http://lists.samba.org/archive/linux/2013-November/032610.html
Author: Carlo Hamalainen <[email protected]>
-}
import Control.Monad
import Data.Binary.Get
import Data.Bits
@carlohamalainen
carlohamalainen / mincworkflow.py
Last active December 26, 2015 09:49
Test workflow for the new MINC interface in Nipype.
# Artificial example (averaging and then dumping) using the new
# MINC interface in Nipype.
#
# Carlo Hamalainen <[email protected]>
import os
import nipype.interfaces.minc as minc
import nipype.interfaces.io as nio
import nipype.interfaces.utility as util
import nipype.pipeline.engine as pe
@carlohamalainen
carlohamalainen / applicativeForm.hs
Created July 24, 2013 00:05
applicative recaptcha
-- Before:
commentForm :: EntryId -> Form Comment
commentForm entryId = renderDivs $ Comment
<$> pure entryId
<*> aformM (liftIO getCurrentTime)
<*> aformM requireAuthId
<*> areq textField (fieldSettingsLabel MsgCommentName) Nothing
<*> areq textareaField (fieldSettingsLabel MsgCommentText) Nothing
-- Adding the ReCAPTCHA form, we just append "<* recaptchaAForm":
@carlohamalainen
carlohamalainen / nondeterminism_active.py
Last active December 17, 2015 12:29
nondeterministic behaviour of inspect().active() in celery
######### blah.py #########
from time import sleep
from celery import Celery
from celery.task import Task
import logging
import traceback
import time
-- Easiest way to run this with ghci:
--
-- ghci -XDataKinds -XGADTs -XEmptyDataDecls -XKindSignatures -XScopedTypeVariables -XTemplateHaskell
-- Natural numbers, e.g.
-- 0 == Z
-- 1 == S Z
-- 2 == S (S Z)
-- 3 == S (S (S Z))
-- etc
@carlohamalainen
carlohamalainen / joomla_password.py
Created May 6, 2013 03:40
Create a Joomla password hash/salt entry using Python
import getpass
import hashlib
import random
import string
password = getpass.getpass('password (not echoed): ')
salt = ''.join(random.choice(string.ascii_lowercase + string.ascii_uppercase + string.digits) for x in range(32))
password_hash = hashlib.md5(password + salt).hexdigest()
print "update CHANGEME_users set password='" + password_hash + ':' + salt + "' where id = ...;"
@carlohamalainen
carlohamalainen / plot_shapefile_on_map.py
Created April 17, 2013 00:50
Plot polygons for a bunch of shapes using basemap.
"""
Carlo Hamalainen <[email protected]>
Given a directory of shapefiles, e.g.
$ ls /path/to/shapefiles/
Project_Name.dbf
Project_Name.prj
Project_Name.sbn
Project_Name.sbx
@carlohamalainen
carlohamalainen / cvl.sh
Created March 15, 2013 03:31
Install basic packages for a CVL system.
#!/bin/bash
# Author: Carlo Hamalainen <[email protected]>
# Use at your own risk :)
set -e
set -x
sudo yum -y install vim
@carlohamalainen
carlohamalainen / ioaction.py
Created March 6, 2013 02:36
Pretend IO actions in Python
# IO actions on integers:
#
# data IOAction = Return Int
# | Put Int (IOAction Int)
# | Get (Int -> IOAction Int)
#
# Implement using nested lists, e.g.
#
# [Return, 3] == Return 3
#
@carlohamalainen
carlohamalainen / Simple.hs
Last active December 14, 2015 12:38
Response to Immanuel Normann on haskell-cafe thread "simple parsec question"
{-# LANGUAGE FlexibleContexts #-}
import Text.Parsec
import Control.Applicative hiding ((<|>),many)
-- Example input:
{-
top 1: