Skip to content

Instantly share code, notes, and snippets.

View arnar's full-sized avatar

Arnar Birgisson arnar

View GitHub Profile
### Password hashing
def hash_pwd(pwd, salt=None, rounds=2**16):
"""Hashes a password using 2**16 rounds of SHA512 and a 64-bit salt.
The salt and hash result are concatenated and returned as a hexdigest.
"""
# Note: if this turns out to be too slow, consider using the py-bcrypt package
if salt is None:
# Note: Do not use python's random module for crypto!
salt = os.urandom(8)
@arnar
arnar / deck.py
Created July 16, 2012 19:38
When you don't have a deck of cards
import random
def makeDeck():
ranks = 'Ace Two Three Four Five Six Seven Eight Nine Ten Jack Queen King'.split()
suits = 'Hearts Clubs Spades Diamonds'.split()
return ['%s of %s' % (r,s) for r in ranks for s in suits]
def draw(deck):
card = random.choice(deck)
deck.remove(card)
@arnar
arnar / gist:1717737
Created February 1, 2012 16:06
Generate all interleavings in two lists (Haskell)
interleave :: [a] -> [a] -> [[a]]
interleave [] [] = []
interleave as [] = [as]
interleave [] bs = [bs]
interleave as bs = [ (head as):arest | arest <- interleave (tail as) bs ]
++ [ (head bs):brest | brest <- interleave as (tail bs) ]
--- setnohs.sorted 2012-01-27 11:45:01.768205853 +0100
+++ seths.sorted 2012-01-27 11:45:23.088143702 +0100
@@ -0,0 +1,2 @@
+n
+t
@@ -21,2 +23,2 @@
-noballooneval
- balloonexpr=
+ ballooneval
+ balloonexpr=GHC_TypeBalloon()
---
layout: page
categories:
- title: Journal Papers
publications:
- title: Rule Formats for Determinism and Idempotency (journal version)
date: 31.03.2010
authors:
- Luca Aceto
- Arnar Birgisson
diff --git a/src/Syntax.hs b/src/Syntax.hs
index 1905488..475a02a 100644
--- a/src/Syntax.hs
+++ b/src/Syntax.hs
@@ -2,6 +2,7 @@
module Syntax where
import Labels
+import Control.Monad.State
import Data.Generics
;; Personal prefs.
(setq user-mail-address "x")
(global-set-key "\C-w" 'backward-kill-word)
(global-set-key "\C-x\C-k" 'kill-region)
;; Packages and bundles
(add-to-list 'load-path "~/.emacs.d/")
(add-to-list 'load-path "~/.emacs.d/color-theme-6.6.0")
;; Viper mode
# Project Euler problem 102
# Which side of the line AB is the point P?
# (The dot product of AP and the perpendicular to AB)
def side((ax,ay), (bx,by), (px,py)):
return (bx - ax) * (py - ay) - (by - ay) * (px - ax)
def same_side(a, b, p, q):
sp = side(a, b, p)
sq = side(a, b, q)
@arnar
arnar / spotifyctrl.py
Created October 31, 2011 16:18
Control Spotify from a bottle script
from bottle import route, run, debug
import subprocess
def sendkeys(*keys):
subprocess.call(['xdotool', 'search', '--name', 'Spotify Premium - Linux Preview', 'key'] + list(keys))
return "ok\n"
@route('/pause')
@route('/play')
def play(): return sendkeys('space')
@arnar
arnar / gist:1310968
Created October 25, 2011 00:46
Goodbye...
;int main(void) { printf( /*
(format t ;*/
"goodbye dmr and jmc, thanks for everything!"
); return 0; } /*
(quit)
;*/