Skip to content

Instantly share code, notes, and snippets.

View tigerclaw-az's full-sized avatar

Erik James tigerclaw-az

View GitHub Profile
function formatDuration (seconds) {
// Complete this function
if (seconds === 0) return 'now';
var calc = {
years: {time: 60*60*24*365, str: 'year'},
days: {time: 60*60*24, str: 'day'},
hours: {time: 60*60, str: 'hour'},
mins: {time: 60, str: 'minute'}
}, duration = [];
function prime(num) {
var primes = [],
i, j;
if (num < 2) return [];
for (i = 2; i <= num; i++) { primes[i] = true; }
for (i = 2; i <= Math.floor(Math.sqrt(num)); i++) {
var n = 0;
function tongues(code) {
var vowels = ['a', 'i', 'y', 'e', 'o', 'u'],
consonants = ['b', 'k', 'x', 'z', 'n', 'h', 'd', 'c', 'w', 'g', 'p', 'v', 'j', 'q', 't', 's', 'r', 'l', 'm', 'f'];
return code.split('').map(function(l) {
var v = vowels.indexOf(l.toLowerCase()),
c = consonants.indexOf(l.toLowerCase()),
letter = l;
if (v !== -1) {
@tigerclaw-az
tigerclaw-az / generateUuid.js
Created January 18, 2014 04:01
Generate one or more UUIDs
/**
* @param {Number} length (optional) Number of UUIDs to generate
* @return {String|Array} UUID(s)
*/
generateUuid: function(length) {
var uuids = length ? [] : null,
uuid,
generate = function() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
@tigerclaw-az
tigerclaw-az / debug.js
Created January 18, 2014 04:03
JavaScript debugging helper functions
/**
* Defines the start point of a debugging section
* @param {string} what Decription of debug section [optional]
* @example
* console.beginDebugging(); // Will try to use the function name as description
* console.beginDebugging('my method'); // Uses 'my method' as description
*/
console.beginDebugging = function beginDebugging(what) {
var caller = console.beginDebugging.caller,
title;
@tigerclaw-az
tigerclaw-az / string-prototypes.js
Last active January 3, 2016 15:58
Additional functions applied to the JavaScript String.prototype
String.prototype.capitalizeFirstLetter = function capitalizeFirstLetter() {
return this[0].toUpperCase() + this.slice(1);
};
String.prototype.capitalizeAllWords = function capitalizeAllWords() {
return this.replace(/(^| )\w/g, function(match) {
return match.toUpperCase();
});
};
@tigerclaw-az
tigerclaw-az / pre-commit-forbidden.rb
Last active January 4, 2016 03:29
pre-commit hook for Git that looks for certain patterns and rejects the commit if found
#!/usr/bin/env ruby -w
FORBIDDEN = [
/(?<!\/\/\s)console\.log/,
/(?<!\/\/\s)console\.debug/,
/(?<!\/\/\s)echo print_r/,
/\bdo not commit\b/i
]
full_diff = `git diff --cached --`
@tigerclaw-az
tigerclaw-az / pre-commit-jshint.sh
Created January 22, 2014 16:59
Git pre-commit hook that will run jshint against files being committed
#!/bin/sh
files=$(git diff --cached --name-only --diff-filter=ACM | grep ".js$")
if [ "$files" = "" ]; then
exit 0
fi
pass=true
for file in ${files}; do
@tigerclaw-az
tigerclaw-az / pre-commit.bash
Last active January 4, 2016 03:29
Git pre-commit hook that will look for all 'pre-commit-*' hooks and execute them one at a time.
#!/bin/bash
SCRIPTPATH=`git rev-parse --show-toplevel`"/.git/hooks"
HOOKS="${SCRIPTPATH}/pre-commit-*"
shopt -s nullglob
pass=true
for hook in $HOOKS
@tigerclaw-az
tigerclaw-az / .csslintrc
Created February 13, 2014 15:40
CSS Linter file
{
"important": true,
"adjoining-classes": true,
"known-properties": true,
"box-sizing": false,
"box-model": true,
"overqualified-elements": true,
"display-property-grouping": true,
"bulletproof-font-face": true,
"compatible-vendor-prefixes": true,