Skip to content

Instantly share code, notes, and snippets.

View kiruh's full-sized avatar
👨‍💻
Exploring...

kiruh kiruh

👨‍💻
Exploring...
  • Google
  • Munich, Germany
View GitHub Profile
@kiruh
kiruh / .bashrc
Created May 12, 2021 12:31
virtualenv
export WORKON_HOME=/home/kiril/.virtualenvs
export PROJECT_HOME=/home/kiril/projects
export VIRTUALENV_PYTHON=/usr/bin/python3
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
source /usr/local/bin/virtualenvwrapper.sh
@kiruh
kiruh / .bashrc
Created May 12, 2021 12:06
direnv
eval "$(direnv hook bash)"
show_virtual_env() {
if [ -n "$VIRTUAL_ENV" ]; then
echo "($(basename $VIRTUAL_ENV)) "
fi
}
PS1='$(show_virtual_env)'$PS1
@kiruh
kiruh / defaultdict.js
Last active August 6, 2020 11:51
JavaScript implementation of Python's defaultdict using Proxy and Reflect
const defaultdict = (getDefault) =>
new Proxy(
{},
{
get: (target, key) => {
if (!Reflect.has(target, key))
Reflect.set(
target,
key,
typeof getDefault === "function" ? getDefault() : getDefault
@kiruh
kiruh / memoize.js
Last active August 14, 2019 09:46
Memoize decorator for ES6
let disabled = false;
let disabledMap = new WeakMap();
let storage = new WeakMap();
const hasMemoizedProperty = (obj, propName) => {
if (!storage.has(obj)) storage.set(obj, {});
const props = storage.get(obj);
if (propName in props) return true;
return false;
};
const getMemoizedProperty = (obj, propName) => {
@kiruh
kiruh / combineRootWithReducers.js
Created August 2, 2019 10:47
Combine root reducer with nested reducers
const combineRootWithReducers = ({
root = () => ({}), // reducer which should be on the root level of global state
reducers = {}, // other reducers
initial = {}, // initial state of global state
rootLast = false // if true, root reducer will be called after other reducers
}) => {
/*
this method allows you to combine basic reducers with a reducer which
manages state on the root level of global state
{
@kiruh
kiruh / AxiosTokenHelper.js
Last active July 14, 2019 15:00
This helper allows you to cancel old api calls, if new one occurs
export class AxiosTokenHelper {
/*
This helper allows you to cancel old api calls, if new
one occurs.
const helper = new AxiosTokenHelper();
const callToApi = async (...) => {
const source = helper.create();
try {
const response = await axios.get(