Skip to content

Instantly share code, notes, and snippets.

@alaingilbert
alaingilbert / server.js
Created December 12, 2011 12:14
EventSource server with nodejs
var http = require('http')
, fs = require('fs')
, PORT = process.argv[2] || 8080
, HOST = process.argv[3] || '127.0.0.1';
http.createServer(function (req, res) {
if (req.url == '/events') {
res.writeHead(200, { 'Content-Type' : 'text/event-stream'
, 'Cache-Control' : 'no-cache'
@alaingilbert
alaingilbert / main.js
Created September 26, 2011 21:45
Remove a large playlist on turntable.fm
// Remove the current playlist
var files = turntable.playlist.files;
var arr = [];
for (var i=0, len=files.length; i<len; i++) {
arr.push(files[i].fileId);
}
function remRec(arr) {
var fileId = arr.splice(0, 1)[0];
turntable.playlist.removeFile(fileId);
if (arr.length > 0) {
@alaingilbert
alaingilbert / main.js
Created September 14, 2011 20:24
Nodejs Crawler
// Intallation:
// npm install jsdom jquery
var jsdom = require('jsdom');
jsdom.env('http://google.ca/', null, function (err, window) {
$ = require('jquery').create(window);
$('a').each(function () {
console.log($(this).attr('href'), ' ---> ', $(this).text());
});