Skip to content

Instantly share code, notes, and snippets.

Noj Vek (Manoj P) nojvek

Block or report user

Report or block nojvek

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@nojvek
nojvek / paginate.js
Last active Jun 10, 2017
Paginate algorithm
View paginate.js
/*
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
View printDiff.ts
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 Apr 7, 2017
inspect_module so you can know what the module internals are
View inspect_module.py
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 Jan 29, 2018
VSCode Keybindings
View keybindings.json
[
{"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 Mar 17, 2018
Sync git branch + changes from one machine to another continuosly
View sync.sh
#!/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 Mar 15, 2017
VSCode webpack attach
View launch.json
{
"name": "Attach",
"type": "chrome",
"request": "attach",
"port": 9222,
"url": "https://mixpanel.com/*",
"webRoot": "${workspaceRoot}",
"diagnosticLogging": false,
"sourceMapPathOverrides": {
"webpack:///./~/*": "${workspaceRoot}/node_modules/*",
View Object.map.js
/**
* 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 Dec 13, 2016
DroneSeed challenge
View droneseed.ts
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 Jun 18, 2016
tsc watch terminal notifier
View tsc watch
tsc --watch | xargs -L1 -I{} terminal-notifier -message '{}'
View ypeescript
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:
You can’t perform that action at this time.