Skip to content

Instantly share code, notes, and snippets.

View mikevalstar's full-sized avatar

Mike Valstar mikevalstar

View GitHub Profile
@mikevalstar
mikevalstar / hashbangv1.js
Created November 15, 2011 18:46
Simple hashbang URL handler
function loadPage(hash, fn){
if(!hash || hash == '')
return; // nothing to do
var url = (hash[0] == '#') ? hash.substring(2): hash;
$('#C').html('Loading Content...'); // replace with loading screen code
var callback = function(responseText, textStatus, XMLHttpRequest){
$(document).attr('title', $(responseText).filter('title').text());
function loadPage(hash, fn){
if(!hash || hash == ''){
if(typeof _gaq !== 'undefined')
_gaq.push(['_trackPageview']);
return; // nothing to do
}
var url = (hash[0] == '#') ? hash.substring(2): hash;
$('#C').html('Loading Content...'); // replace with loading screen code
@mikevalstar
mikevalstar / app.js
Created January 18, 2012 15:33
Tutorial app.js addition of 404 page
// 404 Page
app.use(function(req, res, next){
res.render('404.jade', {title: "404 - Page Not Found", showFullNav: false, status: 404, url: req.url });
});
@mikevalstar
mikevalstar / ErrorHandler.js
Created January 18, 2012 15:47
Error Handler Class for Node js tutorial with Express
/**
* Modified from the Connect project: https://github.com/senchalabs/connect/blob/master/lib/middleware/errorHandler.js
*
* Flexible error handler, providing (_optional_) stack traces and logging
* and error message responses for requests accepting text, html, or json.
*
* Options:
*
* - `showStack` respond with both the error message and stack trace. Defaults to `false`
* - `showMessage`, respond with the exception message only. Defaults to `false`
@mikevalstar
mikevalstar / app.js
Created January 18, 2012 15:56
App.js changed for tutorial project
var error = require('./lib/ErrorHandler');
app.configure('development', function(){
//app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
app.use(error({ showMessage: true, dumpExceptions: true, showStack: true, logErrors: __dirname + '/log/error_log' }));
});
app.configure('production', function(){
//app.use(express.errorHandler());
app.use(error());
@mikevalstar
mikevalstar / AdminPages.js
Created January 27, 2012 15:33
Files for Node.js Tutorial Part 3
// Includes
var crypto = require('crypto');
function hashString(value) {
hash = crypto.createHash('sha1');
hash.update(value);
return hash.digest('hex');
}
var AdminPages = module.exports = function AdminPages(){};
@mikevalstar
mikevalstar / app.js
Created January 28, 2012 22:40
Part 3.1 of the node tutorial
/**
* Module dependencies.
*/
var express = require('express')
, mongoStore = require('session-mongoose');
var app = module.exports = express.createServer();
// Configuration
app.configure(function(){
<?php
class gPDO{
public static function init(){
$GLOBALS['gPDO'] = array();
$GLOBALS['gPDO']['server'] = '';
$GLOBALS['gPDO']['user'] = '';
$GLOBALS['gPDO']['password'] = '';
$GLOBALS['gPDO']['db'] = '';
$GLOBALS['gPDO']['charset'] = 'UTF-8';
function project_add_user($var, $run = true){
$expected = array('project_id' => '', 'id' => '');
if(!cBasecamp::_checkVarTemplate($expected, $var, "project_del_user"))
return false;
if(!$run){
cBasecamp::_schedule("project_add_user", "Add user to group", $var);
return true;
}elseif($run === true){
// store then run with new taskid
@mikevalstar
mikevalstar / Database.js
Created April 16, 2012 19:25
Coding with Node Part 4 - section 1
var mongoose = require('mongoose');
var Schema = mongoose.Schema
, ObjectId = Schema.ObjectId;
var Database = module.exports = function Database(){};
Database.prototype = {
_collections: {
adminUser: {