Skip to content

Instantly share code, notes, and snippets.

View panzi's full-sized avatar

Mathias Panzenböck panzi

View GitHub Profile
@panzi
panzi / getwebfont.sh
Last active December 15, 2015 21:18
This downloads all variants of a Google Web Font. Please be sure that the font in question uses a license that allows this.
#!/bin/bash
family=`echo "$1"|tr ' ' '+'`
filename=`echo "$1"|sed 's/ //g'`
weight=$2
subset=$3
if [ "$weight" != "" ]; then
family="$family:$weight"
filename="$filename-$weight"
// derived from https://github.com/django/django/blob/master/django/contrib/admin/static/admin/js/urlify.js
var TRANSLITERATE_MAP = {
// latin
'À': 'A', 'Á': 'A', 'Â': 'A', 'Ã': 'A', 'Ä': 'AE', 'Å': 'A', 'Æ': 'AE', 'Ç':
'C', 'È': 'E', 'É': 'E', 'Ê': 'E', 'Ë': 'E', 'Ì': 'I', 'Í': 'I', 'Î': 'I',
'Ï': 'I', 'Ð': 'D', 'Ñ': 'N', 'Ò': 'O', 'Ó': 'O', 'Ô': 'O', 'Õ': 'O', 'Ö':
'OE', 'Ő': 'O', 'Ø': 'O', 'Ù': 'U', 'Ú': 'U', 'Û': 'U', 'Ü': 'UE', 'Ű': 'U',
'Ý': 'Y', 'Þ': 'TH', 'ß': 'ss', 'à':'a', 'á':'a', 'â': 'a', 'ã': 'a', 'ä':
'ae', 'å': 'a', 'æ': 'ae', 'ç': 'c', 'è': 'e', 'é': 'e', 'ê': 'e', 'ë': 'e',
@panzi
panzi / mkplaylist.sh
Created June 21, 2013 01:54
Makes a playlist of all audio files in directory and all descendant directories. It detects audio files just by some well known file name extensions.
#!/bin/sh
dir="$1"
playlist="$2"
if [ "$playlist" = "" ]; then
playlist=playlist.m3u
fi
find "`readlink -f "$dir"`" -type f -and \( -iname '*.mp3' -or -iname '*.ogg' -or -iname '*.wav' -or -iname '*.flac' -or -iname '*.m4a' -or -iname '*.aac' -or -iname '*.wma' -or -iname '*.opus' \) > "$playlist"
@panzi
panzi / main.rs
Last active December 20, 2015 14:59
None-working unsafe weakrefs for rust (currently crashes the compiler, later it will crash any program that uses this). **Don't use this!** This is just an experiment.
use weakref::{Weakref,Weakrefs,Referred};
mod weakref;
struct Node {
weakrefs: ~Weakrefs<Node>,
parent: ~Weakref<Node>,
children: ~[~Node],
data: ~str
}
@panzi
panzi / blogger-social-share-privacy.html
Last active December 20, 2015 21:09
Please consider hosting of the scripts, styles and images yourself.
<link rel="stylesheet" type="text/css" href="http://panzi.github.io/SocialSharePrivacy/stylesheets/jquery.socialshareprivacy.min.css" />
<style type="text/css">
#content-wrapper {
position: relative;
}
#share {
position: absolute;
top: 0px;
left: -100px;
opacity: 0.3;
@panzi
panzi / conststruct.rb
Last active December 24, 2015 16:39
Very similar class to OpenStruct, except all instances are immutable. Use ConstStruct.derive("MyClass") to dynamically create a subclass (so instance.inspect gives a nicer/more specific class name).
class ConstStruct
def self.derive(name)
cls = Class.new(ConstStruct)
cls.instance_variable_set :@name, name
def cls.name; @name end
def cls.inspect; @name end
def cls.to_s; @name end
cls
end
@panzi
panzi / cexpr.sh
Last active December 25, 2015 16:59
Run some C code. -p to simply pass a printf format string and args, -iFILE to include FILE, -I -L -l -E -S -D and -O will be passed as such to gcc.Examples: CFLAGS=-std=c99 cexpr.sh 'puts("hello world");'; cexpr.sh -imath.h -lm -p '%g' 'log2(8)'
#!/bin/bash
do_printf=off
incs=""
flags="$CFLAGS"
only_preproc=off
no_asm=off
if [ "$CC" = "" ]; then
CC=gcc
@panzi
panzi / cppexpr.sh
Last active December 25, 2015 16:59
Print some C++ expresions. -iFILE to include FILE, -I -L -l -E -D -S and -O will be passed as such to g++. More compiler flags can be passed via -f$FLAG or $CXXFLAGS environment variable. Example: cppexpr.sh -f-std=c++0x -imath.h -lm 'log2(8)'
#!/bin/bash
incs=""
flags="$CXXFLAGS"
only_preproc=off
no_asm=off
no_space=off
if [ "$CXX" = "" ]; then
CXX=g++
@panzi
panzi / Makefile
Created November 10, 2013 17:22
Usage: visprim <width> <height> <output-filename> [number-of-threads]
CPP = g++
LIB = `Magick++-config --cppflags --cxxflags --ldflags --libs` -lboost_thread-mt
CPPFLAGS = -Wall -O3 `Magick++-config --cppflags --cxxflags`
LDFLAGS = $(LIB) -Wall -O3
BIN = visprim
.PHONY: all zip clean
all: $(BIN)
@panzi
panzi / visprim.py
Created November 10, 2013 17:24
Usage: python visprim.py <width> <height> <output-filename>
#!/usr/bin/env python
import sys
import Image
from itertools import islice
def primes():
yield False # 0
yield False # 1
yield True # 2