Skip to content

Instantly share code, notes, and snippets.

@niklasb
niklasb / tlds_to_js_regex.py
Created Jan 15, 2012
Extract TLDs from Chrome's effective_tld_names.dat and dump as a Javascript regex
View tlds_to_js_regex.py
import re
import sys
import codecs
def js_str_chunks(l, n):
tmp = []
size = 0
for x in l:
char_size = len(repr(x)) - 3
if size + char_size > n:
@niklasb
niklasb / convert-to-mp4.sh
Created Jan 29, 2012
Convert video to MP4 for Android
View convert-to-mp4.sh
#!/bin/bash
if [[ $# != 2 ]]; then
echo >&2 "Syntax: $0 infile outfile"
fi
ffmpeg -i "$1" -s 480x320 -vcodec mpeg4 -acodec libfaac -ac 1 -ar 16000 -r 15 -ab 32000 -aspect 3:2 -threads 12 "$2"
@niklasb
niklasb / googlers_minimal.py
Created Apr 19, 2012
Codejam 2012 - Dancing with the Googlers
View googlers_minimal.py
def acc(p, total):
best, rest = divmod(total + 2, 3)
return (1, 0) if best >= p else (0, total and rest and best + 1 == p)
for i, line in enumerate(input() for _ in range(int(input()))):
_, S, p, *totals = map(int, line.split())
a, s = map(sum, zip(*(acc(p, total) for total in totals)))
print("Case #%d: %d" % (i + 1, a + min(s, S)))
View gist:3318047
require 'savon'
require 'pry'
url = 'http://kim-cm-bts01.scc.kit.edu/HeadingTreeService/HeadingTreeService.svc?wsdl'
client = Savon::Client.new do
wsdl.document = 'http://kim-cm-bts01.scc.kit.edu/HeadingTreeService/HeadingTreeService.svc?wsdl'
http.proxy = "http://dtun.de:9999"
end
@niklasb
niklasb / gist:3318976
Created Aug 10, 2012
More from Savon
View gist:3318976
require 'savon'
url = 'http://kim-cm-bts01.scc.kit.edu/HeadingTreeService/HeadingTreeService.svc?wsdl'
client = Savon::Client.new do
wsdl.document = url
http.proxy = "http://dtun.de:9999"
http.auth.basic "heroku", "XXX"
end
@niklasb
niklasb / primegen.cpp
Last active Dec 17, 2015
Generate primes < 10^9
View primegen.cpp
#include <iostream>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long ll;
View Code Golf SE Aristoteles
#include <bits/stdc++.h>
using namespace std;
#define R(i,e)for(I i=1;i<min(20,e);++i)
#define X(x) if(x<1||V[x])continue;V[x]=x;
#define J(a,b,c) X(a)X(b)X(c)
#define P printf
#define D "%2d "
typedef int I;I T=38;I main() {
I V[T];
R(h,20)R(c,20)R(s,20)
View keybase.md

Keybase proof

I hereby claim:

  • I am niklasb on github.
  • I am nba (https://keybase.io/nba) on keybase.
  • I have a public key whose fingerprint is EFA9 7C96 C0CD 9721 101F 5D67 7784 A6C0 F0BD 08CF

To claim this, I am signing this object:

@niklasb
niklasb / wtfregexp.py
Created Dec 26, 2014
solution for ADCTF2014 wtfregexp
View wtfregexp.py
import random
f = open("wtfregexp.pl", "r")
reg = f.readlines()[0]
reg = reg[reg.index('/')+1:-3]
clauses = []
maxi = 0
for l in reg.split(','):
l = l[3:-1].replace("[01]", ".")
View pubkey_laptop
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDM4dCzsln+r77vUypKy47W1Hlp1DtBLIFCscYTXuWZgcBnu/yl50p64HfYk5VPi95hUNsHujfdHWWg4dDLUVWnya7I6vbFJh1WIUscTB9+aOzTa7MkH5etliYWhecrb/UuAJ8Crx43nFpYlo2PVrePKy0jeODZqnWB5SMS7Bgl8hW6Rtcg4xuc2MnEprOINg0CzY1cCb9ZHL0UqBW9hzNiJRmhSgq+WLL4f07y2SsEewNg88KXcvfgYqKzxYdc1zNLb9zUhrw39dngAXTssG5SX2IdlOD8JsjxGPT2FovKuQsDOOKb0MibfETsT1qF1XQ4h7mNL7ig/rmmq7Nwnqrp niklas@grampa