Skip to content

Instantly share code, notes, and snippets.

View ronen-e's full-sized avatar

Ronen Elster ronen-e

  • Tel Aviv, Israel
View GitHub Profile
@ronen-e
ronen-e / LICENSE
Last active May 24, 2021 08:55
bookmarklet for easier unfriending on facebook
/*
Copyright (c) 2021, Ronen Elster
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
@ronen-e
ronen-e / tasks-vue.js
Last active March 31, 2021 07:37
asynchronous task queue using Vue instances to keep the data
function newData(options = {}) {
var data = Object.assign({
sort: 'date+',
}, options, { queue: [] })
return data;
}
function delay(timeout = 0) {
return new Promise((resolve, reject) => setTimeout(resolve, timeout));
}
@ronen-e
ronen-e / index.css
Created June 23, 2018 19:48
Simple react-redux demo with translations for Browser
header {
margin-top: 20px;
display: flex;
justify-content: space-around;
}
@ronen-e
ronen-e / bind.js
Created April 5, 2017 05:16
autobind implementation - bind all prototype methods to instance
function binder(instance) {
for (var prop in instance) {
if (typeof instance[prop] === 'function' && !instance.hasOwnProperty(prop)) {
instance[prop] = instance[prop].bind(instance);
}
}
}
function binder2(instance, prototype) {
Object.keys(prototype)
@ronen-e
ronen-e / scope.js
Created April 5, 2017 05:15
Create new scope in javascript
function func() {
for (var i = 0; i < 10; i++) {
setTimeout(function() {
console.log('i:' + i);
}, 0);
}
}
// func();
function solution1() {
for (let i = 0; i < 10; i++) {
@ronen-e
ronen-e / connect.js
Created December 17, 2016 19:35
Redux connect implementation
function connect(mapStateToProps, mapDispatchToProps) {
return function connector(Component) {
class ContainerComponent extends React.Component {
componentDidMount() {
const { store } = this.context;
this.unsubscribe = store.subscribe(() => this.forceUpdate());
}
componentWillUnmount() {
this.unsubscribe();
@ronen-e
ronen-e / generator.js
Created December 13, 2016 17:05
Fun with generators
function* gen(param) {
if (!Array.isArray(param))
yield param;
else
for (let item of param)
yield* gen(item);
}
function* genNumbers(iterable) {
var items = gen(iterable);
@ronen-e
ronen-e / search-modules.js
Created October 10, 2016 14:18
Search modules
var Modules = new Map();
function addModule(id, searchFn) {
if (Modules.has(id)) {
throw 'Error: module: ' + id + ' already exists.';
}
Modules.set(id, searchFn);
}
function searchFn(id, query) {
@ronen-e
ronen-e / compose.js
Created October 9, 2016 16:14
compose functions
/**
* add the result of a function as an argument for the next function, e.g f(g(c))
* @param {...Function} functions to be composed
* @return {Function} the composed function
*/
function compose() {
var funcs = arguments;
return function composed(value) {
var i = funcs.length;
@ronen-e
ronen-e / solution.js
Last active August 16, 2018 13:29
Table render exercise with pure javascript
(function(window){
// sample data from server
var data1 = [ { "company_name":"Medline Industries, Inc.", "product":"Benzalkonium Chloride", "price":"481.63" }, { "company_name":"PD-Rx Pharmaceuticals, Inc.", "product":"Alprazolam", "price":"167.62", "fda_date_approved":"02/12/2015" }, { "company_name":"West-ward Pharmaceutical Corp.", "product":"Flumazenil", "fda_date_approved":"23/04/2015" }, { "company_name":"HyVee Inc", "product":"Aspirin", "price":"218.32", "fda_date_approved":"26/07/2015" }, { "company_name":"Aurobindo Pharma Limited", "product":"carisoprodol", "price":"375.58", "fda_date_approved":"28/11/2014" }, { "company_name":"Apotex Corp", "product":"Risperidone", "price":"213.49", "fda_date_approved":"06/11/2015" }, { "company_name":"Unit Dose Services", "product":"Lovastatin", "price":"169.14", "fda_date_approved":"14/09/2015" }, { "company_name":"Jubilant HollisterStier LLC", "product":"Dog Hair Canis spp.", "fda_date_approved":"31/12/2014" }, { "company_name":"AAA Pharmaceutical, Inc