Skip to content

Instantly share code, notes, and snippets.

> db.users.findOne
function (query, fields) {
var cursor = this._mongo.find(this._fullName, this._massageObject(query) || {}, fields, -1, 0, 0, 0);
if (!cursor.hasNext()) {
return null;
}
var ret = cursor.next();
if (cursor.hasNext()) {
throw "findOne has more than 1 result!";
}
// Date library
var log4js = require('log4js'),
log = log4js.getLogger('Date'),
fmts = {
// Returns the full day of the week (e.g. Sunday)
'A' : function (d) {
var day = d.getUTCDay();
Number is: <?php
function fibonacci($n) {
if ($n < 2) {
return 1;
} else {
return fibonacci($n - 2) + fibonacci($n - 1);
}
}
echo fibonacci(40);
?>
var http = require('http');
function fibonacci(n) {
if (n < 2)
return 1;
else
return fibonacci(n-2) + fibonacci(n-1);
}
http.createServer(function (req, res) {
@joshkehn
joshkehn / gist:1258324
Created October 3, 2011 02:43
fibserver.js ab results
Joshs-MacBook-Pro:~ josh$ ab -n 10 -c 5 http://127.0.0.1:1337/
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 127.0.0.1 (be patient).....done
Server Software:
Server Hostname: 127.0.0.1
import SocketServer
import SimpleHTTPServer
PORT = 1339
def fibonacci (n):
if n < 2:
return 1
else:
return fibonacci(n - 2) + fibonacci(n - 1)
public class Student
{
String name;
int age;
public Student (String name, int age)
{
this.name = name;
this.age = age;
}
function Student (name, age) {
this.name = name;
this.age = age;
}
Student.prototype.toString = function toString () {
return this.name + " is " + this.age + " years old.";
};
var me = new Student("Joshua", 26);
var Laws = {
drinking_age : function (age, fn) {
fn(age > 21);
}
}
Student.prototype.check_drinking = function check_drinking (fn) {
Laws.drinking_age(this.age, function (able_to_drink) {
if (able_to_drink) {
fn(null, true);
var Laws = {
drinking_age : function (fn) {
fn(this.age > 21);
}
}
/* snip */
Laws.drinking_age.call(this, function (able_to_drink) {