Skip to content

Instantly share code, notes, and snippets.

View xjamundx's full-sized avatar

Jamund Ferguson xjamundx

View GitHub Profile
@xjamundx
xjamundx / cookies.js
Created February 3, 2011 22:10
expressjs cookie fail
//express server creation
var app = express.createServer()
var MemoryStore = require('connect/middleware/session/memory')
// configuration
app.configure(function() {
app.use(express.cookieDecoder());
app.use(express.session({
secret:"HAHAHHAHAHAHAHAHAH"
}))
@xjamundx
xjamundx / mustacheMathAddOn.js
Created February 19, 2011 22:39
This was a commonJS module we played around with for node.
////
// Math Support
//
// This is an an awesome addition to mustache.js to
// add support for basic math operations. No evals!
//
// Examples:
//
// 2 == {{#math}} {{four}} / {{two}} {{/math}}
// 20 == {{#math}} 100 / 5 {{/math}}
@xjamundx
xjamundx / canvas-upload.php
Created February 26, 2011 16:13
php canvas base64 png decoder
<?php
// requires php5
define('UPLOAD_DIR', 'images/');
$img = $_POST['img'];
$img = str_replace('data:image/png;base64,', '', $img);
$img = str_replace(' ', '+', $img);
$data = base64_decode($img);
$file = UPLOAD_DIR . uniqid() . '.png';
$success = file_put_contents($file, $data);
@xjamundx
xjamundx / sencha-touch-signature.js
Created February 26, 2011 16:18
Signature Drawing Canvas Panel in Sencha Touch
(function() {
var clicked, canvas, ctx, coords, offsetX, offsetY, oldX, oldY;
app.views.Signature = Ext.extend(Ext.Panel, {
layout: {
type: 'vbox',
pack: "center",
align: "center"
},
@xjamundx
xjamundx / gist:911831
Created April 9, 2011 22:14
simple mongo collection with mongohq
~ $ mongo -u USERNAME -p PASSWORD Flame.mongohq.com:27094/wereviewutah
MongoDB shell version: 1.6.5
connecting to: Flame.mongohq.com:27094/wereviewutah
> db.logs.find()
{ "_id" : ObjectId("4da0d8a5a130714ae1000023"), "count" : 1 }
> db.logs.findOne()
{ "_id" : ObjectId("4da0d8a5a130714ae1000023"), "count" : 1 }
> db.logs.update({}, {$inc:{count:1}})
> db.logs.findOne()
{ "_id" : ObjectId("4da0d8a5a130714ae1000023"), "count" : 2 }
@xjamundx
xjamundx / express-locals.js
Created April 11, 2011 13:22
Express JS Locals
// using the res.local syntax
app.all('*', function(req, res, next) {
db.logs.findOne(function(err, logs) {
if (err) return console.log("Error: ", err);
res.local('count', logs.count);
res.local('edit', false);
next();
});
});
@xjamundx
xjamundx / db.js
Created April 11, 2011 13:27
Simple MongoDB Wrapper
////////////////////////////////////////
// Simple MongoDB Wrapper //
// Written to use with MongoHQ.com //
// By Jamund Ferguson //
// April 9, 2011
////////////////////////////////////////
var mongodb = require('mongodb'),
db;
@xjamundx
xjamundx / mongohq-sample.js
Created April 11, 2011 13:38
using my simple mongohq wrapper
// initialize it with your db name and credentials
var db = require("./db").init({
user: "username",
pass: "password",
name: "database",
host: "yourmongohqhost.mongohq.com",
port: 27094
});
// define your collections
@xjamundx
xjamundx / standards.js
Created April 14, 2011 17:30
Here are some coding standards
////////////
// jQuery //
////////////
// 1. Name jQuery objects so that we know what they are
var $container = $("div");
///////////////
// Normal JS //
///////////////
@xjamundx
xjamundx / express-pagination.js
Created April 19, 2011 05:28
sample pagination using express route-specific middleware
// articles per page
var limit = 10;
// pagination middleware function sets some
// local view variables that any view can use
function pagination(req, res, next) {
var page = parseInt(req.params.page) || 1,
num = page * limit;
db.articles.count(function(err, total) {
res.local("total", total);