Skip to content

Instantly share code, notes, and snippets.

View fb55's full-sized avatar

Felix Boehm fb55

View GitHub Profile
@fb55
fb55 / html2article.xml
Created April 25, 2010 18:23
a YQL script to extract articles from webpages
<?xml version="1.0" encoding="UTF-8" ?>
<table xmlns="http://query.yahooapis.com/v1/schema/table.xsd">
<meta>
<author>Felix Boehm</author>
<documentationURL>http://feedic.com/</documentationURL>
<sampleQuery>select * from t where url="feedic.com"</sampleQuery>
</meta>
<bindings>
<select itemPath="" produces="XML">
<urls>
//just wrote this code for a project. how cool is that?
var reqURL = (function loopRegExps (url, regExps) {
for(var i in regExps){
if(url.match(regExps[i][0])){ return (regExps[i][1] + "url=" + encodeURIcomponent(url))}
}
})(url, collectionA);
/*just some thoughts:
I would always use a named function, so it can call itself if needed. It's just a good practice.
@fb55
fb55 / clone.java
Created August 23, 2010 15:35
jsarray-behaviour for java
class clone{
private int id;
public clone next;
public clone previous;
private boolean deleted = false;
public String value;
public int getId(){
return this.id;
@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(){
@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 / 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 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 / 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 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 / 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;