Skip to content

Instantly share code, notes, and snippets.

View nojvek's full-sized avatar

Noj Vek nojvek

View GitHub Profile
@nojvek
nojvek / words2num.js
Created August 29, 2019 02:10
Words to Num
const wordsToNumMap = {
zero: 0,
one: 1,
two: 2,
three: 3,
four: 4,
five: 5,
six: 6,
seven: 7,
eight: 8,
@nojvek
nojvek / createElem.js
Created March 14, 2019 18:11
createEleme - simple dom helper for creating dom nodes
/**
* A simple helper for creating nested dom tree inspired by snabbdom-jsx syntax
* @param {string} name
* @param {{[attr: string]: any}} attrs
* @param {Array<HTMLElement | string>} children
* @returns {HTMLElement}
*/
export function createElem(name, attrs, children) {
const elem = document.createElement(name);
@nojvek
nojvek / nested_iterator.js
Created November 27, 2018 22:55
Nested iterator in javascript
/*
Problem: Write a class that implements the following iterator interface:
bool hasNext()
int next()
The iterator is used to sequentially iterate over a collection. Given an implementation of this iterator MyIterator, its usage can be summarized by the following snippet:
input = [1,2,3]
@nojvek
nojvek / line_counter.js
Created November 26, 2018 21:02
Count lines by file extension and path and output csv ready to be sql-analyzed
/* eslint-env node */
const fs = require(`fs`);
const path = require(`path`);
const filePaths = fs.readFileSync(`${__dirname}/file_list.txt`, `utf-8`).trim().split(`\n`);
console.log(`Total files`, filePaths.length);
for (let i = 0, len = filePaths.length; i < len; ++i) {
const filePath = filePaths[i];
let lines = null;
@nojvek
nojvek / backbone-debug.js
Created November 7, 2018 01:09
backbone debug
var $bbSetElement = Backbone.View.prototype.setElement;
Backbone.View.prototype.setElement = function setElement(element) {
if (this.el && this.el !== element) {
delete this.el.$bbView;
}
const domElem = element.jquery ? element[0] : element;
domElem.$bbView = this;
domElem.setAttribute(`data-backbone-view`, `true`);
return $bbSetElement.apply(this, arguments);
@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 / diff_asset_manifests.py
Last active March 23, 2019 00:36
diff asset manifests
import codecs
import json
import os
import sys
from os import path
from urllib import urlopen
asset_diff_dir = '/tmp/_asset_diff'
def load_file(file):
# 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 / bundler.py
Last active February 4, 2019 21:16
Bundler interview question
/**
* **********
* ** 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.
* Don't need to test extensively but describe what kind of tests you'll add as 'TODO:' comments
* You are totally free to use google and stackoverflow.
* Talk about O(n) CPU and memory requirements. Best case and worst case.
@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;