Skip to content

Instantly share code, notes, and snippets.

@youurayy
youurayy / filesender.js
Created November 9, 2011 09:02
Node.js (v0.4) sendfile() non-caching fileserver - fast and efficient!
var http = require('http');
var fs = require('fs');
var path = require('path');
var constants = require('constants');
var timers = require('timers');
var port = 8080;
http.createServer(function(req, res) {
if(req.url == '/') {
res.writeHead(200, { 'Content-Type': 'text/plain' });
// Here is a proposal for minimalist JavaScript classes, humbly offered.
// There are (at least) two different directions in which classes can be steered.
// If we go for a wholly new semantics and implementation, then fancier classical
// inheritance can be supported with parallel prototype chains for true inheritance
// of properties at both the class and instance level.
// If however, we keep current JavaScript prototype semantics, and add a form that
// can desugar to ES3, things must necessarily stay simpler. This is the direction
// I'm assuming here.
@tj
tj / routes.js
Created October 15, 2011 00:23
Express routes
var app = require('../app');
console.log();
app.routes.all().forEach(function(route){
console.log(' \033[90m%s \033[36m%s\033[0m', route.method.toUpperCase(), route.path);
});
console.log();
process.exit();
@nhoizey
nhoizey / index.html
Created September 13, 2011 12:47
Un affichage de numéro vert avec Microformat et mise en forme en CSS
<!-- Live demo : http://bl.ocks.org/1213727 -->
<html>
<head>
<title>Un affichage de numéro vert avec Microformat et mise en forme en CSS</title>
<link rel="stylesheet" media="all" href="numero_vert.css" type="text/css" />
</head>
<body>
<span class="vcard numerovert">
<span class="fn">Nom de la société</span>
@havvg
havvg / bdd-experiment-guide.md
Created September 9, 2011 14:44
Behavior Driven Development in Symfony2 with Behat, Mink and Zombie.js
@ratibus
ratibus / sfSearchTask.class.php
Created September 8, 2011 14:24
symfony search task
<?php
class sfSearchTask extends sfCommandApplicationTask
{
/**
* @see sfTask
*/
protected function configure()
{
$this->addArguments(array(
@naholyr
naholyr / update-sublime-text.sh
Created September 6, 2011 15:27
Install or update Sublime Text from web site
#!/bin/bash
# Requirements: sed, grep, curl, pkill
# User configuration
LOCAL_INSTALL="/usr/lib/sublime-text-2" # Must be user-writable
REPO="dev" # "dev" for dev releases, or "2" for beta releases
TARGET_BUILD="Linux 32 bit" # can be one of "Windows", "Windows 64 bit", "OS X", "Linux 32 bit", "Linux 64 bit"
# Check if sublime text is running
@naholyr
naholyr / app.js
Created August 27, 2011 10:13
REST avec NodeJS & Express - Application
var express = require('express')
, app = module.exports = express.createServer()
app.configure(function () {
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(app.router);
app.use(express.static(__dirname + '/public'));
});
app.configure('development', function () {
@naholyr
naholyr / 01-db-test.js
Created August 27, 2011 09:39
REST avec NodeJS & Express - Tests Unitaires
var assert = require('assert')
, db = require('../db')({namespace:'bookmarks-test-db'})
, the_bookmark = {}
require('vows')
.describe('bookmarks-db')
.addBatch({
"Initialize": {
topic: function () {
db.deleteAll(this.callback);
@tj
tj / equivalent.js
Created August 24, 2011 00:21
example of backbone-style routing with Express
app.get('/help', function(req, res){
res.send('some help');
});
app.get('/search/:query/p:page', function(req, res){
var query = req.params.query
, page = req.params.page;
res.send('search "' + query + '", page ' + (page || 1));
});