Skip to content

Instantly share code, notes, and snippets.

View travisperson's full-sized avatar
🏠
Working from home

Travis Person travisperson

🏠
Working from home
View GitHub Profile
@travisperson
travisperson / express-mysql.js
Created June 24, 2011 04:31
Simple express no blocking test
var app = require('express').createServer();
var Client = require('mysql').Client,
db = new Client();
db.user = 'root';
db.password = '';
db.connect();
@travisperson
travisperson / dont-block-me.js
Created June 24, 2011 08:12
Node js Blocking
var http = require('http');
var exec = require('child_process').exec;
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
console.log("New request");
// Don't block me bro!
exec("perl -e 'sleep(60)'", function (error, stdout, stderr) {
res.write(stdout);
@travisperson
travisperson / resthook.js
Created September 15, 2011 19:59
"Resthook"
var Hook = require('hook.io').Hook,
http = require('http'),
util = require('util'),
uuid = require('node-uuid'),
url = require('url'),
qstring = require('querystring');
var Resthook = exports.Resthook = function(options){
var self = this;
@travisperson
travisperson / protype.js
Created September 22, 2011 19:03
Overwriting a function prototype
var util = require("util");
//// Model ////
var Model = function(data) {
this._data = data
}
Model.prototype.show = function (data, cb) {
// act on data and then return exicute the callback
// FizzBuzz
// Saw this problem on hacker news and decided to write it out
// Originally wrote it with console.log and ran into a few problems
// so I came back and added the `write` method to console.
var util = require('util')
argv = process.argv
// No line break to stdout
console.write = function () {
process.stdout.write(util.format.apply(this, arguments))
@travisperson
travisperson / BankMenu.cpp
Created March 2, 2012 18:49
Interesting Visual Studio Effect
// Given the following definitions:
void
BankMenu::execute(Command cmd)
{
// Runs a command
//...
}
@travisperson
travisperson / gist:2279134
Created April 1, 2012 22:22
Printing a Squares Coordinates

Printing a Squares Coordinates

Write a single function that takes an integer 'n' as a parameter representing the length of a single side of a square.

Print all the integer coordinate points that make up the square starting at (0,0) and going clockwise around (spiraling to the center). You must not print the same coordinate twice.

Note: The x coordinates increase as you move to the right, and the Y coordinates increase as you go down.

sf::IntRect thisFutureRect = sf::IntRect(obj.X() + (int)obj.getVelocity().x * dTime, obj.Y() + (int)obj.getVelocity().y * dTime, obj.getBoundingBox().width, obj.getBoundingBox().height);
sf::IntRect objFutureRect = sf::IntRect(collideWith.X() + (int)collideWith.getVelocity().x * dTime, collideWith.Y() + (int)collideWith.getVelocity().y * dTime, collideWith.getBoundingBox().width, collideWith.getBoundingBox().height);
sf::IntRect intersect;
thisFutureRect.intersects(objFutureRect, intersect);
// hitting the side of something
/*if (((obj_y + (ObjBox.height / 2)) >= ((collideWith_y + (CollideBox.height / 2)) - (CollideBox.height)))
&& ((obj_y + (ObjBox.height / 2)) <= ((collideWith_y + (CollideBox.height / 2)) + (CollideBox.height))))
{*/
@travisperson
travisperson / List.js
Created May 10, 2012 04:45
Start of a implementation of a doubly linked list in javascript
List = function (debug) {
var self = this
if ( debug == true)
self._debug = debug
self._size = 0;
self._head = null;
self._tail = null;
self._node_id = 0;
@travisperson
travisperson / gist:3441085
Created August 23, 2012 20:13 — forked from caseman/gist:3428752
Ctor: Lightweight Javascript Constructors with Inheritance

Ctor: Lightweight Javascript Constructors with Inheritance

Author: Casey Duncan @iamnotcasey

This Javascript constructor with inheritance pattern is designed as a lightweight alternative to other methods I've seen while still providing a nice abstraction as a 13 line function that can be easily inlined into your code.