Skip to content

Instantly share code, notes, and snippets.

Avatar

Aaron Stannard Aaronontheweb

View GitHub Profile
@Aaronontheweb
Aaronontheweb / helloworld-node.js
Created Jan 28, 2012
Node.JS: Hello World w/ IP Address
View helloworld-node.js
/* 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 Feb 1, 2012
How far can an aircraft carrier catapult fling a four-ton pickup truck?
View pickup-truck-aircraft-carrier-catapult
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 Feb 25, 2012
How to structure an Express Controller Module
View routes-post.js
/*
* Module dependencies
*/
var Post = require('../models/post')
, PostValidator = require('../validators/post-validator')
, requiresLogin = require('../helpers/requireLogin').requiresLogin
, marked = require('marked');
View ScreenshotControllerAsync.cs
[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 Apr 11, 2012
everyauth password module
View auth.js
*
* 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
Ninject for MVC4 WebApi
View NinjectWebCommon.cs
/* 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 Aug 21, 2012
Windows Phone 7 Last-Chance Exception Handling with LittleWatson
View App.xaml.cs
// 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 Aug 21, 2012
Last-chance exception handling code in WinJS (with MarkedUp)
View default.js
(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 Sep 11, 2012
ShardStrategy.ShardingOn Example - taken from RavenDB.NET docs
View ShardExample.cs
//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)
View BadDefaultShard.cs
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);
You can’t perform that action at this time.