Skip to content

Instantly share code, notes, and snippets.

View ax2mx's full-sized avatar

Andrei ax2mx

View GitHub Profile
@ax2mx
ax2mx / memoize.js
Created July 17, 2022 09:07
Simple memoize wrapper
const argKey = x => x.toString() + ':' + typeof(x);
const generateKey = args => args.map(argKey).join('|');
const memoize = fn => {
const cache = Object.create(null);
return (...args) => {
const key = generateKey(args);
const val = cache[key];
if (val) return val;
const res = fn(...args);
@ax2mx
ax2mx / serializer.js
Created June 23, 2022 20:25
Simple object serializer
const serialize = (obj) => {
const type = typeof obj;
if (obj === null) return 'null';
else if (type === 'string') return `'${obj}'`;
else if (type === 'number') return obj.toString();
else if (type === 'boolean') return obj.toString();
else if (type !== 'object') return obj.toString();
else if (Array.isArray(obj)) {
return `[${obj}]`;
} else {
@ax2mx
ax2mx / curry.js
Last active August 26, 2024 11:50
The most concise currying function in JavaScript so far
const curryPartial = (fn, ...args) =>
args.length >= fn.length
? fn(...args)
: (...rest) => curryPartial(fn, ...args, ...rest);
@ax2mx
ax2mx / README.md
Created January 21, 2022 21:37 — forked from paolocarrasco/README.md
How to understand the `gpg failed to sign the data` problem in git

Problem

You have installed GPG, then tried to commit and suddenly you see this error message after it:

error: gpg failed to sign the data
fatal: failed to write commit object

Debug

@ax2mx
ax2mx / macos-process-management.md
Created March 11, 2019 08:23
Управление процессами в MacOS

Работа с процессами в MacOS

Отобразить список процессов

Наиболшую свободу действий в работе с процессами, как впрочем и во всём, даёт терминал и его команды.

ps aux # Выводит список и расширенную информацию о запущенных процессах

Список содержит следующие сведения:

@ax2mx
ax2mx / list-ssh-keys.md
Last active July 12, 2019 15:00
Отобразить открытые SSH-ключи

Вывести список имеющихся ключей: ls ~/.ssh/*.pub

Отобразить открытый ключ: cat ~/.ssh/id_rsa.pub or cat ~/.ssh/id_dsa.pub

Скопировать открытый ключ в буфер обмена% pbcopy < ~/.ssh/id_rsa.pub

@ax2mx
ax2mx / git-commit-style.md
Created December 24, 2018 14:56
Стиль написания коммитов
@ax2mx
ax2mx / git-commit-signing-win-config.md
Last active December 3, 2018 15:04
Настройка цифровой подписи для коммитов Git в Windows

Инструкций по настройки цифровой подписи для коммитов много [к примеру][1]. Но ни один алгоритм в точности не помог. Приведу здесь мой частный случай...

  1. Устанавливаем [GPG4Win][2]. У меня она установилась в C:\Users\UserName\AppData\Local\Gpg4win\..\GnuPG\bin\gpg.exe
  2. Создаём ключевую пару:
gpg --gen-key
  1. Проверяем, что ключ создан:
@ax2mx
ax2mx / create-remote-repo-from-local.md
Last active November 30, 2018 12:00
Создание удалённого репозитория из локального проекта

На всякий случай удаляем историю изменений локального проекта:

rm -rf .git

Заново создаём репозиторий:

git init
git add .
git commit -m "Initial commit"
@ax2mx
ax2mx / update-package-deps-versions.md
Last active October 24, 2018 09:31
Обновление версий зависимостей в package.json

Обновить версии зависимостей в package.json можно с помощью пакета [npm-check-updates][1].

Алгоритм такой:

npm i -g npm-check-updates # Устанавливаем пакет глобально
ncu # Получаем список доступных для обновления версий зависимостей
ncu -u # Обновляем версии зависимостей в package.json

Наконец обновляем зависимости в соответствии c новыми версиями: