Skip to content

Instantly share code, notes, and snippets.

View johntran's full-sized avatar
🌈
Make it last forever, FRIENDSHIP NEVER ENDS

johntran

🌈
Make it last forever, FRIENDSHIP NEVER ENDS
View GitHub Profile
// HeartBeat.ino
//////////////////////////
//////////////////////////
void PRIME_HEARTBEAT(byte BeatColor)
{
byte CCSET;
int ColorSelection;
float in, out;
//Re-writing Underscore and LoDash functions.
var forEach = function(collection, callback) {
for (var key in collection) {
callback(collection[key]);
}
};
var map = function(collection, callback) {
var result = [];
@johntran
johntran / johnLinkedList.js
Last active August 29, 2015 14:27
Implementing a doubly-linked list.
var node = function(value, next, prev) {
this.data = value,
this.next = next,
this.prev = prev
};
var LinkedList = function() {
this.head = null;
this.tail = null;
this.size = 0;
/** Given an array, guarantee
* each element is shuffled once
* O(n) runtime
*/
Array.prototype.shuffle = function() {
var remainingElements = this.length;
var helper;
var target;
while (remainingElements) {
target = Math.floor(Math.random()*remainingElements--);
@johntran
johntran / walkingTheDOM.js
Last active September 12, 2020 20:09
walking the DOM from Douglas Crockford, JavaScript: The Good Parts, p. 36
/** Define a walk_the_DOM function that visits every
* node of the tree in HTML source order, starting
* from some given node. It invokes a function,
* passing it each node in turn. walk_the_DOM calls
* itself to process each of the child nodes.
*/
var walk_the_DOM = function walk(node, callback) {
callback(node);
node = node.firstChild;
while (node) {
// Given an array with nested arrays, return a non-nested array.
function flatten(collection) {
var result = [];
var getValues = function(collection, result) {
for (var key in collection) {
if (!Array.isArray(collection[key])) {
result.push(collection[key]);
} else {
getValues(collection[key], result);
function debounce(callback, wait, immediate) {
var timeout;
return function() {
var context = this;
var args = arguments;
var delayedFire = function() {
timeout = null;
if (!immediate) callback.apply(context, args);
};
clearTimeout(timeout);
@johntran
johntran / .bash_profile
Created September 1, 2015 21:57
ShipHawk bash profile
eval "$(rbenv init-)"
alias atm='open -a "Atom"'
alias prof='atm ~/.bash_profile'
alias dev='cd ~/Documents/shiphawk-dev'
alias dash='cd ~/Documents/dashboard-mvp'
alias hosts='sudo atm /private/etc/hosts'
alias elastic='elasticsearch --config=/usr/local/opt/elasticsearch/config/elasticsearch.yml'
alias redis='redis-server /usr/local/etc/redis.conf'
alias rls-s='rails s'
var myCoffee = "HOT"
if (myCoffee === "HOT") {
/** always use "===" over "==". "===" is more strict than "==", so less errors.
* see http://stackoverflow.com/questions/523643/difference-between-and-in-javascript
*/
console.log("Please proceed with caution");
} else if (myCoffee === "IS NOT HOT") {
console.log("IT IS NOT HOT");
}
{ "extends": "eslint-config-airbnb",
"env": {
"browser": true,
"node": true,
"mocha": true
},
"rules": {
"react/no-multi-comp": 0,
"import/default": 0,
"import/no-duplicates": 0,