Skip to content

Instantly share code, notes, and snippets.

panzi /
Created Feb 10, 2014
Simple switch-case like thing for Python. I don't recommend using this or anything similar. This is just an exercise.
#!/usr/bin/env python
import re
from switch import switch
case = switch("Foo")
if case("bar"): # False
print repr("bar")
View gist:10319120
The really strange thumbr theme you are using causes some very strange things.
It loads some other website in a "fullscreen" iframe that then in turn loads your
tumblr in another iframe. This causes the Browser Ponies JavaScript to be executed
twice, once in the toplevel frame and once in the inner most iframe. However the
ponies in the toplevel frame are somehow not visible, but they still cost CPU power.
Anyway, if you want to have the ponies always in the background, add this to the
source of your tumblr:
<style type="text/css">#content { position: relative; z-index: 100000000; }</style>
panzi /
Last active Aug 29, 2015
search for vertical string in text file: python <search-string> [filename...]
#!/usr/bin/env python
from __future__ import with_statement, print_function
from collections import deque
from itertools import islice
def vertical_search(needle,haystack):
needle = tuple(needle)
n = len(needle)
if n == 0:
panzi / is_iterable.cpp
Created Aug 9, 2014
Match arrays and classes that implement methods needed to be iterable.
View is_iterable.cpp
// $ g++ -Wall -Wextra -Werror -pedantic -std=c++1y is_iterable.cpp -O3 -o is_iterable
#include <type_traits>
#include <iterator>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <array>
#include <set>
#include <map>
panzi /
Created Aug 12, 2014
A trivial shell script that deletes the files logged in install_manifest.txt (as written by cmake).
if [ $# -eq 0 ]; then
elif [ -d "$1" ]; then
panzi /
Last active Aug 29, 2015
Bookmarklet to find bigger version of an image on tumblr.

Copy this link and create bookmark with this as it's URL in your bookmark toolbar:

javascript:(function(){"use strict";function t(t){function l(e){var t=new XMLHttpRequest;t.onload=function(){if(this.status>=200&&this.status<400){a.push(e)}};t.onloadend=c;"HEAD",r+e+s,true);t.send();++f}function c(){--f;if(f===0){if(a.length>0){a.sort(function(e,t){return e-t});var e=r+a[a.length-1]+s;location.href=e}else{alert("No bigger image found.")}}}var n=/^(.*_)(\d+)(\.[a-z]+)$/i.exec(t);if(!n){alert("Not a tumblr image URL.");return}var r=n[1];var i=Number(n[2]);var s=n[3];var o=null;for(var u=0;u<e.length;++u){if(e[u]>i){o=u;break}}if(o===null){alert("There is no bigger known size.");return}var a=[];var f=0;for(var u=o;u<e.length;++u){l(e[u])}}var e=[75,100,250,400,500,1280];t(location.href)})()

Then when you view a tumblr image and suspect that there is a bigger version of it click this bookmarklet.

panzi /
Created Sep 25, 2014
Tool to test if your server is affected by the shellshock vulnerability. Please use it responsibly.
payload="() { :;};echo;echo $tag;exit"
function shellshock () {
response=`curl --header "$header: $payload" --silent --insecure "$url"`
panzi /
Created Oct 8, 2014
Find SQLite files and vacuum them. (E.g. to really clear deleted browser history.)
# Usage: ./ ~/.config/google-chrome ~/.mozilla
find "$1" -type f -print0|while read -d $'\0' fname; do
type=`file -b "$fname"`
case "$type" in
echo "$fname"
sqlite3 "$fname" "VACUUM;" || exit $?
fn main() {
let args = os::args();
let mut washed_args = Vec::new();
for arg in args.iter() {
match washed_args.as_slice() {
[_, "review", opts..] => { review(opts) }
_ => { usage() }
panzi /
Last active Aug 29, 2015
simple grouping function in Python
from collections import defaultdict
__all__ = 'group_by', 'index_by'
def group_by(iterable, key):
grouped = defaultdict(list)
for item in iterable:
return grouped
You can’t perform that action at this time.