Skip to content

Instantly share code, notes, and snippets.

@kharandziuk
kharandziuk / terraform-presigned-url.tf
Created June 25, 2020 11:50
A hack to generate a presigned url in terraform
variable "bucket_name" {
default = "max-bucket-for-testing"
}
provider "aws" {
region = var.aws_region
profile = var.aws_profile
}
resource "aws_s3_bucket" "artifacts" {
@kharandziuk
kharandziuk / playbook.yml
Created January 20, 2017 15:43
ansible playbook for postgis
# -*- mode: yaml-*-
# vi: set ft=yaml sw=2 ts=2 :
- name: Configure scala study machine
hosts: all
sudo: True
vars:
pg_version: 9.4
pg_conf: "/etc/postgresql/{{ pg_version }}/main/postgresql.conf"
pg_hba: "/etc/postgresql/{{ pg_version }}/main/pg_hba.conf"
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 / article.md
Last active March 2, 2021 03:41
Node.js Streams and Reactive Programming Primer

This article shows how to apply Node.js Stream and a bit of Reactive programming to a real(tm) problem. The article is intended to be highly practical and oriented for an intermediate reader. I intentionally omit some basic explanations. If you miss something try to check the API documentation or its retelling(e.g.: this one)

So, lets start from the problem description. We need to implement a simple web scraper which grabs all the data from some REST API, process the data somehow and inserts into our Database. For simplicity, I omit the details about the actual database and REST API(in real life it was the API of some travel fare aggregator website and a Pg database)

Consider we have two functions(code of the IO simulator functions and the other article code is here):

getAPI(n, count) // pseudo API ca
@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)