Skip to content

Instantly share code, notes, and snippets.

View josephdburdick's full-sized avatar
😇
Mentally present

Joe josephdburdick

😇
Mentally present
View GitHub Profile
// non-modular
jQuery.fn.limit = function(count){
return $(this).filter(function(index){ return index < count; });
};
// non-modular usage
$('sel').limit(3);
// modular
var $ = require('jquery');
@josephdburdick
josephdburdick / service-worker.js
Last active August 29, 2015 14:27 — forked from deanhume/service-worker.js
Register Service Worker
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('service-worker.js').then(function(registration) {
// Registration was successful
console.log('ServiceWorker registration successful with scope: ', registration.scope);
registration.pushManager.subscribe().then(function(subscription){
isPushEnabled = true;
console.log("subscription.subscriptionId: ", subscription.subscriptionId);
console.log("subscription.endpoint: ", subscription.endpoint);
// TODO: Send the subscription subscription.endpoint
@josephdburdick
josephdburdick / gulpfile.js
Last active September 21, 2015 22:42 — forked from danharper/gulpfile.js
New ES6 project with Babel, Browserify & Gulp
var gulp = require('gulp');
var sourcemaps = require('gulp-sourcemaps');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var browserify = require('browserify');
var watchify = require('watchify');
var babel = require('babelify');
function compile(watch) {
var bundler = watchify(browserify('./src/index.js', { debug: true }).transform(babel));
@josephdburdick
josephdburdick / smarten.js
Created July 7, 2016 20:32 — forked from hkfoster/smarten.js
Replace dumb quotes with smart quotes, double dashes with an em dash, and three dots with an ellipsis.
// Make punctuation smarter
jQuery.fn.smarten = (function() {
function smartenNode(node) {
if (node.nodeType === 3) {
node.data = node.data
.replace(/(^|[-\u2014/(\[{"\s])'/g, "$1\u2018") // Opening singles
.replace(/'/g, "\u2019") // Closing singles & apostrophes
.replace(/(^|[-\u2014/(\[{\u2018\s])"/g, "$1\u201c") // Opening doubles
.replace(/"/g, "\u201d") // Closing doubles
{
"env": {
"browser": true,
"builtin": true,
"jasmine": true,
"mocha": true,
"node": true
},
"extends": "airbnb",
"globals": {
[libs]
[ignore]
[options]
{
"presets": [
"stage-2",
"es2015"
],
"plugins": [
"transform-flow-strip-types",
"transform-object-assign",
"transform-class-properties",
"transform-runtime"
# Logs
logs
*.log
npm-debug.log*
# compiled js
dist
# Dependency directories
node_modules
src
.idea/
node_modules
@josephdburdick
josephdburdick / random.js
Created September 12, 2016 22:47 — forked from kerimdzhanov/random.js
Javascript get random number in a specific range
/**
* Get a random floating point number between `min` and `max`.
*
* @param {number} min - min number
* @param {number} max - max number
* @return {float} a random floating point number
*/
function getRandom(min, max) {
return Math.random() * (max - min) + min;
}