Skip to content

Instantly share code, notes, and snippets.

@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());
});
@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 / 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'
import urllib2, urllib, re, sys
def main():
if not len(sys.argv) > 1:
print "You shall give a genre. example: python band.py house"
return
keyword = sys.argv[1]
@alaingilbert
alaingilbert / main.py
Created March 11, 2012 06:14
CallTV answer
v = {'A': list('CDFIKEGJLPQHMRSNU'),
'B': list('CEHNUDGMTFJRILKPO'),
'C': list('ABDFIKOEHNU'),
'D': list('ACBFIKOGMS'),
'E': list('ACBHNUGJLP'),
'F': list('AJROKIDCB'),
'G': list('ADMSPLJEB'),
'H': list('ACENUBMR'),
'I': list('ALQOKFDCB'),
'J': list('AFRPLGEB'),
@alaingilbert
alaingilbert / index.html
Created May 13, 2012 15:28
Sprite state
<!doctype html>
<html>
<head>
<style>
label { display: block; width: 70px; float: left; border-right: 1px solid #187215; padding: 5px; }
.box { color: #187215; clear: both; border: 1px solid #187215; margin: 5px; background-color: #e9ffe8; }
.cross { width: 30px; height="30px"; display: block; background-color: #f6fff6; text-align: center; float: left; padding: 5px; }
.ctrl { margin: 20px; }
.left { float: left; }
.clear { clear: both; }
@alaingilbert
alaingilbert / index.html
Created May 25, 2012 00:42
Object follow a bezier curve
<!doctype html>
<html>
<head>
</head>
<body>
<canvas id="canvas" width="800" height="600"></canvas>
<script type="text/javascript">
var ctx = document.getElementById('canvas').getContext('2d')
<!doctype html>
<html>
<head>
</head>
<body>
<canvas id="canvas" width="800" height="600"></canvas>
<script type="text/javascript">
var ctx = document.getElementById('canvas').getContext('2d')
@alaingilbert
alaingilbert / main.py
Created August 22, 2012 01:01
How many squares question...
# http://www.quora.com/Puzzle-and-Trick-Questions/How-many-squares-are-in-this-picture
def get_square_count(length):
squares = 0
nb_nodes = length ** 2
for i in range(nb_nodes):
tmp = i + 1
while tmp % 5 != 0 and tmp + ((tmp - i) * length) < nb_nodes:
tmp += 1
squares += 1
@alaingilbert
alaingilbert / main.py
Created November 14, 2012 04:36
Get a pdf on seao.ca
#! /usr/bin/python
# INSTALLATION:
# pip install requests
# pip install beautifulsoup4
from bs4 import BeautifulSoup
import os
import requests