Skip to content

Instantly share code, notes, and snippets.

View arnar's full-sized avatar

Arnar Birgisson arnar

View GitHub Profile
@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)
### 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 / gist:3838851
Created October 5, 2012 09:06
pyramid_debugtoolbar and requirejs conflict
from wsgiref.simple_server import make_server
from pyramid.config import Configurator
from pyramid.response import Response
def main(request):
return Response('''
<html>
<head>
<script src="http://requirejs.org/docs/release/2.1.0/minified/require.js"></script>
exports.config =
# See docs at http://brunch.readthedocs.org/en/latest/config.html.
modules:
definition: false
wrapper: (path, data) ->
if data.match /^\s*define\s*\(\s*\[/
data.replace(/^(\s*define\s*\()/, "$1#{path}, ")
else
"""
define(#{path}, ['require', 'jquery'], function(require, $) {
@arnar
arnar / gist:5143144
Last active December 14, 2015 20:19
Monitor.registerStub = function (name, fun) {
Monitor.prototype[name] = function () { return fun.apply(this, arguments); }
}
@arnar
arnar / gist:5627777
Last active December 17, 2015 14:49
arnar@air:/tmp$ cat lennartsurl.json
{"totalPoints":14395,"version":1,"rounds":[["round","lat","lng","gLat","gLng","cLat",[null],"cLng",[null],"points"],[1,53.774101,87.18442600000003,46.07323062540838,4.21875,0,0,1337],[2,-31.704593,137.22421099999997,-26.431228064506424,132.890625,0,0,2296],[3,46.165393,14.310496999999941,47.754097979680026,14.58984375,0,0,2845],[4,22.218447,114.211588,22.375476015564765,114.1534423828125,0,0,5210],[5,-15.780246,-47.92931199999998,-13.923403897723334,-49.21875,0,0,2707]],"isChallenge":false,"challengeScore":null}
arnar@air:/tmp$ for url in $(cat lennartsurl.json \
| jq -r '.rounds[1:][] | @uri "http://maps.googleapis.com/maps/api/geocode/json?latlng=\(.[1]),\(.[2])&sensor=true"'); do \
curl -s $url | jq '.results[0].formatted_address'; \
done
"ulitsa Vodopadnaya, Novokuznetsk, Kemerovo Oblast, Russia, 654000"
"Stuart Highway, Mount Gunson SA 5710, Australia"
#ifndef _SHELLCODE_H
#define _SHELLCODE_H
static char shellcode[] =
"\xb9\xff\xff\xff\xff"
"\x31\xc0" //sets real user id from effective user id.
"\xb0\x31"
"\xcd\x80"
var spawn = require('child_process').spawn;
var midi = require('midi');
// Set up a new input.
var input = new midi.input();
var sharpnames = ['c', 'cis', 'd', 'dis', 'e', 'f', 'fis', 'g', 'gis', 'a', 'ais', 'b'];
var flatnames = ['c', 'des', 'd', 'es', 'e', 'f', 'ges', 'g', 'as', 'a', 'bes', 'b'];
var notenames = flatnames;
@arnar
arnar / cph
Created October 25, 2013 19:23
Things to check out:
Ny Carlsberg Glyptotek - a museum mostly with scupltures, but nice atmosphere
The round tower http://www.rundetaarn.dk/
Nice tower in the center with good views. Has a spiral road fit for a horse carriage
to the top because the king was too lazy to walk.
Nyhavn, Stroget and Kobmagergade, but probably you know these already.
http://www.cph-bike-rental.dk/ Nice bike rental
% Chapter headers and other customizations (fold)
\newenvironment{pabstract}{{\sc abstract}\hspace{.5em}\small}{}
\usepackage{titlesec}
\titleformat{\section}{\large\bfseries}{\protect\makebox[0pt][r]{\thesection\quad}}{0pt}{}
\titleformat{\subsection}{\bfseries}{\protect\makebox[0pt][r]{\thesubsection\quad}}{0pt}{}
\titlespacing*{\paragraph}{0pt}{.7em}{1em}
\setcounter{chapter}{-1}