Skip to content

Instantly share code, notes, and snippets.

View jfensign's full-sized avatar

Joseph Ensign jfensign

  • Bloomberg L.P.
  • New York
View GitHub Profile
@jfensign
jfensign / d3-force-graph.js
Created June 11, 2014 14:11
D3 force-directed graph Class
function forceGraph(opts) {
opts = opts || {};
opts.node = opts.node || {};
opts.link = opts.link || {};
var
Self = this,
@jfensign
jfensign / tree_path_snippet.js
Created March 5, 2014 01:16
Unique paths in tree.
var tree = {
name: "Tree",
children: [
{
name: "1",
children:[
{
name: "1.1"
},
{
@jfensign
jfensign / cluster
Created February 7, 2014 05:41
Generic Node.js cluster implementation.
var Cluster = require('cluster')
//Console Styling
, Colors = require('colors')
//Total number of CPUs
, CPU_Count = require('os').cpus().length
//Timeouts for handling erroneous child-process spawning
, TimeOuts = []
//Number of worker processes
, WorkerC = 0
//Log errors (an alert/logging mechanism belongs here)
@jfensign
jfensign / simple_thumbnail
Created February 7, 2014 05:15
Simple document thumbailer script. Packages unoconv and gs (GhostScript) are required.
Thumbnailer = ->
Thumbnailer = this
fs = require "fs"
cp = require "child_process"
path = require "path"
@jfensign
jfensign / MY_Model.php
Created April 9, 2012 18:42
Codeigniter Abstract Module
<?php if(! defined("BASEPATH")) exit("No direct script access allowed");
abstract class MY_Model extends CI_Model {
private $file_dest;
private $table;
private $fields;
private $field_values;
public function __construct() {
@jfensign
jfensign / index.js
Created April 9, 2012 00:24
NodeJS User Registration and Authentication
//index.js
var express = require('express'),
app = module.exports = express.createServer(),
mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/nodeAuth');
//configure app
app.configure(function() {
app.set('views', __dirname + '/views');
@jfensign
jfensign / AppException.php
Created April 7, 2012 23:29
Extending PHP's Exception Class
<?php
//AppException.php
class AppException extends Exception {
public function __construct($msg="", $code = 0) {
/*
PHP's Exception class will handle all
of the necessary validation
*/
@jfensign
jfensign / formTest.php
Created April 6, 2012 21:35
Generate forms quickly for testing (Do not use in production)
<?php
$connect = mysql_connect(DB_HOST, DB_USER, DB_PASS)
or die(mysql_error());
mysql_select_db(DB);
//SQL
$sql = "SHOW COLUMNS FROM TABLENAME";
//Query
$query = mysql_query($sql)
or die(mysql_query());
//results
@jfensign
jfensign / App.class.php
Created April 6, 2012 20:58
Front Controller
<?php
//App class
class App {
//Holds Singleton instance
public static $instance;
//environment vars
public static $vars = array();
@jfensign
jfensign / A_dirStructure.txt
Created March 26, 2012 23:44
NodeJS and Google's Geocoder API
//Directory Structure
/app
/scripts
|-handleFormSubmit.js
/node_modules
/views
|-index.jade
/controllers
|-maps_controller.js