Skip to content

Instantly share code, notes, and snippets.

View yakovenkodenis's full-sized avatar
:octocat:

Denis Yakovenko yakovenkodenis

:octocat:
View GitHub Profile
@slikts
slikts / context-vs-redux-2020.md
Last active March 6, 2022 20:41
Up to date answer about when to use React context or Redux (Redux Toolkit)

nelabs.dev

React context vs Redux in 2020

The [React docs][condoc] give some example use cases for context:

Context is designed to share data that can be considered “global” for a tree of React components, such as the current authenticated user, theme, or preferred language.

The common property of these use cases is that data like the current theme doesn't change often and needs to be shared deep down the component tree, which would be cumbersome with "[prop drilling][drill]". Something else that needs to be shared everywhere is the application state when using a "single source of truth" pattern, so it would follow that the context API would help with that as well, but there's a catch: components that use context will rerender every time that the provided value changes, so sharing the whole application state through context would cause excessive render lifecycles.

@artalar
artalar / map_typed.ts
Last active September 22, 2022 07:35
type M = [any, any];
type Delete<k, m extends M> = k extends m[0]
? m extends [k, any]
? never
: m
: m[0] extends k
? [unknown, unknown]
: m;
type Add<k, v, m extends M> = [k, v] | Delete<k, m>;
type Get<k, m extends M> = k extends m[0]
import pandas as pd
from collections import Counter
import tensorflow as tf
from tffm import TFFMRegressor
from sklearn.metrics import mean_squared_error
from sklearn.model_selection import train_test_split
import numpy as np
# Loading datasets'
var str = 'class ಠ_ಠ extends Array {constructor(j = "a", ...c) {const q = (({u: e}) => {return { [`s${c}`]: Symbol(j) };})({});super(j, q, ...c);}}' +
'new Promise((f) => {const a = function* (){return "\u{20BB7}".match(/./u)[0].length === 2 || true;};for (let vre of a()) {' +
'const [uw, as, he, re] = [new Set(), new WeakSet(), new Map(), new WeakMap()];break;}f(new Proxy({}, {get: (han, h) => h in han ? han[h] ' +
': "42".repeat(0o10)}));}).then(bi => new ಠ_ಠ(bi.rd));';
try {
eval(str);
} catch(e) {
alert('Your browser does not support ES6!')
}
@yakovenkodenis
yakovenkodenis / anagram.js
Last active January 3, 2017 17:06
A function that takes an array of random words and outputs a two-dimensional array of anagrams.
// Very inefficient but purely declarative approach
const findAnagrams = words => {
const pairIsAnagram = (word1, word2) =>
word1.split('').sort()
.reduce(
(acc, el, i) => { acc[i] = el == acc[i]; return acc; },
word2.split('').sort()
)
.reduce((acc, el, i) => acc && el, true);
@yakovenkodenis
yakovenkodenis / cartpole.py
Last active April 29, 2019 03:58
Solving CartPole-v0 in OpenAI gym environment using tabular Q-learning
import os
import gym
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from collections import defaultdict
@yakovenkodenis
yakovenkodenis / grid_search_for_wlr.py
Created October 15, 2016 17:02
Grid Search for Locally Weighted Linear Regression
import numpy as np
import pandas as pd
from statistics import mean
from sklearn.grid_search import ParameterGrid
from sklearn.preprocessing import StandardScaler
def getPredict(theta, x):
return np.dot(x, theta)
@wojteklu
wojteklu / clean_code.md
Last active November 18, 2024 16:37
Summary of 'Clean code' by Robert C. Martin

Code is clean if it can be understood easily – by everyone on the team. Clean code can be read and enhanced by a developer other than its original author. With understandability comes readability, changeability, extensibility and maintainability.


General rules

  1. Follow standard conventions.
  2. Keep it simple stupid. Simpler is always better. Reduce complexity as much as possible.
  3. Boy scout rule. Leave the campground cleaner than you found it.
  4. Always find root cause. Always look for the root cause of a problem.

Design rules

@yakovenkodenis
yakovenkodenis / DES.js
Created May 26, 2016 15:29
ES6 DES implementation (with PKCS7 padding)
export default class DES {
_initial_permutation = [
58, 50, 42, 34, 26, 18, 10, 2,
60, 52, 44, 36, 28, 20, 12, 4,
62, 54, 46, 38, 30, 22, 14, 6,
64, 56, 48, 40, 32, 24, 16, 8,
57, 49, 41, 33, 25, 17, 9, 1,
59, 51, 43, 35, 27, 19, 11, 3,