Skip to content

Instantly share code, notes, and snippets.

View nojvek's full-sized avatar

Noj Vek nojvek

View GitHub Profile
@nojvek
nojvek / tsc watch
Created June 18, 2016 19:13
tsc watch terminal notifier
tsc --watch | xargs -L1 -I{} terminal-notifier -message '{}'
@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 / 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 / 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 / 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 / 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 / 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):
@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 / webpackJsonp.js
Created November 23, 2019 00:46
webpackJsonp modules
moduleMap = {};
for (const p of webpackJsonp) {
const modules = p[1];
for (const [moduleName, moduleFn] of Object.entries(modules)) {
const moduleContent = moduleFn.toString();
const nameParts = moduleName.split(`!`);
const moduleId = nameParts[nameParts.length - 1] + (nameParts.length > 1 ? `!` : ``);
if (!moduleMap[moduleId]) {
moduleMap[moduleId] = moduleContent
} else if (moduleMap[moduleId] !== moduleContent) {
@nojvek
nojvek / PerfMeasure.ts
Created January 14, 2020 22:36
Add marks and measures to performance timeline
const START = `start`;
const END = `end`;
export class PerfMeasure {
public measureName: string;
public started: boolean;
public ended: boolean;
constructor(measureName: string) {
this.measureName = measureName;