Skip to content

Instantly share code, notes, and snippets.

View freddyb's full-sized avatar

Frederik B freddyb

View GitHub Profile
@freddyb
freddyb / rssgrep.py
Created November 4, 2011 21:42
grep for keywords in rss files
import feedparser
import datetime
def main(urls, keywords):
keywords = map(lambda x: x.lower(), keywords)
for url in urls:
print "Starting to parse", url
feed = feedparser.parse(url)
for item in feed['items']:
title_text = item['title_detail']['value']
@freddyb
freddyb / debug_net.py
Created March 22, 2012 08:09
whenever my intarwebs fail, I debug my connection with this old, dirty hack of a python script
#!/usr/bin/env python
import subprocess
def get_default_gw():
''' returns ip address of default gateway as a string'''
res = subprocess.check_output(['route','-n'])
for line in res.split('\n'):
if line.startswith('0.0.0.0'):
@freddyb
freddyb / check_minified.js
Created May 10, 2012 21:18
check code integrity of JS files for ZeroBin
function getSource(a){x=new XMLHttpRequest;x.open("GET",a,false);try{x.send()}catch(b){console.dir("Could not get JavaScript source due to some external JS references");alert("Code Integrity check failed")}sources.push(x.response.replace(/\s+/g,""));if(sources.length==document.scripts.length){computedHash=Sha256.hash(sources.join(""));console.dir("Hash of all JavaScript is "+computedHash);if(computedHash=="43958ba2baa4cc09552a52066cb13cd732141a4a920f6b4873c44f643ed1985b"){alert("Code Integrity verified")}else{alert("Warning, code integrity error. Do not trust this site with your code")}}}var Sha256={};Sha256.hash=function(a,b){b=typeof b=="undefined"?true:b;if(b)a=Utf8.encode(a);var c=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,11392
@freddyb
freddyb / check.js
Created May 10, 2012 21:19
check code integrity of JS files for ZeroBin (uncompressed version)
// checking integrity of JS files by freddyb
// using SHA256 by Chris Veness, licensed under LGPL
// but, to be honest, do whatever the heck you want
// it's not black magic, you know ;)
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/* SHA-256 implementation in JavaScript | (c) Chris Veness 2002-2010 | www.movable-type.co.uk */
/* - see http://csrc.nist.gov/groups/ST/toolkit/secure_hashing.html */
/* http://csrc.nist.gov/groups/ST/toolkit/examples.html */
@freddyb
freddyb / pickle_compiler.py
Created August 15, 2012 14:36
compile arbitrary python source code into pickle format. will execute on unpickling
## Frederik Braun, Jun 2011
## Contact: <fb(AT)frederik-braun.com>
## Licence: WTFPL
## Python 2.7x
try:
import cPickle as pickle
except ImportError:
import pickle
@freddyb
freddyb / cidrator.py
Created October 6, 2012 20:58
python iterator that returns IP addresses (as strings) for given ip/cidr string
class cidrator():
def __init__(self, mask ="192.168.1.1/16", skip255=True, skip0=True):
self.skip255 = skip255
self.skip0 = skip0
addr, rng = mask.split("/")
addr_int = sum((256**(3-i) * int(b)) for i,b in enumerate(addr.split (".")))
self.start = addr_int & int("0b"+("1"*int(rng)) + "0"*(32-int(rng)),2)
self.stop = addr_int | int("0b"+("0"*int(rng)) + "1"*(32-int(rng)),2)
self.current = self.start
@freddyb
freddyb / merge_into_png.py
Created January 23, 2013 10:17
merge a file as a text-chunk into a given png, Usage: merge_into_png.py <file> <png>
#!/usr/bin/env python
"""
Length Chunk type Chunk data CRC
4 bytes 4 bytes Length bytes 4 bytes
89 50 4E 47 0D 0A 1A 0A
@freddyb
freddyb / gist:7581901
Created November 21, 2013 13:53
join2Async, could be easily expanded to N-size. looked useful but then didn't solve the problem. dumping here so I may use it when in need. hopefully this makes it easier to find: join queue parallel asynchronous synchronous add flush empty enqueue dequeue
/* this queue-style thing accepts a callback
and calls it when it has two results attached
usage:
j2a = new join2Async(console.log);
setTimeout( 'j2a.addResult("foo")', Math.ceil(Math.random()*10));
setTimeout( 'j2a.addResult("var")', Math.ceil(Math.random()*10));
// enjoy the race and see who's first \o/
*/
function join2Async(cb) {
// join 2 async call and return once *both* are done.
@freddyb
freddyb / anonabox-is-not-a-magic-bullet.md
Last active August 29, 2015 14:07
My personal notes on Anonabox and anonymity with Tor

The master version of this document has now been moved to my blog

Anonabox is not a magic bullet!

Yesterday, a lot of mainstream media (e.g., WIRED) started reporting about anonabox, an "an open source embedded networking device designed specifically to run Tor.", to quote their Kickstarter campaign.

For those of you who don't know what Tor is: It's a network run by volunteers that anonymizes your internet traffic. With everyone in the network using someone else's address from time to time, it is becoming harder for an observer (e.g. the websites you browse) to find out who is who.

Advertisements & Social Media kill Anonymity

@freddyb
freddyb / twitter_gazebo.md
Last active August 29, 2015 14:25
The Twitter Gazebo

The Twitter Gazebo (DRAFT)

################################################################################################################