Skip to content

Instantly share code, notes, and snippets.

View nicksheffield's full-sized avatar

Nick Sheffield nicksheffield

View GitHub Profile
@nicksheffield
nicksheffield / flex.css
Created August 31, 2014 11:59
Extremely simple flexbox system
.flex{
display: flex;
flex: 1;
justify-content: space-between;
}
.flex-row { flex-flow: row nowrap; }
.flex-column { flex-flow: column nowrap; }
@nicksheffield
nicksheffield / gist:d4cc9228de0dca472dc0
Created February 25, 2015 00:17
random number generator
// r( max, min, decimal places)
function r(a,b,c){ return parseFloat((Math.random()*((a?a:1)-(b?b:0))+(b?b:0)).toFixed(c?c:0)); }
@nicksheffield
nicksheffield / RomanToInt.js
Created February 25, 2015 04:43
Roman numeral to integer converter
function romanToInt(s){
var n=0,i=0,d={'I':1,'V':5,'X':10,'L':50,'C':100,'D':500,'M':1000};
for(;i<s.length;i++)n+=d[s[i+1]]>d[s[i]]?d[s[i]]*-1:d[s[i]];
return n;
}
@nicksheffield
nicksheffield / flexy.css
Last active August 29, 2015 14:19
HTML attribute based flexbox framework
[layout], [data-layout] { display: flex; }
[layout~="row"], [data-layout~="row"] { flex-direction: row; }
[layout~="col"], [data-layout~="col"] { flex-direction: column; }
[layout~="full-col"], [data-layout~="full-col"] { flex-direction: column; min-height: 100vh; }
[justify~="start"], [data-justify~="start"] { justify-content: flex-start; }
[justify~="end"], [data-justify~="end"] { justify-content: flex-start; }
[justify~="center"], [data-justify~="center"] { justify-content: center; }
[justify~="between"], [data-justify~="between"] { justify-content: space-between; }
[justify~="around"], [data-justify~="around"] { justify-content: space-around; }
[align~="start"], [data-align~="start"] { align-items: flex-start; }
@nicksheffield
nicksheffield / gist:a543801d5d729e16ea18
Created June 4, 2015 02:04
Easy jQuery smooth scroll
# Modified from https://css-tricks.com/snippets/jquery/smooth-scrolling/
$('a[href*=#]:not([href=#])').click(function() {
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
if (target.length) {
$('html,body').animate({ scrollTop: target.offset().top }, 500, function(){
location.hash = target.selector;
@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(){
@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 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
<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 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