Skip to content

Instantly share code, notes, and snippets.

View istarkov's full-sized avatar
💭
I need snow, now!

Ivan Starkov istarkov

💭
I need snow, now!
View GitHub Profile
@istarkov
istarkov / question.md
Last active March 5, 2018 22:00
Need help

I want to hold ordering of some items in SQL, like field in a table index: 0,1,2,3,4,... and I have operation moveItem

If I want to move item from index: 1 to index: 3 I can do

delete from table where index = 1;
update table set index = index - 1 where index > 1
update table set index = index + 1 where index >=3
insert into table (index) values (3)

The problem: old ubuntu does not support chrome http2 as chrome uses APLN which is exists in openssl ^1.0.2h

create file /etc/apt/sources.list.d/nginx.list and add lines

deb http://nginx.org/packages/mainline/ubuntu/ trusty nginx
deb-src http://nginx.org/packages/mainline/ubuntu/ trusty nginx
@istarkov
istarkov / peg parser
Last active March 14, 2021 16:59
Icu messages format pegjs parser
/*Parses ICU messages format https://messageformat.github.io/messageformat/guide/
like
{from} - {to} {results, plural,
one { # result }
many { # results }
} text {vr} rmm
{s, select,
man { He is "#"#"#" }
woman { She is # }
}
@istarkov
istarkov / esbuild.js
Created May 22, 2021 13:38
esbuild node app setup for latest stable node > 14.16.0
// same as `yarn esbuild index.ts src/**/*.ts --platform=node --format=esm --tsconfig=./tsconfig.json --outdir=dist --watch`
// but with respawn server on change
import esbuild from 'esbuild';
import fg from 'fast-glob';
import { spawn } from 'child_process';
const entryPoints = await fg(['index.ts', 'src/**/*.ts']);
const dev = process.env.NODE_ENV !== 'production';

Challenge

You have a json file with following structure (example)

[
  { 
    "id": 1,
    "title": "Hello",
 "description": "World"
@istarkov
istarkov / rollup-plugin-relay.js
Last active March 3, 2022 01:20
Fast and dirty rollup relay plugin (for use in vite + sveltekit)
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export default function relay() {
return {
name: 'relay',
transform(code) {
// Use indexOf as its probably ;-) faster
if (code.indexOf('graphql`') > -1) {
const re = /graphql`[^`]+(?<type>query|fragment|mutation)\s+(?<name>[\w_-\d]+)[^`]+`/gm;
let imports = [];
@istarkov
istarkov / .bashrc
Last active June 9, 2022 22:28
Bash alias for terraform, switches all subfolder workspaces loads secrets sets NOMAD and CONSUL envs
# ------------------------------------------------------------------------------
# `hashi` - shows all subfolders workspaces
# `hashi test` - switch all subfolders terraform workspaces to test, load test secrets and sets nomad and consul env vars
# `hashi -init-all` - execute terraform init at all subfolders terraform workspaces
# `hashi <tab>` - autocomplete workspaces
# `hashi .<tab>` - autocomlete and cd into
# `hashi -<tab>` - autocomlete commands
alias gitclean="git remote prune origin && git branch -vv | grep 'origin/.*: gone]' | awk '{print \$1}' | xargs git branch -D"
@istarkov
istarkov / icu.ts
Created November 4, 2021 11:41
icu.pegjs
/*Parses ICU messages format https://messageformat.github.io/messageformat/guide/
like
{from} - {to} {results, plural,
one { # result }
many { # results }
} text {vr} rmm
{s, select,
man { He is "#"#"#" }
woman { She is # }
}
@istarkov
istarkov / .zshrc
Last active April 17, 2023 06:06
gitclean alias
# gitclean allows to work with multiple origins, cleans all deleteded aliases
alias gitclean="(git remote | xargs git remote prune) && git branch -vv | egrep '('\$(git remote | xargs | sed -e 's/ /|/g')')/.*: gone]' | awk '{print \$1}' | xargs git branch -D"
@istarkov
istarkov / .zshrc
Created April 25, 2023 06:49
Get bw password by exact name, fix of this https://github.com/bitwarden/clients/issues/3366
# https://github.com/bitwarden/clients/issues/3366
# Usage:
# bwget <item-name>
# to get any org password
# bwget <item-name> null
# to get self password
bwget() {
local pwd
local count
# by default search inside any organisation