Skip to content

Instantly share code, notes, and snippets.

View jaxxreal's full-sized avatar
😌
Working from smoothy club

Eugeny Voronin jaxxreal

😌
Working from smoothy club
View GitHub Profile
function order(sortKey) {
return (items) => {
return [...items].sort((a, b) => a[sortKey] < b[sortKey] ? 1 : -1);
};
}
function where(filter) {
const [filterKey] = Object.keys(filter);
return (items) =>
items.filter((item) => item[filterKey] === filter[filterKey]);
@jaxxreal
jaxxreal / js2jsx.bash
Created May 26, 2021 14:46
Rename js to jsx on MacOS
find ./ -depth -name "index.js" -exec sh -c 'mv "$1" "${1%.js}.jsx"' _ {} \;
function makePercent(inputArr) {
const sum = inputArr.reduce((sum, next) => sum + parseFloat(next), 0);
return inputArr.map(v => (parseFloat(v) / sum * 100).toFixed(3));
}
// time complexity O(2n)
// space complexity O(n+1)
// array length must be lower than 10.000.000 (10 millions) to make it run under 5s
@jaxxreal
jaxxreal / useCarousel.ts
Created November 22, 2019 05:28
Carousel hook with gestures support
import * as React from 'react';
const { default: TinyGesture } = require('tinygesture');
export function useCarousel(itemsLength: number) {
const [state, setState] = React.useState({ currentIndex: 0, translateValue: 0 });
const carouselRef = React.useRef<HTMLDivElement>(null);
React.useEffect(() => {
const gesture = new TinyGesture(carouselRef.current);
@jaxxreal
jaxxreal / compose.js
Created December 7, 2018 16:38
String code challenge
// Write a simple compose function, that works next way:
let addTwo = a => a + 2;
let mulitplyByFour = a => a * 4;
let subtractTen = a => a - 10;
compose(addTwo, mulitplyByFour, subtractTen)(45); // 178
@jaxxreal
jaxxreal / readme.md
Last active January 7, 2018 18:42
JS Tgn Weekends #1 official readme

Мероприятие пройдет в формате свободного микрофона. В зависимости от количества участников, каждому будет выделено от 5-10 минут «эфирного времени».

За это время нужно пройтись по следующим четырем пунктам:

О себе

Все что считаете нужным. Но помните, вы пришли общаться и знакомиться. От вашей открытости зависит открытость остальных участников.

Стоит упомянуть названия технологий, проектов, фреймворков, мест работы.

Кул-стори

@jaxxreal
jaxxreal / styleProps.md
Last active December 28, 2017 09:54
Styletron team worked hard, and added «styleProps» - special property to operate with element's styles. «styleProps» object won't be passed to the actual DOM-element which makes React happy, and you won't get ugly warnings about it 🎉

🤔 How it was before styleProps existed:

const OnboardingProgressContainer = styled('div', ({ visible = true }: { visible: boolean }) => ({
    display: 'flex',
    alignItems: 'center',
    justifyContent: 'flex-end',
    position: 'relative',
    flex: '0 0 auto',
    visibility: visible ? 'visible' : 'hidden',
@jaxxreal
jaxxreal / GooglePlace.tsx
Created December 8, 2016 13:11
React component for Google Places Autocomplete
import * as React from "react";
import { Component, ValidationMap, FormEvent, PropTypes } from "react";
import { includes, isFunction } from "lodash";
// components
import { TextField } from "../material";
// interfaces
import { UserAddress } from "../../interfaces/user";
import { GeoQuery } from "../../interfaces/google";
@jaxxreal
jaxxreal / PureCheckbox.js
Created October 22, 2016 13:09
PureCheckbox example
class PureCheckbox extends Component {
shouldComponentUpdate(nextProps) {
return nextProps.label !== this.props.label || nextProps.checked !== this.props.checked;
}
render() {
return <Checkbox {...this.props}/>;
}
}
@jaxxreal
jaxxreal / spriter.js
Created September 21, 2016 21:06
Make svg sprite with no pain (watch inside)
var fs = require('fs');
var path = require('path');
var sys = require('sys');
var exec = require('child_process').exec;
makeSprite();
console.log('start watching');
exec('svgo -f ./src/assets/icons' , () => {
fs.watch(`${__dirname}/src/assets/icons`, (eventType, filename) => {