Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / .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 / 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 / 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 / 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 / 8ball.md
Last active May 27, 2016 06:09
Find the odd ball out

8 ball problem

Of 8 balls one of them is a different weight. The only way to find the different ball is to use a scale. Find the odd ball (no pun intended) and determine if it's heavier or lighter than the rest.

Solution summary

Use a decision tree to deduce what balls need to be removed.

Max number of weighings: 3 #####Notes:

  • Finding normal balls for reference in the 2 ball series is trivial so I won't reference finding them.
  • Numbers in an array represent balls on one side of a scale like "[1, 2, 3]".
@eternal44
eternal44 / countChars.js
Created June 3, 2016 00:18
Returns a map of characters & their consecutive frequency.
// 'AAAABBCDDDEEAA' => 'A4B2C1D3E2A2'
function countChars (str) {
var currentChar = str[0];
var charCount = 1;
var results = [];
for (var i = 1; i < str.length; i++) {
if(str[i] === currentChar) {
charCount++;
@eternal44
eternal44 / findIndex.js
Last active July 27, 2016 16:36
Finds the index of an integer in a sorted array
function bsearch(ns, n) {
var startPoint = 0
var endPoint = ns.length - 1
var midPoint
while((startPoint < (endPoint + 1))) {
midPoint = Math.floor((endPoint - startPoint) / 2) + startPoint
if(ns[midPoint] === n){
return midPoint