View gameOfLife.js
/* GAME OF LIFE | |
1. Any live cell with fewer than two live neighbours dies. | |
2. Any live cell with two or three live neighbours lives on to the next generation. | |
3. Any live cell with more than three live neighbours dies. | |
4. Any dead cell with exactly three live neighbours becomes a live cell. | |
*/ | |
const blinkerSeed = { | |
height: 5, | |
coords: [[2,1], [2,2], [2,3]] |
View callWhenReadyToGo.js
// Use only vanilla JS | |
function callWhenReadyToGo(cb) { | |
var allImagesLoaded = false; | |
// Look at all P and SPAN for very short text that says "loading" | |
// we don't want long text as it might be part of a longer paragraph then | |
var textEls = document.querySelectorAll('SPAN, P'); | |
var loadingEls = []; | |
for (var i = 0; i < textEls.lenth; i++){ |
View fib_iterative.js
function fib_i(num) { | |
console.log(`Series of ${num}`); | |
let num2 = 0, num1 = 1; | |
for (let i = 0; i < num; i++) { | |
console.log(num1); | |
const next = num2 + num1; | |
num2 = num1; | |
num1 = next; | |
} | |
} |
View term.sh
watch --color git diff --color --stat | |
watch git status --porcelain |
View .tmux.conf
set -g mouse on | |
#set-option -g mouse on | |
set -g status-interval 2 | |
set -g status-right "#S #[fg=green,bg=black]#(tmux-mem-cpu-load --colors --interval 2 --powerline-right)#[default]" | |
set -g status-right-length 60 | |
set -g pane-border-status top | |
set -g pane-border-format "#{pane_index} #{pane_current_command} #{pane_pid}" | |
set -g default-terminal "screen-256color" | |
bind-key P command-prompt -p 'save history to filename:' -I '~/tmux.history' 'capture-pane -S - ; save-buffer %1 ; delete-buffer' |
View mypi.cpp
// g++ -o mypi -std=c++14 mypi.cpp | |
#include <iostream> | |
#include <string> | |
#include <ctime> | |
#include <limits> | |
double myPi(long long loopCount); | |
typedef std::numeric_limits< double > dbl; |
View pomise_lite.js
function myPromise(fn){ | |
let done = false; | |
let next = []; | |
fn(() => { | |
done = true; | |
while (next.length > 0) next.pop()(); | |
}); | |
return { | |
then: fn => { |
View thinArrow.js
//Proposal for temporary scope variables | |
let result = something.crazy.long.bar ? something.crazy.long.bar() : something.crazy.long.other(); | |
//with() - Not 'strict' compliant | |
with (something.crazy.long){ | |
result = bar ? bar() : other(); | |
} | |
//fat arrow function |
View mrdbg-es5.js
//Transpiled from Babel | |
"use strict"; | |
function MRDbg() { | |
for (var _len = arguments.length, txt = Array(_len), _key = 0; _key < _len; _key++) { | |
txt[_key] = arguments[_key]; | |
} | |
return function (prev, cur, i, arr) { | |
if (i === 1) { |
View SomeController.js
//Use ES6 modules for your controllers in SailsJS | |
//requires https://github.com/artificialio/sails-hook-babel | |
export default { | |
controllerAction1(req, res) { | |
//... | |
}, | |
controllerAction2(req, res) { | |
//... |
NewerOlder