Skip to content

Instantly share code, notes, and snippets.

View pdeschen's full-sized avatar

Pascal Deschênes pdeschen

  • Montréal, Canada
View GitHub Profile
@pdeschen
pdeschen / webapi.curl
Created November 19, 2011 04:42
Montreal Open Data API
# get all ice rings from Cote-Des-Neiges
-X GET /cdn/patinoires/
# get all ice rings
-X GET /patinoires
# get all open ice rings
-X GET /patinoires/?open=true
# get geolocation of the ice rings in Code-Des-Neiges
-X GET /cdn/patinoires/locations
@pdeschen
pdeschen / patinoires.js
Created November 19, 2011 04:03
Montreal Open Data Patinoires
var ndg = new montreal.data.arrondissement("Côte-des-Neiges - Notre-Dame-de-Grâce")
var patinoires = new montreal.data.patinoires();
patinoires.filter(ndg, function(patinoire) {
console.log(patinoire.location);
if (patinoire.open)
console.log(patinoire.condition);
});
We can make this file beautiful and searchable if this error is corrected: It looks like row 4 should actually have 1 column, instead of 3. in line 3.
Source : Ville de Montréal
URL : http://donnees.ville.montreal.qc.ca/archives/fiche-donnees/elections-2009-section-vote-par-adresse
AdrComplete1;AdrComplete2;NoArrondissement;Arrondissement;NoDistrict;District;Section;BVA;BVA-Description;BVA-Adresse1;BVA-Adresse2;BVA-Adresse3;BVO;BVO-Description;BVO-Adresse1;BVO-Adresse2;BVO-Adresse3;NoCiv;NoCivAlpha;NoApp;NoAppAlpha;Specifique;Direction;Generique;Particule;CodePostal;Lot;Matricule;VilleProv;NbElecteurs
7180 avenue des Acacias;Anjou Qc H1J 2B4;2;d'Anjou;21;Ouest (Anjou);13;A-021-01;?COLE JACQUES-ROUSSEAU;7455, rue Jarry est;Anjou (Qc) H1J 1G8;Gymnase;S-021-02;?COLE JACQUES-ROUSSEAU;7455, rue Jarry Est;Anjou (Qc) H1J 1G8;Gymnase;7180;;;;Acacias;;avenue;des;H1J2B4;; ;Anjou;2;
7181 avenue des Acacias;Anjou Qc H1J 2B4;2;d'Anjou;21;Ouest (Anjou);13;A-021-01;?COLE JACQUES-ROUSSEAU;7455, rue Jarry est;Anjou (Qc) H1J 1G8;Gymnase;S-021-02;?COLE JACQUES-ROUSSEAU;7455, rue Jarry Est;Anjou (Qc) H1J 1G8;Gymnase;7181;;;;Acacias;;avenue;des;H1J2B4;; ;Anjou;2;
7190 av
@pdeschen
pdeschen / gist:983717
Created May 20, 2011 20:19
nginx 403 handling
upstream test {
server localhost:8080;
}
server {
...
error_page 401 =403 /login;
location ~ ^/model/(.*)$ {
auth_basic "Restricted";
auth_basic_user_file conf/htpasswd;
@pdeschen
pdeschen / gist:983569
Created May 20, 2011 19:15
Ajax jQuery Authentication Request
$.ajax( {
url : '/model/user.json',
dataType : 'json',
beforeSend : function(xhr) {
var bytes = Crypto.charenc.Binary.stringToBytes(username + ":" + password);
var base64 = Crypto.util.bytesToBase64(bytes);
xhr.setRequestHeader("Authorization", "Basic " + base64);
},
error : function(xhr, ajaxOptions, thrownError) {
reset();
@pdeschen
pdeschen / constroller.js
Created May 15, 2011 21:55
mustache.js rendering
render : function(view, model, callback) {
cst.model = model;
cst.view = view;
try {
var html = Mustache.to_html(view, model);
callback.call(this, html);
} catch (error) {
onError('Error while rendering template.');
}
}
@pdeschen
pdeschen / gist:973578
Created May 15, 2011 21:49
mustache template
<h1>{{header}}</h1>
{{#items}}
{{#first}}
<li>
<strong>{{name}}</strong>
</li>
{{/first}}
{{#link}}
<li>
@pdeschen
pdeschen / model.json
Created May 15, 2011 21:42
json model
{
"header": "Colors",
"items": [
{"name": "red", "first": true, "url": "#Red"},
{"name": "green", "link": true, "url": "#Green"},
{"name": "blue", "link": true, "url": "#Blue"}
],
"empty": false
}
@pdeschen
pdeschen / foobar.js
Created April 9, 2011 01:02
sharing between modules?
/* foo.js */
var date = new Date();
exports.Date = date;
/* bar.js */
var foo = require('./foo.js');
exports.Date = foo.Date;
/* foobar.js */
@pdeschen
pdeschen / static-server.js
Created April 6, 2011 19:58
A node.js static file server using mime.
var libpath = require('path'),
http = require("http"),
fs = require('fs'),
url = require("url"),
mime = require('mime');
var path = ".";
var port = 8088;
http.createServer(function (request, response) {