Skip to content

Instantly share code, notes, and snippets.

View ronapelbaum's full-sized avatar

Ron Apelbaum ronapelbaum

View GitHub Profile
@ronapelbaum
ronapelbaum / .travis.yml
Created May 4, 2017 05:50
How to run ESLint in you travis CI
language: node_js
node_js:
- "6"
script:
- npm run lint
- npm run build
- npm test
@ronapelbaum
ronapelbaum / index.js
Created April 1, 2020 09:45
javascript interview question - findIntersection
/**
* https://dev.to/coderbyte/a-common-coding-interview-question-461f
* https://jsfiddle.net/ronapelbaum/yLkbg4v1/
*/
function sol1(arr1, arr2) {
// O(n*m)
return arr1.filter(d => arr2.includes(d));
}
function sol2(arr1, arr2) {
@ronapelbaum
ronapelbaum / index.js
Created April 1, 2020 09:41
High Order Functions - Array.prototype.filter
/**
* https://jsfiddle.net/ronapelbaum/qk6mcrae/
*/
// HOF get a func and returns a func
function createFilterFunc(fn) {
return function(arr) {
const res = [];
for(let i = 0; i < arr.length; i++) {
if(!!fn(arr[i])) {
res.push(arr[i]);
@ronapelbaum
ronapelbaum / git-increment.js
Created November 19, 2018 08:24
git-increment
const proc = require('child_process');
const gitGetTag = cb => proc.execFile('git', ['describe', '--abbrev=0', '--tags'], (err, res) => cb(res.trim()));
const gitPutTag = (tag, cb) => proc.execFile('git', ['tag', tag], (err, res) => cb(res.trim()));
const parseTag = (tag) => {
try {
return /v(\d+)\.(\d+)\.(\d+)(-(\d+))?/.exec(tag).slice(1)
} catch (e) {
// do nothing
@ronapelbaum
ronapelbaum / generators.js
Created September 20, 2018 06:21
play with javascript generators
const sleep = ms => new Promise(res => setTimeout(()=>res(ms), ms))
// main1();
// main2();
// run(main3);
run2(main3);
function main1() {
console.log(1);
sleep(100).then(t => console.log(2, t));
@ronapelbaum
ronapelbaum / app.js
Last active July 23, 2018 08:27
test.js - minimal nodejs test
const app = () => {
const list = []
return {
add: (item) => list.push(list),
get: () => list.slice(0),
}
}
module.exports = app
@ronapelbaum
ronapelbaum / package.json
Last active March 29, 2018 05:57
NPM Version Management Auto-Patch
{
"name": "my-package",
"version": "1.2.0",
"scripts": {
"patch-version": "node patch-version.js",
"tag-version": "node tag-version.js \"release-tag\"",
"prerelease": "npm run patch-version && npm run tag-version",
"release": "npm publish",
}
}
@ronapelbaum
ronapelbaum / README.MD
Last active March 28, 2018 18:33
interview: front end developer

interview: front end developer

basic algorithm

  1. implement function reverseString(str)
  2. implement function factorial(n)
  3. implement function removeFromArray(arr, arg1, arg2, ...)

javascript

  1. What will be the output of this:
@ronapelbaum
ronapelbaum / README.MD
Created June 13, 2017 11:41
Remove the `/* eslint-disable */` comment at file header, for changed files on branch

When you try to add eslint to a large project, you better try this approach as in this script.

Now, you want to enforce your team members to actually remove the /* eslint-disable */ comment at file header, for all files that they've changed.

Here you go.

@ronapelbaum
ronapelbaum / README.MD
Last active May 7, 2017 09:45
interview: front end developer (answers)

Interview: Front-End developer (answers)

basic algorithm

1. implement function reverseString(str)

  • use simple iteration
  • split() vs join()
  • array vs string

2. implement function factorial(n)

  • use simple recurtion