Skip to content

Instantly share code, notes, and snippets.

@eternal44
eternal44 / vendingMachine.js
Created May 4, 2016 20:09
Designing a vending machine
/*
##########
# PROMPT #
##########
- This vending machine must take user inputs (i.e. A1, A2, B1..etc) and dispenses an item after users input money.
- There are only 9 inputs.
- Assume that there are different kinds of items in the vending machine (Sprite, cheetos, etc).
- The vending machine must store instances of items to be dispensed, the item can't be created at the moment someone requests it.
@eternal44
eternal44 / calculator-revised.js
Last active May 20, 2016 07:04
Calculate a stringified math equation
function evaluate(string){
// reverse string & evaluate backwards to keep indexes relevant
console.log('original string: ', string);
string = reverseString(string);
var opArr = [];
var singleExp;
var firstPart;
var secondPart;
var evalString;
@eternal44
eternal44 / error.log
Created February 3, 2016 01:21
Error: 'node-pre-gyp install --fallback-to-build'
gyp ERR! node-gyp -v v1.0.1
gyp ERR! not ok
node-pre-gyp ERR! build error
node-pre-gyp ERR! stack Error: Failed to execute '/home/james/.nvm/versions/node/v5.4.1/bin/node /usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --module=/home/james/js_lab/makerSquare/4week/MKS-SF-shortly-express/node_modules/sqlite3/lib/binding/node-v47-linux-ia32/node_sqlite3.node --module_name=node_sqlite3 --module_path=/home/james/js_lab/makerSquare/4week/MKS-SF-shortly-express/node_modules/sqlite3/lib/binding/node-v47-linux-ia32 --python=/usr/bin/python2.6' (1)
node-pre-gyp ERR! stack at ChildProcess.<anonymous> (/home/james/js_lab/makerSquare/4week/MKS-SF-shortly-express/node_modules/sqlite3/node_modules/node-pre-gyp/lib/util/compile.js:83:29)
node-pre-gyp ERR! stack at emitTwo (events.js:87:13)
node-pre-gyp ERR! stack at ChildProcess.emit (events.js:172:7)
node-pre-gyp ERR! stack at maybeClose (internal/child_process.js:821:16)
node-pre-gyp ERR! stack at Process
@eternal44
eternal44 / .gitconfig
Last active April 11, 2016 20:26
James' .gitconfig file
[alias]
co = checkout
ci = commit
st = status
br = branch
lg = log --graph --full-history --all --color --pretty=format:"%x1b[31m%h%x09%x1b[32m%d%x1b[0m%x20%s[%an]"
type = cat-file -t
dump = cat-file -p
[user]
name = James Youn
@eternal44
eternal44 / something.txt
Created January 4, 2016 19:31
sublime key binding
[
{ "keys": ["ctrl+super+l"], "command": "angularjs_find" },
{ "keys": ["alt+up"], "command": "move_text_up" },
{ "keys": ["alt+down"], "command": "move_text_down" },
{ "keys": ["ctrl+q"], "command": "noop" },
{ "keys": ["j", "k"], "command": "chain",
"args": {
"commands": [
["exit_insert_mode"],
["save"]
@eternal44
eternal44 / something.txt
Created January 4, 2016 19:28
user preferences - sublime
{
"color_scheme": "Packages/User/SublimeLinter/All Hallow's Eve (SL).tmTheme",
"font_size": 9,
"ignored_packages":
[
""
],
"tab_size": 2,
"translate_tabs_to_spaces": true,
"vintage_start_in_command_mode": true
@eternal44
eternal44 / getElementsByClassname.js
Created December 22, 2015 04:27
Trouble shooting infinite loop
var getElementsByClassName = function(className){
// Array of document element
var elementList = Array.prototype.slice.call(
document.body.querySelectorAll('*')
);
var results = [];
var count = elementList.length;
// check body independently since the above array doesn't contain 'body'
@eternal44
eternal44 / memoize.js
Created December 21, 2015 19:23
Memoize solution
_.memoize = function(func) {
var history = {};
var result;
return function() {
var args = Array.prototype.slice.call(arguments); // to set as object keys
var setResult = function(func){
result = func.apply(this, args);
};
@eternal44
eternal44 / memoize.js
Last active December 20, 2015 18:14
Function decorators
_.memoize = function(func) {
var history = {};
/* PSEUDO CODE
check if func & arguments in history
if they are: look up the stored return value
if not: run it with 'once' and store it in 'history' as an object with 3 properties:
history = {
{
function: ____,
@eternal44
eternal44 / sort.js
Created December 15, 2015 15:44
Custom 'sort' function
var sort = function(arr){
var newArray = [];
var copyOfArr = arr;
var count = arr.length;
while(copyOfArr.length > 0){
var minIndex = copyOfArr.indexOf(Math.min.apply(null, arr));
newArray.push(Number(copyOfArr.splice(minIndex, 1)));
}
return newArray;