Skip to content

Instantly share code, notes, and snippets.

@drewlesueur
drewlesueur / CRUD-nodejs-mongodb.coffee
Created October 2, 2010 09:29
Mongo db crud example
#Examples of crud operations on node.js using node-mongodb-native (in coffeescript)
mongo = require("mongodb")
host = 'localhost'
port = mongo.Connection.DEFAULT_PORT
this.ObjectID = mongo.ObjectID
this.db = new mongo.Db 'mydb', new mongo.Server(host, port, {}), {}
@drewlesueur
drewlesueur / sequence.html
Created October 6, 2010 04:38
sequence diagram
<!doctype html>
<html>
<head>
<script>
/*!
* jQuery JavaScript Library v1.4.2
* http://jquery.com/
*
* Copyright 2010, John Resig
* Dual licensed under the MIT or GPL Version 2 licenses.
@drewlesueur
drewlesueur / avoid_nested_callbacks.coffee
Created November 5, 2010 19:47
Javascript pattern for avoiding nested callbacks
# Drew LeSueur @drewlesueur
# An abstraction for calling multiple asynchronous
# functions at once, and calling a callback
# with the "return values" of all functions
# when they are all done.
# requires underscore.js
_.mixin # underscore.js mixin
do_these: (to_dos, callback) ->
return_values = if _.isArray(to_dos) then [] else {}
@drewlesueur
drewlesueur / .vimrc
Created November 8, 2010 08:15
My vimrc
call pathogen#runtime_append_all_bundles()
filetype plugin indent on
set backspace=indent,eol,start
set tabstop=2
set shiftwidth=2
set expandtab
"colorscheme jellybeans
ino jj <esc>
cno jj <c-c>
vno v <esc>
@drewlesueur
drewlesueur / sites-enabled-file
Created November 8, 2010 19:44
infinite subdomains
#allows you to have infinite subdomains
<VirtualHost *:80>
# first do a2enmod vhost_alias
ServerName anything.the.tl
ServerAlias *.the.tl
UseCanonicalName Off
VirtualDocumentRoot /root/workspace/sites/%0 # %0 is the full domain name
</VirtualHost>
@drewlesueur
drewlesueur / sites-enabled-file2
Created November 8, 2010 19:46
Hook up node.js with apache.
#hook up node.js with apache so you can have an apache site on port 80
# and a node.js server running on port 80
# you may need to `a2enmod proxy` and `a2enmod proxy_http`
<VirtualHost *:80>
ServerName severus.the.tl
ProxyPass / http://127.0.0.1:86/
# CustomLog /var/log/apache2/lazeroids-node-access.log combined
# ErrorLog /var/log/apache2/lazeroids-node-error.log
# NoCache *
<Proxy *>
@drewlesueur
drewlesueur / closure.coffee
Created November 9, 2010 00:46
Example of a closure in CoffeeScript
person = () ->
name = "Fred"
ret =
getName: () ->
return name
setName: (newName) ->
name = newName
bob = person()
alert bob.getName()
@drewlesueur
drewlesueur / csv_to_array.php
Created November 17, 2010 03:42
Simple Csv parser for PHP <= 5.2
public static function csv_to_array($csv) {
if (substr($csv,-1) != "\n" && substr($csv,-1) != "\r") {
$csv .= "\n";
}
$len = strlen($csv);
$table = array();
$cur_row = array();
$cur_val = "";
$state = "first item";
@drewlesueur
drewlesueur / image_functions.php
Created November 17, 2010 03:42
Simple image manipulation functions for php
public static function resize_image($image, $w, $h) {
$ret = imagecreatetruecolor($w, $h);
imagealphablending( $ret, false );
imagesavealpha( $ret, true );
imagecopyresampled($ret, $image, 0, 0, 0, 0, $w, $h, imagesx($image), imagesy($image));
//imageantialias($ret,true);
return $ret;
}
public static function overlay_image($image, $overlay, $x, $y) {
<img src="pics/IMG_1255.jpg" width="300"><br>
<img src="pics/IMG_1256.jpg" width="300"><br>
<img src="pics/IMG_1257.jpg" width="300"><br>
<img src="pics/IMG_1258.jpg" width="300"><br>
<img src="pics/IMG_1259.jpg" width="300"><br>