Skip to content

Instantly share code, notes, and snippets.

@carlohamalainen
carlohamalainen / shrink_pdf.sh
Created November 8, 2011 00:46
Shrink a PDF file by transferring to DJVU, then PS, then back to PDF.
#!/bin/bash
set -o nounset # explode on undefined variables
set -e # explode if any command fails
# Best way to shrink a PDF of scanned pages without losing quality. Found on
# http://ubuntuforums.org/archive/index.php/t-1133357.html
# example: ./shrink_pdf.sh big_file.pdf 600 small_file.pdf
@carlohamalainen
carlohamalainen / tunnel.py
Created September 29, 2012 12:06
check ssh tunnel from Python
"""
From the man page for ssh:
-f Requests ssh to go to background just before command execution. This is useful if ssh is going to ask
for passwords or passphrases, but the user wants it in the background. This implies -n. The recommended way
to start X11 programs at a remote site is with something like ssh -f host xterm.
If the ExitOnForwardFailure configuration option is set to “yes”, then a client started with -f will wait
for all remote port forwards to be successfully established before placing itself in the background.
@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 = ...;"

Keybase proof

I hereby claim:

  • I am carlohamalainen on github.
  • I am carlohamalainen (https://keybase.io/carlohamalainen) on keybase.
  • I have a public key whose fingerprint is 7679 121C 2296 4C12 8888 93D1 269E 0DC4 E3E4 A5B8

To claim this, I am signing this object:

@carlohamalainen
carlohamalainen / ghc-7.6.3 vs Cabal-1.18
Created January 23, 2014 08:15
ghc-7.6.3 vs Cabal-1.18
Resolving dependencies...
cabal: Could not resolve dependencies:
trying: ghc-imported-from-0.1.0.0 (user goal)
next goal: Cabal (dependency of ghc-imported-from-0.1.0.0)
rejecting: Cabal-1.16.0/installed-c6e... (conflict: ghc-imported-from =>
Cabal>=1.18)
trying: Cabal-1.18.1.2
next goal: ghc (dependency of ghc-imported-from-0.1.0.0)
rejecting: ghc-7.6.3/installed-189... (conflict: Cabal==1.18.1.2, ghc =>
Cabal==1.16.0/installed-c6e...)
{-
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 <carlo@carlo-hamalainen.net>
-}
import Control.Monad
import Data.Binary.Get
import Data.Bits
@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 <carlo@carlo-hamalainen.net>
-}
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 <carlo@carlo-hamalainen.net>
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