Skip to content

Instantly share code, notes, and snippets.

View dustinc's full-sized avatar

Dustin Coffey dustinc

  • Ellijay, GA
  • 23:20 (UTC -04:00)
View GitHub Profile
for i in [i * 0.1 for i in range(0, 10)]:
print i
def is_prime(n):
if n % 2 == 0:
return False
for i in range(3, n/2, 2):
if n % i == 0:
return False
return True
distance = 2000000
primes = [1] * distance
def set_primes():
primes[0] = 0
primes[1] = 0
for i in range(3, distance, 2):
@dustinc
dustinc / node_http.js
Created July 31, 2012 17:49
Node.js Hello World
var http = require('http');
var server = http.createServer(function(req, res) {
res.writeHead(200);
res.end('Hello World');
});
server.listen(8000);
var foo = 'foo'
, bar = 'bar'
, lul = 'lul'
;
var foo = 'foo',
bar = 'bar',
lul = 'lul';
@dustinc
dustinc / gist:3230603
Created August 1, 2012 20:52
People "document" in MongoDB
[
{ "name" : "Dustin", "_id" : { "$oid" : "5019968ccc93742e0d0bba0b" }, "age" : 29 },
{ "name" : "Steve", "_id" : { "$oid" : "5019969acc93742e0d0bba0c" } },
]
var default_vars = {
title: 'Serious Title Stuffs'
};
exports.index = function(req, res){
default_vars.title = default_vars.title + ' Index Page';
res.render('index', default_vars);
};
exports.dustin = function(req, res) {
controller.index = function(req, res, next) {
db.users.find({}, function(err, docs) {
console.log(err + ' ' + docs);
res.render('user/index', {users: docs});
});
};
//controller
controller.index = function(req, res, next) {
var users = db.users.getUsers();
res.render('user/index', {users: users});
};
//model
User.statics.getUsers = function(callback) {
//somehow return here... this approach is not asynchronous
controller.profile.save = function(req, res, next) {
var Profile = db.main.model('Profile'),
profile = req.body.profile;
Profile.findOne({'_id': profile.id}, function(err, _profile) {
if(err) return next(err);
if(null == _profile) {
_profile = new Profile(profile);