Skip to content

Instantly share code, notes, and snippets.

View nicksheffield's full-sized avatar

Nick Sheffield nicksheffield

View GitHub Profile
@nicksheffield
nicksheffield / ordinality.js
Last active April 21, 2016 04:03
Get an ordinal string from a number. Eg; 1 -> '1st'
function ordinality(n) {
var s = '' + n, s1 = s[s.length-1], s10 = s[s.length-2]
if(!s10 || s10 && s10 != 1) {
if(s1 == 1) return s + 'st'
if(s1 == 2) return s + 'nd'
if(s1 == 3) return s + 'rd'
}
return s + 'th'
@nicksheffield
nicksheffield / http.js
Last active January 27, 2016 00:14
node.js http server with no npm dependencies
// Load dependency libraries
var http = require('http'),
fs = require('fs'),
path = require('path')
// Create the http server
var server = http.createServer(onRequest)
// start the server
server.listen(process.env.port || 8000)
@nicksheffield
nicksheffield / example.js
Created November 16, 2015 01:37
ngSocket
angular.module('app.controllers')
.controller('mainCtrl', function($scope, $socket) {
$scope.siteTitle = 'My Angular Site'
$socket.connect('http://localhost:9999')
$socket.on('welcome', function(data) {
console.log('welcome', data)
})
@nicksheffield
nicksheffield / Example.html
Last active November 13, 2015 00:45
Angular tooltip directive
<p ns-tooltip="yo dawg">Paragraph with a tooltip.</p>
@nicksheffield
nicksheffield / gulpfile.js
Last active January 26, 2016 23:54
Angular + Stylus
var gulp = require('gulp') // the main guy
var clone = require('gulp-clone') // used to fork a stream
var order = require('gulp-order') // reorder files in stream
var uglify = require('gulp-uglify') // minify js
var rename = require('gulp-rename') // rename file
var concat = require('gulp-concat') // merge files together
var stylus = require('gulp-stylus') // turn stylus into css
var addsrc = require('gulp-add-src') // mid-stream gulp.src()
var notify = require('gulp-notify') // OS-level notifications
var plumber = require('gulp-plumber') // handle errors without crashing
@nicksheffield
nicksheffield / gulpfile.js
Last active October 29, 2015 01:37
Angular with gulp
var gulp = require('gulp') // the main guy
var order = require('gulp-order') // reorder files in stream
var uglify = require('gulp-uglify') // minify js
var rename = require('gulp-rename') // rename file
var concat = require('gulp-concat') // merge files together
var addsrc = require('gulp-add-src') // mid-stream gulp.src()
var notify = require('gulp-notify') // OS-level notifications
var plumber = require('gulp-plumber') // handle errors without crashing
var annotate = require('gulp-ng-annotate') // safely minify angular
var templateCache = require('gulp-angular-templatecache') // cache angular template files
<snippet>
<content><![CDATA[
<?xml version="1.0"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="${1}" height="${2}" viewBox="0 0 ${1} ${2}">
${3}
</svg>
]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
@nicksheffield
nicksheffield / gulpfile.js
Last active February 10, 2022 05:33
Stylus with gulp
// jshint asi: true
var gulp = require('gulp') // the main guy
var clone = require('gulp-clone') // used to fork a stream
var notify = require('gulp-notify') // OS-level notifications
var rename = require('gulp-rename') // rename files in a stream
var stylus = require('gulp-stylus') // turn stylus code into css
var plumber = require('gulp-plumber') // handle errors
var beautify = require('gulp-cssbeautify') // make files human readable
var sourcemap = require('gulp-sourcemaps') // write sourcemaps
var minifycss = require('gulp-minify-css') // minify css code
@nicksheffield
nicksheffield / index.html
Created August 12, 2015 06:05
Basic jQuery DOM Traversal
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>DOM Traversal</title>
<style>
.box1, .box2, .box3, .box4, .box5{
border: 1px solid black;
padding: 1em;
@nicksheffield
nicksheffield / gulpfile.js
Last active January 7, 2017 06:04
gulp lesson example files
var gulp = require('gulp') // the main guy
var rename = require('gulp-rename') // rename files in a stream
var stylus = require('gulp-stylus') // turn stylus code into css
var plumber = require('gulp-plumber') // handle errors
var sourcemap = require('gulp-sourcemaps') // write sourcemaps
var minifycss = require('gulp-minify-css') // minify css code
var autoprefix = require('gulp-autoprefixer') // prefix any css with low support
gulp.task('css', function(){