Skip to content

Instantly share code, notes, and snippets.

View nojvek's full-sized avatar

Noj Vek nojvek

View GitHub Profile
@nojvek
nojvek / paginate.js
Last active June 10, 2017 20:09
Paginate algorithm
/*
Write a method that returns a string representing the state of a pagination nav bar
# rule 1: the number of pages returned should not exceed the value of the "numVisiblePages" parameter
# rule 2: always show the first page
# rule 3: always show the last page
# rule 4: put ellipses where appropriate
# rule 5: place [] around the selected page and, if possible, center it
currentPage = 5
@nojvek
nojvek / printDiff.ts
Last active May 19, 2017 08:13
printDiff
printDiff(expected, encoded_actual, referencePath(relativeFileName), actualFileName);
/**
* Prints a nice diff that is useful for debugging baseline failures
* It doesn't print the most optimum diff but does it in O(n) time and gives a `good enough` diff for humans
* It also emits a `cp tests/baselines/local/<file> tests/baselines/reference/<file>`
* Which makes experience of updating basefiles case by case much more bearable
*/
export function printDiff(expectedText: string, actualText: string, expectedFileName: string, actualFileName: string) {
type LineNumMap = { [line: string]: number[] };
@nojvek
nojvek / inspect_module.py
Created April 7, 2017 22:58
inspect_module so you can know what the module internals are
def inspect_module(module_name):
module = importlib.import_module(module_name)
print('inspect: ' + module_name)
for name in dir(module):
if name[:2] != '__': # Ignore internals
print(' %s: %s' % (name, getattr(module, name)))
@nojvek
nojvek / keybindings.json
Last active January 29, 2018 23:57
VSCode Keybindings
[
{"key": "shift+cmd+k", "command": "workbench.action.tasks.terminate" },
{"key": "cmd+r", "command": "workbench.action.debug.restart", "when": "inDebugMode" },
{"key": "alt+s", "command": "workbench.action.gotoSymbol" },
{"key": "cmd+[", "command": "workbench.action.navigateBack" },
{"key": "cmd+]", "command": "workbench.action.navigateForward" },
{"key": "alt+[", "command": "editor.action.outdentLines", "when": "editorTextFocus && !editorReadonly"},
{"key": "alt+]", "command": "editor.action.indentLines","when": "editorTextFocus && !editorReadonly"},
{"key": "ctrl+]", "command": "editor.action.dirtydiff.next", "when": "editorTextFocus"},
{"key": "ctrl+[", "command": "editor.action.dirtydiff.previous", "when": "editorTextFocus"},
@nojvek
nojvek / sync.sh
Last active March 17, 2018 18:56
Sync git branch + changes from one machine to another continuosly
#!/usr/local/bin/bash
USAGE=$'Usage: sync.sh <user@host> <dest_dir> e.g ./sync.sh user@host \'~/dest_dir\''
SSH_HOST=${1:?$USAGE}
DEST_DIR=${2:-"~/`basename $PWD`"}
sync_files() {
declare -A file_hash_map
while IFS= read -r file; do
file=${file#"$PWD/"} # get relative path
@nojvek
nojvek / launch.json
Created March 15, 2017 21:22
VSCode webpack attach
{
"name": "Attach",
"type": "chrome",
"request": "attach",
"port": 9222,
"url": "https://mixpanel.com/*",
"webRoot": "${workspaceRoot}",
"diagnosticLogging": false,
"sourceMapPathOverrides": {
"webpack:///./~/*": "${workspaceRoot}/node_modules/*",
@nojvek
nojvek / Object.map.js
Created February 22, 2017 02:02
Object.map
/**
* Suppose there was an Object.map function similar to Array.map
* There is some discussion about this on es-discuss but no one has filed a formal proposal yet (someone should!)
* @param {Object} object
* @param {function} callback
*/
Object.map = function(object, callback) {
if (!object) {
throw new TypeError(`object is null or not defined`);
}
@nojvek
nojvek / droneseed.ts
Last active December 13, 2016 09:13
DroneSeed challenge
const MIN_HEIGHT = 4
const MAX_HEIGHT = 8
const HEIGHT_DELTA = MAX_HEIGHT - MIN_HEIGHT
interface Path {
startIndex: number
startHeight: number
endIndex: number
endHeight: number
}
@nojvek
nojvek / tsc watch
Created June 18, 2016 19:13
tsc watch terminal notifier
tsc --watch | xargs -L1 -I{} terminal-notifier -message '{}'
public render()
const todos = @.props.model.todos
let shownTodos = todos.filter (todo) ->
switch @.state.nowShowing
case ACTIVE_TODOS:
-< !todo.completed
case COMPLETED_TODOS:
-< todo.completed
default: