Skip to content

Instantly share code, notes, and snippets.

View fb55's full-sized avatar

Felix Boehm fb55

View GitHub Profile
@fb55
fb55 / gist:3737020
Created September 17, 2012 12:28
ClosingTags
/*
Tags that have a special meaning in HTML
Every tag can have the following properties:
* parent: A list of all possible parent nodes. If none is present, the tag is wrapped in the first one.
* prev: A list of tags that need to preceed the tag. If they don't exist, they are created.
* past: A list of tags that needs to follow the tag.
* close: A list of elements that are closed when the tag appears. Only walks until it finds the next required parent.
* children: The possible child nodes. Can be a list, false or "text".
* If a list, it's a list of elements that need to be included in the tag. If they don't exist, they are created.
@fb55
fb55 / parse.js
Created May 15, 2012 08:00
Node querystring module test
var newQS = require("./new.js"),
oldQS = require("./old.js"),
bench = require("bench");
//taken from https://github.com/joyent/node/blob/master/test/simple/test-querystring.js
var tests = ["foo=918854443121279438895193", "foo=bar", "foo=bar&foo=quux", "foo=1&bar=2", "my+weird+field=q1%212%22%27w%245%267%2Fz8%29%3F", "foo%3Dbaz=bar", "foo=baz=bar", "str=foo&arr=1&arr=2&arr=3&somenull=&undef=", " foo = bar ", "foo=%zx", "foo=%EF%BF%BD", "hasOwnProperty=x&toString=foo&valueOf=bar&__defineGetter__=baz", "foo&bar=baz"];
exports.compare = {
"parse from new qs": function(){
return tests.map(newQS.parse);
@fb55
fb55 / helper.js
Created May 13, 2012 20:52
Dropbox Dropquest Chapter 21
var encode = {
1: function(str){
return str
.split("")
.filter(function(s){
return !{D:1, R:1, O:1, P:1, B:1, X:1}[s];
}).join("");
},
2: function(str){
return str.split("").map(function(s){
@fb55
fb55 / Example.java
Created May 7, 2012 13:13
with statement in Java vs JS (or: the first time I recognize Java being better than JS)
/*
In Java, it is possible to drop the `this` in front of instance variables
*/
class Example{
private int foo;
public Example(int bar){
foo = bar;
}
public int getFoo(){
return foo;
@fb55
fb55 / index.js
Created April 19, 2012 14:39
RSA.js
(function(global){
var MathUtils = {
powermod: function powermod(num, exp, mod){
if(exp === 1) return num % mod;
if(exp & 1 === 1){ //odd
return (num * powermod(num, exp-1, mod)) % mod;
}
return Math.pow(powermod(num, exp/2, mod), 2) % mod;
},
@fb55
fb55 / sort.java
Created November 20, 2011 18:18
Some sort algorithms (java)
import java.util.Random;
class sort{
public static void main(String[] a){
Sorter[] list = {new InsertionSort(), new BubbleSort(), new QuickSort()};
for(int i = 0; i < list.length; i++){
sort.perform(list[i]);
}
}
@fb55
fb55 / index.js
Created October 29, 2011 11:52
(First try of) port of Node.js' util.inspect to JSON.stringify
var inspect = function(obj, showHidden, depth, colors){
var ctx = {
style: /*colors ? stylyze : */function(a){return a;}, //todo
seen: []
};
return formatValue(ctx, obj, 2);
}
var _reName = /(\n\s+)"([A-Za-z_$][\w$]*)"/g;
var _reValue = /\"([^\n]*)\"(?=,?\n)/g;
@fb55
fb55 / RSAencrypt.java
Created August 31, 2011 14:25
A simple class for Java generating RSA public/private-key pairs
class RSAencrypt{
static public double m;
static public double publicK;
static private double privateK;
static private double nums = 6;
static{
double p = ranPrime.genRanPrime(nums);
double q = ranPrime.genRanPrime(nums);
RSAencrypt.m = p * q;
double phi = (p-1) * (q - 1);
@fb55
fb55 / index.js
Created August 28, 2011 10:18
Test of event module for htmlparser
/*
Dependencies:
* Request (npm install request)
* readabilitySAX (npm install readabilitySAX)
* my htmlparser fork (https://github.com/FB55/node-htmlparser)
*/
var request = require("request"),
readability = require("./readabilitySAX");
Parser = require("node-htmlparser/lib/Parser.js"),
@fb55
fb55 / FeedParser.js
Created June 12, 2011 10:20
A simple (not feature complete) feedparser for node.js. Requires sax.js
/*
Simple feedparser
Based upon:
- https://raw.github.com/drudge/node-easyrss
*/
var sax = require('./libs/sax');
module.exports.streamParser = function(){