Skip to content

Instantly share code, notes, and snippets.

View Aaronontheweb's full-sized avatar
🚀
Shipping!

Aaron Stannard Aaronontheweb

🚀
Shipping!
View GitHub Profile
@Aaronontheweb
Aaronontheweb / helloworld-node.js
Created January 28, 2012 02:07
Node.JS: Hello World w/ IP Address
/* Basic HelloWorld Node.JS example */
var http = require('http');
//Node function called each time our event loop receives a new HTTP request
function onRequest(req, res){
res.writeHead(200, {'Content-Type':'text/plain'});
res.end('Hello ' + req.connection.remoteAddress + '!');
/* Write the IP addresses of our connecting client to console */
console.log('Incoming connection from ' + req.connection.remoteAddress);
@Aaronontheweb
Aaronontheweb / pickup-truck-aircraft-carrier-catapult
Created February 1, 2012 07:51
How far can an aircraft carrier catapult fling a four-ton pickup truck?
How far can a pickup truck be flung off of an aircraft carrier?
333m - length of aircraft carrier deck (Nimitz Class - http://en.wikipedia.org/wiki/Aircraft_carrier)
20,411.6567 - weight of jet in kilos
2 = number of seconds a jet is active on the catapult (assume it clears all 333ms)
165mph takeoff speed = 265.54176 Km/h = 73.7616 m/s
Force = weight * (333/4) - Newton's second law of motion (F = MA | F = kg (m/s^2))
1,699,270.420 Netwons
@Aaronontheweb
Aaronontheweb / routes-post.js
Created February 25, 2012 21:12
How to structure an Express Controller Module
/*
* Module dependencies
*/
var Post = require('../models/post')
, PostValidator = require('../validators/post-validator')
, requiresLogin = require('../helpers/requireLogin').requiresLogin
, marked = require('marked');
@Aaronontheweb
Aaronontheweb / ScreenshotControllerAsync.cs
Created February 26, 2012 20:19
HttpPostFileBase in MVC3
[Authorize]
[HttpPost]
public void ScreenshotsAsync(string appName, HttpPostedFileBase files)
{
AsyncManager.OutstandingOperations.Increment();
var fileModel = new UploadedFileModel();
var result = UploadedFileResult.NoFile;
@Aaronontheweb
Aaronontheweb / auth.js
Created April 11, 2012 03:53
everyauth password module
*
* Module dependencies
*/
var User = require('../models/user')
, UserValidator = require('../validators/user-validator')
, Promise = require('everyauth').Promise;
//Everyauth configuration
module.exports = function(everyauth, repository){
@Aaronontheweb
Aaronontheweb / NinjectWebCommon.cs
Created May 17, 2012 19:46
Ninject for MVC4 WebApi
/* This is part of the file that is generated automatically when you install Ninject.MVC3 -pre via Nuget */
/// <summary>
/// Creates the kernel that will manage your application.
/// </summary>
/// <returns>The created kernel.</returns>
private static IKernel CreateKernel()
{
var kernel = new StandardKernel();
kernel.Bind<Func<IKernel>>().ToMethod(ctx => () => new Bootstrapper().Kernel);
@Aaronontheweb
Aaronontheweb / App.xaml.cs
Created August 21, 2012 07:59
Windows Phone 7 Last-Chance Exception Handling with LittleWatson
// Code to execute on Unhandled Exceptions
private void Application_UnhandledException(object sender,
ApplicationUnhandledExceptionEventArgs e)
{
if (System.Diagnostics.Debugger.IsAttached)
{
// An unhandled exception has occurred;
// break into the debugger
System.Diagnostics.Debugger.Break();
}
@Aaronontheweb
Aaronontheweb / default.js
Created August 21, 2012 08:03
Last-chance exception handling code in WinJS (with MarkedUp)
(function () {
"use strict";
var app = WinJS.Application;
var activation = Windows.ApplicationModel.Activation;
var nav = WinJS.Navigation;
WinJS.strictProcessing();
app.onerror = function (error) {
//Log the last-chance exception (as a crash)
@Aaronontheweb
Aaronontheweb / ShardExample.cs
Created September 11, 2012 19:22
ShardStrategy.ShardingOn Example - taken from RavenDB.NET docs
//from http://ravendb.net/docs/server/scaling-out/sharding
var shards = new Dictionary<string, IDocumentStore>
{
{"Asia", new DocumentStore {Url = "http://localhost:8080"}},
{"Middle East", new DocumentStore {Url = "http://localhost:8081"}},
{"America", new DocumentStore {Url = "http://localhost:8082"}},
};
var shardStrategy = new ShardStrategy(shards)
.ShardingOn<Company>(company => company.Region)
@Aaronontheweb
Aaronontheweb / BadDefaultShard.cs
Created September 11, 2012 19:31
Sharding Models
var shards = new Dictionary<string, IDocumentStore>
{
{"Shard0", new DocumentStore {Url = "http://localhost:8080"}},
{"Shard1", new DocumentStore {Url = "http://localhost:8081"}},
{"Shard2", new DocumentStore {Url = "http://localhost:8082"}},
};
var shardStrategy = new ShardStrategy(shards)
.ShardingOn<FoodOrder>(order => order.CustomerId);