Skip to content

Instantly share code, notes, and snippets.

View elierotenberg's full-sized avatar

Elie Rotenberg elierotenberg

View GitHub Profile
const state = {
counter: 0
};
const randomInt = (min, max) =>
Math.floor(Math.random() * (max - min + 1)) + min;
const sleep = (min, max = min) =>
new Promise(resolve => {
setTimeout(resolve, randomInt(min, max));
@elierotenberg
elierotenberg / task.json
Created February 2, 2018 11:43
task.json file to run currently opened .m (octave/matlab) file with Ctrl+Shift+B
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "Run",
"type": "shell",
"windows": {
"command": "C:\\Octave\\Octave-4.2.1\\bin\\octave-gui.exe",
@stores({
...
})
@debouncePropsUpdate({
x: 1000,
})
@throttlePropsUpdate({
y: 1000,
})
class MyComponent extends React.Component {
@elierotenberg
elierotenberg / ComplexClass-0.js
Created December 14, 2015 16:40
babel-transform-legacy-decorators v1.3.0 bug
import autobind from './autobind';
class Base {
constructor(v) {
this.v = v;
}
}
function multiply(by) {
return function $multiply(target, name, descriptor) {
@elierotenberg
elierotenberg / match-with-example.js
Last active December 8, 2015 08:53
Match with in JS DSL
import match, { $, $$$ } from 'match-with';
// l is a list
const length = match(l).with(
// $() is a single-item named placeholder
// $$$() is a rest-collecting named placeholder
// .when(predicate) adds a guard predicate
clause([$('head'), $$$('tail')]).when(({ tail }) => tail.length > 0)).then(({ head, tail }) => 1 + tail.length),
@elierotenberg
elierotenberg / statefulComponent.jsx
Last active March 3, 2016 23:41
Generator function as a stateful component
const willUnmount = Symbol('unmount');
function statefulComponent(getInitialState, render, componentWillUnmount = () => void 0) {
return function*(props) {
const internalId = React.pleaseGiveMeAnInternalId();
const state = getInitialState(props);
const setState = (nextState) => {
Object.assign(state, nextState);
React.pleaseRerenderThisInternalId(internalId);
};
const $x = Symbol();
const t = { $x: 4, y: 5, z: 6 };
const { [$x], ...collect } = t; // collect = { y: 5, z: 6 }
@elierotenberg
elierotenberg / super1.js
Created June 21, 2015 17:47
super return value
let x;
class A {
constructor() {
this.a = true;
// explictly returns this
return this;
}
}
@elierotenberg
elierotenberg / Preferences.sublime-settings
Last active August 29, 2015 14:23
Preferences.sublime-settings
{
"always_show_minimap_viewport": true,
"bold_folder_labels": true,
"color_scheme": "Packages/Oceanic Next Color Scheme/Oceanic Next.tmTheme",
"copy_with_empty_selection": true,
"ensure_newline_at_eof_on_save": true,
"font_family": "Consolas",
"font_options": "subpixel_antialias",
"highlight_line": true,
"highlight_modified_tabs": true,
@elierotenberg
elierotenberg / gist:6d3b7d4d3751c4ea0103
Created June 8, 2015 15:21
Composing @Nexus.component
@component(() => ({
users: ['remote://users', {}],
}))
@component(({ users }) =>
users.mapKeys((userId) =>
[`user:${userId}`, [`remote://users/${userId}`, { firstName: 'John', lastName: 'Doe' }]]
).toObject()
)
class UserList extends React.Component {
render() {