Skip to content

Instantly share code, notes, and snippets.

View nojvek's full-sized avatar

Noj Vek nojvek

View GitHub Profile
@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 / 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 / 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 / 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 / loader.js
Created June 28, 2017 19:39
Module loader interview question
const _moduleRegistry = {};
// Adds a module to _moduleRegistry
function _addModule(name, deps) {
const module = { name, deps };
module.load = () => {
console.log(`'${name}' loaded`);
return module;
}
_moduleRegistry[name] = module;
# TIPS:
# Please write high level pseudocode approach before writing actual code.
# Use meaningful variables, comments and indent your code.
# Your code should compile, run and produce the correct output.
# Write some tests
# You are totally free to use search engines and stackoverflow.
# Talk about O(n) CPU and memory requirements. Best case and worst case.
# Talk about what things you'll still need to do for your code to be production ready at the end.
num2words_map = {
@nojvek
nojvek / dome2jade.js
Last active September 3, 2017 03:07
dom2jade.coffee - Select DOM element in Chrome debugger, export it to jade
// Usage: copy(dom2jade($0, 0))
// copy copies to clipboard, $0 is selected elem in dev tools, 0 is pre-indent needed
// The beauty about this is that it lets the browser handle quirky html
const dom2jade = function(elem, numIndents = 0) {
const dom2tree = function(elem) {
let text;
if ((elem.nodeType === document.TEXT_NODE) && (elem.nodeValue.trim() !== "")) {
text = elem.nodeValue.trim();
@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 / eslint_suppresor.js
Last active February 6, 2018 22:00
eslint suppresor
/* eslint-env node */
const fs = require(`fs`);
// Generated using: node node_modules/eslint/bin/eslint.js -c .eslintrc.js media/**/*.es5.js -f json > _errors.json
const errors = JSON.parse(fs.readFileSync(`_errors.json`));
for (const error of errors) {
const {filePath, messages, source} = error;
const fileRuleTally = {};
const undefs = new Set();
@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