Skip to content

Instantly share code, notes, and snippets.

View andrelaszlo's full-sized avatar
🤓

André Laszlo andrelaszlo

🤓
View GitHub Profile
@andrelaszlo
andrelaszlo / argparse_interactive.py
Created October 31, 2014 14:52
Incomplete example function that lets a user fill out the parameters for an ArgumentParser interactively
def run_interactive(parser):
"""Inspect the argument parser and let the user decide on values for
all parameters interactively.
"""
args = []
print "You are running this script in interactive mode. " + \
"Press C-d to abort. Run with --help to see more options."
try:
@andrelaszlo
andrelaszlo / dc_sum.py
Last active August 29, 2015 14:08
Python version of the dc command found here http://stackoverflow.com/a/453290/98057
### Implement some commands from dc
registers = {'r': None}
stack = []
def add():
stack.append(stack.pop() + stack.pop())
def z():
stack.append(len(stack))
def less(reg):
if stack.pop() < stack.pop():
registers[reg]()
@andrelaszlo
andrelaszlo / drop_shell.py
Created November 3, 2014 15:27
Start interactive shell inside pythons cript
def drop_shell(global_vars, local_vars):
""" Call with drop_shell(global_vars().copy(), locals()) """
import readline # optional, will allow Up/Down/History in the console
import code
global_vars.update(local_vars)
shell = code.InteractiveConsole(global_vars)
shell.interact()
@andrelaszlo
andrelaszlo / PitTree.scala
Created October 28, 2009 22:41 — forked from AlexanderWingard/PitTree.scala
Added the new pretty toString method
class PitTree[T](val children : Map[String, PitTree[T]], val value : Option[T]) extends Map[String, T] {
def this() = this(Map(), None)
def this(value : T) = this(Map(), Some(value))
def update(path : String, upVal : T) : PitTree[T] = update(splitPath(path), upVal)
def update(path : List[String], upVal : T) : PitTree[T] = path match {
case Nil =>
new PitTree[T](upVal)
case h :: t =>
val child = children.getOrElse(h, new PitTree[T]()).update(t, upVal)
new PitTree[T](children + (h -> child), value)
@andrelaszlo
andrelaszlo / logo.png
Created September 4, 2011 21:27
Control the alsa volume (up/down/mute/set to x%) from the command line or in scripts
logo.png
@andrelaszlo
andrelaszlo / gist:2044696
Created March 15, 2012 15:07
haskell-mode
; haskell mode
(load "~/elisp/haskell-mode-2.8.0/haskell-site-file")
(add-hook 'haskell-mode-hook 'turn-on-haskell-doc-mode)
;These tree indentation modes are mutually exclusive
(add-hook 'haskell-mode-hook 'turn-on-haskell-indentation)
;;(add-hook 'haskell-mode-hook 'turn-on-haskell-indent)
;;(add-hook 'haskell-mode-hook 'turn-on-haskell-simple-indent)
<html>
<head><title>Kombinationer</title></head>
<body>
<script>
// shorthand function
function $(id) {
return document.getElementById(id);
}
@andrelaszlo
andrelaszlo / duego-preregister.user.js
Created April 26, 2012 22:56
Show desktop notification (chrome) when the duego.com pre-register page updates
// ==UserScript==
// @match http://duego.com/preregister*
// @require http://code.jquery.com/jquery-1.4.2.min.js
// ==/UserScript==
var load,execute,loadAndExecute;load=function(a,b,c){var d;d=document.createElement("script"),d.setAttribute("src",a),b!=null&&d.addEventListener("load",b),c!=null&&d.addEventListener("error",c),document.body.appendChild(d);return d},execute=function(a){var b,c;typeof a=="function"?b="("+a+")();":b=a,c=document.createElement("script"),c.textContent=b,document.body.appendChild(c);return c},loadAndExecute=function(a,b){return load(a,function(){return execute(b)})};
loadAndExecute("//ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js", function() {
function Notifier() {};
@andrelaszlo
andrelaszlo / activate
Last active March 17, 2016 15:20
Modified virtualenv2 activate script
# This file must be used with "source bin/activate" *from bash*
# you cannot run it directly
# This script was modified to introduce the following features:
# * Save and restore PYTHONPATH on activate/deactivate
# * Source .virtualenvrc if it exists
deactivate () {
unset pydoc

Keybase proof

I hereby claim:

  • I am andrelaszlo on github.
  • I am sibilant (https://keybase.io/sibilant) on keybase.
  • I have a public key ASAKC1ZDD5z85BC8yXhLazRLqad48O593CtMoupET-WBiAo

To claim this, I am signing this object: