Skip to content

Instantly share code, notes, and snippets.

[test]: Update test/* files
[dist]: Changes to submodules, version bumps, updates to package.json
[minor]: Small changes
[doc]: Updates to documentation
[fix]: Bug fixes
[bin]: Update binary scripts associated with the project
[refactor]: Refactor of existing code
[nit]: Small code review changes mainly around style or syntax
[feat]: New features
@johnstew
johnstew / digitalroot.js
Created April 3, 2013 14:32
JS Digital Root
function root(num){
var total = 0;
if(num.toString().length == 1){
var iNum = parseInt(num);
return iNum;
}else{
num.toString().split("").forEach( function(value){
var iValue = parseInt(value);
return total += iValue;
});
@johnstew
johnstew / formatteddivision.js
Created February 27, 2013 15:15
CoderByte Challenge: Formatted Division
function FormattedDivision(num1, num2){
var quotient = num1 / num2;
var fixed = quotient.toFixed(4);
var parts = fixed.toString().split(".");
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
return parts.join(".");
}
@johnstew
johnstew / gulpfile.js
Last active January 18, 2020 12:09
Gulp, Browserify, Multiple Entry Points
'use strict';
var gulp = require('gulp');
var sass = require('gulp-sass');
var connect = require('gulp-connect');
var watch = require('gulp-watch');
var batch = require('gulp-batch');
var gutil = require('gulp-util');
var source = require('vinyl-source-stream');
var browserify = require('browserify');
@johnstew
johnstew / jagnoster.zsh-theme
Created October 1, 2018 18:03
Custom J Agnoster ZSH Theme
# vim:ft=zsh ts=2 sw=2 sts=2
#
# agnoster's Theme - https://gist.github.com/3712874
# A Powerline-inspired theme for ZSH
#
# # README
#
# In order for this theme to render correctly, you will need a
# [Powerline-patched font](https://github.com/Lokaltog/powerline-fonts).
# Make sure you have a recent version: the code points that Powerline
@johnstew
johnstew / timer.js
Created July 30, 2018 15:50
timer timer timer
class Timer {
constructor(duration) {
const initDuration = (duration || 1) * 60;
this.initDuration = initDuration;
this.duration = initDuration;
this.intervalId = -1;
this.interval = 1000;
this.displayDuration = `${duration}:00`;
}
@johnstew
johnstew / gulpfile.js
Created February 25, 2016 22:04
Gulp, Browserify, SASS
// jscs:disable
'use strict';
var gulp = require('gulp');
var sass = require('gulp-sass');
var connect = require('gulp-connect');
var watch = require('gulp-watch');
var batch = require('gulp-batch');
var gutil = require('gulp-util');
var source = require('vinyl-source-stream');
@johnstew
johnstew / index.js
Last active October 2, 2017 18:47
Webpack v2 Tree Shaking and UglifyJS Dead Code Elimination Analysis
import { render } from './script1';
render();
class Foo {
async getData() {
try {
const f1 = await this.fakeAsyncCall();
const f2 = await this.fakeAsyncCall();
const f3 = await this.fakeAsyncCall();
const f4 = await this.fakeAsyncCall();
console.log(f1, f2, f3, f4); // 'foo data' x 4
// Variable assignment
const getData = async () => {
try {
const data = await fakeAsyncCall();
console.log(data); // foo data
} catch (error) {
console.error(`Uh oh: ${error}`);
}
}