Skip to content

Instantly share code, notes, and snippets.

View rumkin's full-sized avatar
🧠
Getting deeper

Paul Rumkin rumkin

🧠
Getting deeper
View GitHub Profile
@rumkin
rumkin / async.js
Last active January 29, 2022 15:15
// 1. Функции, которые выполняют деление в синхронном и асинхронном стиле
function divide(a, b) {
if (b < 0) {
throw new Error('Divisin by zero')
}
return a / b
}
@rumkin
rumkin / index.spec.ts
Created October 20, 2021 02:20
Testup typescript setup
export default ({define, it}: Testup.ScriptScope) => {
}
@rumkin
rumkin / trap-command.sh
Created November 23, 2020 14:03
Trap command before execution
debug() {
echo "IT'S A TRAP: $BASH_COMMAND"
}
trap 'debug' DEBUG
echo 'HELLO'
@rumkin
rumkin / authkeys.sh
Last active December 1, 2023 00:31
Manage ssh keys with a script
#!/bin/bash
SSH_DIR=$HOME/.ssh/
AUTH_KEYS_DIR=${SSH_DIR}/authorized_keys.d
AUTH_KEYS_FILE=${SSH_DIR}/authorized_keys
# Utils
key-path() {
echo "${AUTH_KEYS_DIR}/${1}"
@rumkin
rumkin / Mixin.ts
Last active November 13, 2020 03:55
Mix methods into a type
type AbstractConstructorHelper<T> = (new (...args: any) => {}) & T;
type Extension = Record<string, {[key in 'method']: unknown}>
type Schematic<T extends Extension> = {
-readonly [K in keyof T]: T[K]['method']
}
type Mixin<T, S extends Extension> = (new (...args: ConstructorParameters<AbstractConstructorHelper<T>>) => InstanceType<AbstractConstructorHelper<T>> & Schematic<S>) & T;
@rumkin
rumkin / lists.sol
Created June 2, 2020 15:11
Lists example
pragma solidity ^0.6.0;
contract Lists {
mapping(uint => uint[]) public list;
function add(uint id, uint value)
public
{
list[id].push(value);
}
@rumkin
rumkin / css-routes-parser.js
Created May 31, 2020 13:58
Parse routes for CSS props
import escapeRegex from 'escape-regexp'
// Tokens
const T_TEXT = 1
const T_PATTERN = 2
const T_LIST = 3
const patternRe = /\[(?<marker>\+|\/|:)(?<id>[A-Za-z0-9_-]+)\]/y
const listRe = /\[(?<id>[A-Za-z0-9_-]+):(?<list>(\S+(\|\S+)*))\]/y
@rumkin
rumkin / readme.md
Last active May 27, 2020 16:12
EventTarget is an error teleporter

EventTarget is an error teleporter

Here is an exmaple of the code which will teleport Error from the place it should be handled to the place it whouldn't occur.

const target = new EventTarget()

target.addEventListener('event', () => {
  throw new Error('Some error')
})
@rumkin
rumkin / Readme.md
Last active May 25, 2020 17:31
Proofs for ideas

Ephemeral Patents

  • Hash: e132645f3c2072e44769b025b338b2e649e743140ad14e7fd846cf005c5f672f Date: 25-02-2020
  • Hash: 4d4814b2978635d27efb0b0eefa248f6b5514e13d26d78671c8ec9bddf3fc1cf Date: 25-02-2020
@rumkin
rumkin / readme.md
Last active May 21, 2020 13:59
Top-level modules

Top Level Modules

When Node.js or a browser imports top-level modules they usually executes top-level code.

Package.json

{
  "exports": {
 "import": "./index.js"