Skip to content

Instantly share code, notes, and snippets.

function waitForElm(selector) {
return new Promise(resolve => {
if (document.querySelector(selector)) {
return resolve(document.querySelector(selector));
}
const observer = new MutationObserver(mutations => {
if (document.querySelector(selector)) {
resolve(document.querySelector(selector));
observer.disconnect();
@kharandziuk
kharandziuk / ssm-env.sh
Created July 28, 2022 16:15
AWS Parameter Store parameters as env
#!/bin/sh
prefix=$1
aws ssm get-parameters-by-path --path "$prefix" | jq -r -c '.Parameters[] | "\(.Name )=\"\(.Value)\""' | cut -c$((${#prefix}+1))-
@kharandziuk
kharandziuk / tasks.py
Created July 21, 2022 16:38
terraform import tasks
import sys
from invoke import task
@task(name="import")
def _import(c, name, id):
print(id)
resource_type, resource_name = name.split(".")
txt = f'resource "{resource_type}" "{resource_name}" {{}}'
@kharandziuk
kharandziuk / tasks.py
Created February 6, 2022 14:14
invoke move modules
@task
def task(c):
txt = c.run('terraform state list').stdout.strip()
for each in txt.split('\n'):
if 'module' in each:
continue
c.run(f'terraform state mv {each} module.before_transcoding.{each}')
@kharandziuk
kharandziuk / 1.sh
Created February 2, 2021 17:13
sophisticated pip
pip install -e git+ssh://git@github.com/org/name.git@staging#egg=package-name\&subdirectory=dir
@kharandziuk
kharandziuk / port-forwarding.sh
Last active October 1, 2020 15:55
Port forwarding
iptables -A INPUT -p tcp --dport 11101 -j ACCEPT
iptables -A PREROUTING -t nat -p tcp --dport 11101 -j REDIRECT --to-port 11100
iptables -t nat -I OUTPUT -p tcp -o lo --dport 11101 -j REDIRECT --to-ports 11100
@kharandziuk
kharandziuk / notes.md
Created August 19, 2020 20:49
words count

Note: I didn't have enough time to finish the "output" part so I am just printing a counter.

  • will determine what are our deliverables here(a script or a library or a service). Provide an interface according to requirements(should the script read a file or should the library work with the string?).
  • will try to think about the edge cases. For example: I treat '2d' as word but it's not a word in your original example. The other possible edge case is a huge file. I am saying "possible" because performance and "size of input" are not issues sometimes. Test it with a different sets of data(ideally provide automated tests)
  • check that code satisfies all the "code" specific to the company/team(naming conventions, style, documentation etc)
@kharandziuk
kharandziuk / non-zero.sh
Created August 19, 2020 08:10
ignore non-zero exit code
yum -y check-update || { rc=$?; [ "$rc" -eq 100 ] && exit 0; exit "$rc"; }
@kharandziuk
kharandziuk / 1.js
Created August 18, 2020 07:37
stream mess
const fs = require('fs')
const stream = require('stream')
const { promisify } = require('util')
const finished = promisify(stream.finished)
const handle = async (compare_object) => {
for (let [key, item] of Object.entries(compare_object)) {
var f = fs.createReadStream(item.local_path);
@kharandziuk
kharandziuk / factories.py
Created July 16, 2020 08:11
django aggregation query
import factory
from broschures import models
class BroschureFactory(factory.django.DjangoModelFactory):
class Meta:
model = models.Broschure
class BroschureClickFactory(factory.django.DjangoModelFactory):