Skip to content

Instantly share code, notes, and snippets.

View nicksheffield's full-sized avatar

Nick Sheffield nicksheffield

View GitHub Profile
@nicksheffield
nicksheffield / server.js
Created November 22, 2013 02:02
Basic Node.js hello world example
var http = require('http');
var server = http.createServer(function (request, response) {
response.writeHead(200, {"Content-Type": "text/html"});
response.write('<h1>Hello World</h1>');
response.end();
console.log('Request: '+request.url);
@nicksheffield
nicksheffield / app.js
Last active January 4, 2016 18:29
Node.js Boilerplate
var
express = require('express'),
io = require('socket.io').listen(server, {log: false}),
mongoose = require('mongoose'),
morgan = require('morgan'),
app = express()
app.listen(8000);
@nicksheffield
nicksheffield / package.json
Last active August 29, 2015 13:56
Node JS Package example
{
"name" : "appname",
"version" : "0.0.1",
"description" : "Description goes here.",
"main" : "app.js",
"author" : "Nick Sheffield",
"dependencies" : {
"express" : "~4.7.2",
"mongoose" : "~3.6.2",
"morgan" : "~1.2.2"
@nicksheffield
nicksheffield / Links.txt
Created March 3, 2014 21:59
Links for the bootcamp class
@nicksheffield
nicksheffield / sprite.css
Created March 4, 2014 22:26
Sprite button in css
.sprite{
background-image: url(button_sprite.png);
background-repeat: no-repeat;
width: 198px; /* width of one button */
height: 54px; /* height of one button */
margin: 2em 0;
/* optional, makes the background slide */
-webkit-transition: background-position 0.1s ease-out;
transition: background-position 0.1s ease-out;
@nicksheffield
nicksheffield / ribbon.svg
Last active August 29, 2015 13:57
SVG of a ribbon with twitter logo
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@nicksheffield
nicksheffield / script.js
Last active August 29, 2015 13:57
iOS style sticky section headers
$(window).scroll(function(){
var scrollY = window.scrollY // how far you are scrolled down
$('section').each(function(){
var e = $(this), // element
height = e.height() // height of element
eTop = e.offset().top // element top offset,
h1 = e.find('h1') // title element
// if the screen is scrolled down past the top of the section
@nicksheffield
nicksheffield / angleTools.js
Last active July 20, 2016 04:22
Work out angles and distances between objects that have x and y properties.
// es6
const at = {
angle: (a,b)=>Math.atan2(b.y-a.y,b.x-a.x)/Math.PI*180,
dist: (a,b)=>Math.sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)),
step: (a,s)=>({x:s*Math.cos(a*Math.PI/180),y:s*Math.sin(a*Math.PI/180)})
}
// es5
var at = {
angle: function(a,b){return Math.atan2(b.y-a.y,b.x-a.x)/Math.PI*180},
@nicksheffield
nicksheffield / gist:aa6b02d384d82c1fdd0b
Created May 1, 2014 04:03
Adds the circle method to 2d canvas context
CanvasRenderingContext2D.prototype.circle = function (x, y, r) {
this.beginPath();
this.arc(x, y, r, 0, 2 * Math.PI, false);
this.closePath();
}
@nicksheffield
nicksheffield / angular-socket.js
Last active September 25, 2015 04:42
AngularJS Socket.io module
var ngSocket = angular.module('ngSocket', []);
ngSocket.factory('socket', ['$rootScope', function ($rootScope) {
var socket = io.connect(location.origin+':9001');
return {
on: function (eventName, callback) {
socket.on(eventName, function () {
var args = arguments;
$rootScope.$apply(function () {
callback.apply(socket, args);