Skip to content

Instantly share code, notes, and snippets.

@panzi
panzi / example.py
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.
View example.py
#!/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
panzi / vsearch.py
Last active Aug 29, 2015
search for vertical string in text file: python vsearch.py <search-string> [filename...]
View vsearch.py
#!/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
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
panzi / cmake_uninstall.sh
Created Aug 12, 2014
A trivial shell script that deletes the files logged in install_manifest.txt (as written by cmake).
View cmake_uninstall.sh
#!/bin/sh
if [ $# -eq 0 ]; then
manifest=install_manifest.txt
elif [ -d "$1" ]; then
manifest="$1/install_manifest.txt"
else
manifest="$1"
fi
@panzi
panzi / bookmarklet.md
Last active Aug 29, 2015
Bookmarklet to find bigger version of an image on tumblr.
View bookmarklet.md

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