Skip to content

Instantly share code, notes, and snippets.

View bignimbus's full-sized avatar
🙃

Jeff Auriemma bignimbus

🙃
View GitHub Profile
@bignimbus
bignimbus / flattenAndAdd.js
Last active August 29, 2015 13:57
Given a JavaScript array, function flattens the array and returns the sum of all primitive-type numbers in the array. The function works recursively.
/*
Given a JavaScript array, function flattens the array and returns the sum of all primitive-type numbers in the array.
The function works recursively.
*/
function flattenAndAdd(arrayToFlatten) {
var originalArray = arrayToFlatten;
var repeat = 1;
@bignimbus
bignimbus / removeDuplicates.js
Created March 25, 2014 12:15
I created a Google Sheet to organize short bursts of lesson plan content across grade and content levels at Dever School. Script automatically deletes out-of-date entries. Script will also sort the page after deleting duplicates so that up-to-date information appears first.
/*
I created a Google Sheet to organize short bursts of lesson plan content across grade and content levels at Dever School.
Script automatically deletes out-of-date entries.
Script will also sort the page after deleting duplicates so that up-to-date information appears first.
*/
function removeDuplicates(){
Logger.clear();
Logger.log("starting over...");
var ss = SpreadsheetApp.openById(**ID NUMBER HERE **); //get spreadsheet
@bignimbus
bignimbus / audio.json
Last active August 29, 2015 13:58
Initial impression of a standard json container for Web Audio API sound synthesis information portability.
{
"name" : "Fun Song",
"instruments" : {
"funSound" : {
"sources" : {
"1" : "sine",
"2" : "sine",
},
"envelope": {
"attack" : 0,
@bignimbus
bignimbus / applyAndCall.js
Last active August 29, 2015 14:01
A brief explanation of JavaScript's native .apply() and .call() functions.
// In a recent interview I was stumped by a question about JS's native
// function.apply() and function.call() methods. I resolved to learn more
// about why these methods are useful to a JS developer. Here's what I now
// understand:
// let's make a simple function that introduces an individual.
// We pass arguments defining the interests of the individual.
// The greeting is personalized by the value of this.name.
function introduceMe (interest1, interest2) {
var that = this;
@bignimbus
bignimbus / nameGenerator.js
Last active August 29, 2015 14:01
(unfinished) A random first name generator. Just for fun!
var
vowels = ['a', 'e', 'i', 'o', 'u', 'y'],
consonants = ['b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'w', 'x', 'y', 'z'],
letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
function name (nameLength, numberOfNames) {
var names = [];
if (nameLength > 14) return 'too long!';
if (numberOfNames > 100 || numberOfNames < 0 || typeof numberOfNames !== 'number') numberOfNames = 1;
var
@bignimbus
bignimbus / rammstein.js
Last active August 29, 2015 14:07
Turns a normal array of words into German industrial metal lyrics.
Array.prototype.rammstein = function () {
var phrase = '', rammsteined = [];
this.forEach( function ( word ) {
phrase += word.toUpperCase() + ' ';
rammsteined.push( phrase );
});
return rammsteined;
}
@bignimbus
bignimbus / fakeMap.js
Last active August 29, 2015 14:08
Simple version of Array.prototype.map
Array.prototype.fakeMap = function (fn, context) {
var out = this instanceof Array ? [] : {},
context = context || this,
result,
n;
if (typeof fn !== "function") {
return [];
}
for (n in this) {
if (this.hasOwnProperty(n)) {
@bignimbus
bignimbus / palindrome.js
Last active August 29, 2015 14:10
detects whether a string is a palindrome
function isPalindrome (str) {
if (typeof str !== 'string') {
return false;
}
var n,
letters = str.split(''),
len = letters.length - 1;
for (n = 0; n <= len; n++) {
if (n !== len - n && letters[n] !== letters[len - n]) {
return false;
@bignimbus
bignimbus / math-pie.js
Last active October 16, 2015 20:03
Math.PIE() - a proposed ECMAScript 7 feature
// in order for this to work, you need a yummly dev account.
function makePie (response) {
var match = JSON.parse(response).matches[0],
yourPie = ["you could bake a delicious ",
match.recipeName,
" using "];
match.ingredients.forEach(function (ingredient) {
yourPie.push("[" + ingredient + "]");
});
@bignimbus
bignimbus / pre-commit-eslint
Created December 17, 2015 20:23 — forked from linhmtran168/pre-commit-eslint
Pre-commit hook to check for Javascript using ESLint
#!/bin/sh
STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep ".js\{0,1\}")
if [[ "$STAGED_FILES" = "" ]]; then
exit 0
fi
PASS=true