Skip to content

Instantly share code, notes, and snippets.

View me-andre's full-sized avatar

Andrew Pazniak me-andre

View GitHub Profile
const filter = (array, template) => array;
filter([{ a: 1, c: 2 }, { a: 3, b: 4 }, { a: 3, b: 2 }], { a: 1 }); // [{ a: 1, c: 2 }]
filter([{ a: 1, b: 2 }, { a: 3, b: 4 }, { a: 3, b: 2 }], { a: 3 }); // [{ a: 3, b: 4 }, { a: 3, b: 2 }]
filter([{ a: 1, c: 2 }, { a: 3, b: 4 }, { a: 3, b: 2 }], { a: 3, c: 2 }); // []
const [a, setA] = useState(1);
if (value < 0.5) {
const [b, setB] = useState(2);
}
const [c, setC] = useState(3);
console.log(c); // ?
// render 1: value < 0.5
// render 2: value > 0.5
const add = () => {};
const divide = () => {};
const multiply = () => {};
const apply = () => {};
const result = apply(
multiply(5),
add(1),
divide(2)
@me-andre
me-andre / train.js
Created January 15, 2020 21:51
finding train length puzzle
const getRandomLight = () => Math.random() >= 0.5;
const generateTrain = (length) => {
const head = {
prev: null,
next: null,
light: getRandomLight()
};
let prev = head;
for (let i = 0; i < length; i++) {
const { debounce, throttle, times, delay } = require('lodash');
const superContext = {
debounced: debounce(function () {
console.log(this.i);
}, 100),
throttled: throttle(function () {
console.log(this.i);
}, 100)
};
@me-andre
me-andre / js-code-style.md
Last active March 24, 2016 08:51
Javascript code style thoughts

Javascript Code Style Thoughts

Multiline var declaration

I would avoid multiline var for several reasons:

  1. You're visually grouping statements which may have unrelated logic except that you initialize variables. Example:
var {a, b} = getValues();
a = a || initializeA();
// good logical grouping
<FluxCache store={store} propName="items" component={Component} id={this.props.routeParams.id} />
var FluxCache = React.createClass({
componentWillMount() {
this.props.store.addListener('change', this.onStoreChange);
},
componentWillUnmount() {
this.props.store.removeListener('change', this.onStoreChange);
},
onStoreChange() {
@me-andre
me-andre / README.md
Last active August 29, 2015 14:22 — forked from denji/README.md

Quick uninstall JetBrains settings:

curl -sL https://gist.github.com/denji/9731967/raw/jetbrains-uninstall.sh | bash -s
class String
def constantize context = nil, &block
const_names = self.split '::'
if const_names.first.empty?
const_names.shift
const = ::Object
else
const = if context
context.class
elsif block
require 'eventmachine'
require 'em-http-request'
require 'fiber'
class FiberPool
class Fiber < ::Fiber
def initialize pool, *args
@resumed = false