Skip to content

Instantly share code, notes, and snippets.

@luccastera
luccastera / roster.js
Created June 27, 2014 16:33
World Cup Rosters
var request = require('request'),
cheerio = require('cheerio');
if (process.argv.length !== 3) {
console.log('Usage: node roster.js <country>');
process.exit(1);
}
var country = process.argv[2];
@luccastera
luccastera / GlobalLeak.html
Created June 25, 2012 21:53
jquery autosize global leak
<html>
<head>
<meta charset="utf-8">
<title>Global Leak - Mocha Test</title>
<link rel="stylesheet" href="https://raw.github.com/visionmedia/mocha/master/mocha.css" />
<script src="https://raw.github.com/visionmedia/mocha/master/mocha.js"></script>
<script>
mocha.setup({ui: 'bdd', globals: ['XMLHttpRequest']})
</script>
@luccastera
luccastera / mongoose_validation_test.js
Created November 14, 2011 21:26
Mongoose validation does not work when using ref
var mongoose = require('mongoose'),
Schema = mongoose.Schema
mongoose.connect('mongodb://localhost/my_database')
// Define User Schema
var UserSchema = new Schema({
name: {type: String}
})
var User = mongoose.model('User', UserSchema)
@luccastera
luccastera / object_create.js
Created October 6, 2011 15:45
Javascript Object.create
if (typeof Object.create !== 'function') {
Object.create = function(o) {
var F = function() {};
F.prototype = o;
return new F();
}
};
@luccastera
luccastera / example.js
Created May 3, 2011 14:36
"Can't set headers after they are sent." example
app.post('/recover_password', function(req, res) {
User.get(req.body.username, function(err,data) {
if (err) {
req.session.error = 'We could not find this user.';
res.redirect('back'); // ERROR THROWN HERE
} else {
var user = new User(data);
user.resetPassword(function(err,data) {
var newUser = new User(data);
newUser.sendPasswordRecoveryEmail();
@luccastera
luccastera / test_riak.js
Created April 28, 2011 19:43
Testing riak-js getAll()
var db = require('riak-js').getClient({port: 8098, debug: false});
db.save('memberships', '1', {user_id: 'luc', group_id: "barca_fans"});
db.getAll('memberships', {where: { user_id: 'luc' }}, function(err,data) { console.log(data) });
db.getAll('memberships', {where: { user_id: 'mourinho' }}, function(err,data) { console.log(data) });
@luccastera
luccastera / make-cert.sh
Created July 28, 2009 19:46
Used to create a self-signed certificate
#!/bin/sh
NAME=$1
if [ "$NAME" == '' ]
then
echo "$0 <certificate name>" 1>&2
exit 1
fi
openssl genrsa 1024 | openssl pkcs8 -topk8 -nocrypt -out $NAME.key