Skip to content

Instantly share code, notes, and snippets.

View niklasfi's full-sized avatar

Niklas Fischer niklasfi

View GitHub Profile
@niklasfi
niklasfi / gist:793773
Created January 24, 2011 19:26
This is supposed to be a simple http downloader:
var http = require('http');
var fs = require('fs');
var options = {
host: 'nodejs.org',
port: 80,
path: '/docs/v0.3.6/api/http.html#http.ClientResponse'
};
var ws=fs.createWriteStream('./file');
var sys = require('sys'),
fs = require('fs');
var b=new Buffer('hello world');
fs.open('test','w',undefined, function(err,fd){
if(err) throw err;
fs.write(fd,b,0,b.length,3,function(err,written){
@niklasfi
niklasfi / nodejs
Created January 27, 2011 09:26
c++
#define _XOPEN_SOURCE 500
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
int main(){
char* ds=new char[10];
for(unsigned int i = 0 ; i<10;i++)
ds[i]=65;
var fs = require('fs');
var http = require('http');
var urlparser = require('url');
var k = process.binding('constants');
function Download(url,path){
this.u= urlparser.parse(url);
this.httpStatus=null;
this.recievedHeader=null;
this.filestats = {filesize: null, bytesWritten: 0, bytesRecieved: 0}
var fs = require('fs');
var http = require('http');
var urlparser = require('url');
var k = process.binding('constants');
function Download(url,path, options,callback){
/*
existing options:
- range: [start, end] specifies the Range of the part to be downloaded. start or end may be null to specify download "from beginning" or "to end" respecively.
- continue: if not set to true file will be truncated before writing to it
var http = require('http');
var fs = require('fs');
var url = require('url');
var settingsPath='settings2.json';
var Server = function(path){
this.readSettings(path);
}
proxy.balance = "fair"
$HTTP["host"] == "localhost" {
proxy.server = ("" => (
("host" => "127.0.0.1", "port" => 8080)
))
}
/* John Resig's array.remove taken from http://ejohn.org/blog/javascript-array-remove/ */
Array.prototype.remove = function(from, to) {
var rest = this.slice((to || from) + 1 || this.length);
this.length = from < 0 ? this.length + from : from;
return this.push.apply(this, rest);
};
var ticket = function(id){this.id=id}
var ticketlist = function(){ this.q = [] , this.all= {}}
@niklasfi
niklasfi / foo.js
Created February 7, 2011 21:35
main.js
var foo = exports;
//now i would like to have a constructor function for the foo "class" (i know in JS that does not exist)
//with normal js this would be
foo = function(arg1,arg2){
this.something = arg1;
this.somethingOther = arg2;
}
@niklasfi
niklasfi / gist:821077
Created February 10, 2011 18:42
locale -a
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_MESSAGES to default locale: No such file or directory
locale: Cannot set LC_COLLATE to default locale: No such file or directory
C
POSIX