Skip to content

Instantly share code, notes, and snippets.

View ilyash-b's full-sized avatar
😄
Working on Next Generation Shell

Ilya Sher ilyash-b

😄
Working on Next Generation Shell
View GitHub Profile
public int getId(String queryId, String queryParameter, String objectName) {
try (PreparedStatement preparedStmt = getConnection().prepareStatement(queryId)) {
preparedStmt.setString(1, queryParameter);
ResultSet u = preparedStmt.executeQuery();
if (u.next()) {
return u.getInt("id");
}
throw new SQLException(objectName + " does not exists");
} catch (SQLException e) {
e.printStackTrace();
@ilyash-b
ilyash-b / recurse_hash.ngs
Created March 4, 2022 08:03
Recurse into hashes
F recurse_hash(h:Hash, cb:Fun) {
F is_not_hash(x) x is not Hash
h.tr(is_not_hash -> F(val, ctx) {
cb(val, ctx._path)
})
}
test("recurse_hash(Hash, Fun) sum", {
h = {
'a': {'b': 2}
@ilyash-b
ilyash-b / deep_set.ngs
Created February 9, 2022 11:02
Autovivification for Next Generation Shell - experiment
# Following line will be needed when files will be auto-wrapped in "ns { ... }"
{ global deep_get, deep_set, deep_get_step, deep_set_step, deep_index_to_container_type }
doc %STATUS - experimental
F deep_get_step(node, _) {
throw LookupFail().set(container=node)
}
doc %STATUS - experimental
F deep_set_step(container, idx_or_key, next_idx_or_key) throw NotImplemented()
@ilyash-b
ilyash-b / gist:d7f03561235941f59d3eec921b06346f
Created March 5, 2020 15:03
Converge to iptables rules given in CSV files
#!/usr/bin/env ngs
# Turn rules parsing debugging with "DEBUG=rules" environment variable setting
COMMENT_PREFIX = 'aws-migration-'
INT_NUMBER_REGEX = /^[0-9]+$/
F is_ip(x:Str) {
octets = x.split('.')
#!/usr/bin/env ngs
# This script is rough translation of https://gist.github.com/shokoe/e7b4d80b63ea5931ba23bcad1c7684d4
# The translation was made as part of thinking about scripting by both parties: @shokoe, @ilyash-b
# The script was changed to match @ilyash-b's environment
# Starts new instance with same settings as given instances from backup AMI of the given instance
# Syntax: ec2_kamino.ngs <ENV> <ROLE>
# Syntax: ec2_kamino.ngs <INSTNACE_ID>
# If ENV and ROLE are given, finds the latest instance which has backup AMI
#!/usr/bin/env ngs
# This script is rough translation of https://gist.github.com/shokoe/e7b4d80b63ea5931ba23bcad1c7684d4
# The translation was made as part of thinking about scripting by both parties: @shokoe, @ilyash-b
# Syntax: ec2_kamino.ngs <source instance 'Name' tag> [target new instance 'Name' tag].
# If target name is not given <source name>-clone is used.
# Description: Builds a temporary template from a given instance and runs the latest found ami from that template.
# New instance settings can be overriden by OVERRIDES.
# AMI selection is filtered by AMI_SELECT_TAGS.
@ilyash-b
ilyash-b / ngs.rb
Created April 26, 2019 19:50
WIP brew packaging
class Ngs < Formula
desc "Next Generation Shell"
homepage "https://ngs-lang.org"
# url "https://github.com/ngs-lang/ngs/archive/v0.2.6.tar.gz"
url "https://github.com/ngs-lang/ngs/archive/69d761c84f45072e439e31b8cd70271e0862d406.tar.gz"
version "0.2.7-alpha"
# sha256 "22b8c371dcb6d55d0ff4f227b66523cdb07a15ff8ede72ff05cc9c478e67f1ca"
depends_on "bdw-gc" => :build
depends_on "cmake" => :build
depends_on "gnu-sed" => :build
@ilyash-b
ilyash-b / gist:037583905ae2be333c990cd22f47ee75
Created April 14, 2019 07:28
brew install -s -d ~/Downloads/ngs.rb
/usr/local/Homebrew/Library/Homebrew/brew.rb (Formulary::FromPathLoader): loading /Users/ilya/Downloads/ngs.rb
/usr/local/Homebrew/Library/Homebrew/brew.rb (Formulary::FormulaLoader): loading /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/awk.rb
/usr/local/Homebrew/Library/Homebrew/brew.rb (Formulary::FormulaLoader): loading /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/bdw-gc.rb
/usr/local/Homebrew/Library/Homebrew/brew.rb (Formulary::FormulaLoader): loading /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/libatomic_ops.rb
/usr/local/Homebrew/Library/Homebrew/brew.rb (Formulary::FormulaLoader): loading /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/pkg-config.rb
/usr/local/Homebrew/Library/Homebrew/brew.rb (Formulary::FormulaLoader): loading /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/cmake.rb
/usr/local/Homebrew/Library/Homebrew/brew.rb (Formulary::FormulaLoader): loading /usr/local/Homebrew/Library/Taps/homebrew/homebrew
@ilyash-b
ilyash-b / trello-tag.ngs
Last active January 11, 2021 15:25
[trello] Add prefix to all cards on personal board in given list
#!/usr/bin/env ngs
F main(list_name:Str) {
AUTH = "?key=${ENV.TRELLO_API_KEY}&token=${ENV.TRELLO_API_TOKEN}"
board = ``curl -s "https://api.trello.com/1/members/me/boards${AUTH}"``.the_one({"name": /personal/})
list = ``curl -s "https://api.trello.com/1/boards/${board.id}/lists${AUTH}&cards=open"``.the_one({"name": list_name})
tag = list.name.split(' ')[0]
pfx = "[${tag}] "
list.cards.reject({'name': Pfx('[')}).each(F(card) {
echo("${card.name} -> ${pfx}${card.name}")
@ilyash-b
ilyash-b / find-key.elv
Last active November 15, 2018 07:29
find key at any level of a tree and collect the associated value
# By zzamboni
fn find-key [tree key]{
if (eq (kind-of $tree) map) {
keys $tree | each [k]{
if (eq $k $key) {
put $tree[$k]
} else {
find-key $tree[$k]
}
}