Skip to content

Instantly share code, notes, and snippets.

@kireal
kireal / scale_with_coroutine.py
Last active August 24, 2021 21:48
Scale up AWS calls with coroutines
# import goes here
# client that runs ecs task
def call_ecs_task(ecs_client, payload):
results = ecs_client.run_task()
pass
# client that runs lambda task
@kireal
kireal / lambda_ecs.py
Last active August 23, 2021 20:55
Lambda import in ecs container
# import goes here
def lambda_handler(event, context):
# lambda code goes here
pass
if __name__ == '__main__': # in case if we run it in a container
if 'EVENT' not in os.environ:
raise Exception('No event provided in os.environ.')
else:
@kireal
kireal / odbcinst.ini
Created October 26, 2016 02:41
Enable ODBC trace
[ODBC]
Trace=1
ForceTrace=1
TraceFile=/tmp/Trace.txt
TraceLibrary=libodbctrac.so
@kireal
kireal / env_sas.sas
Created October 14, 2016 16:58
Get env from macro
%let LD_LIBRARY_PATH =%sysget(LD_LIBRARY_PATH);
%put LD_LIBRARY_PATH is &LD_LIBRARY_PATH;
%let ODBCINST =%sysget(ODBCINST);
%put ODBCINST is &ODBCINST;
@kireal
kireal / git_restore.sh
Created October 13, 2016 18:42
Git restore deleted files
git rev-list -n 1 HEAD -- <file_path>
git checkout <deleting_commit>^ -- <file_path>
@kireal
kireal / deduplication_mongod.py
Last active February 12, 2018 18:43
Run to deduplicate mongodb collection
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Deduplication collection mongodb database utility.
#
# Works only with pymongo >= 3.0
# Kireal
#
# 01.10.2016
# Last change: 04.10.2016
@kireal
kireal / docker_outbound
Created August 27, 2016 05:45
Docker outbound connection
The FORWARD chain does need policy set to ACCEPT if you have --iptables=false. It only appears this is not needed because the Docker installation package auto starts Docker and adds iptable rules the FORWARD chain. When afterwards you add --iptables=false to your config and restart docker those rules are still there. After the next reboot these rules will be gone and your containers wont be able to communicate unless you have the FORWARD chain policy set to ACCEPT.
What you need for a setup that allows filtering with UFW, inter container networking and outbound connectivity is
start docker with --iptables=false
FORWARD chain policy set to ACCEPT
add the following NAT rule:
iptables -t nat -A POSTROUTING ! -o docker0 -s 172.17.0.0/16 -j MASQUERADE
@kireal
kireal / googleplay
Created August 20, 2016 19:47
Google play change country
Инструкция от саппорта гугла для возвращению русского маркета:
1) Войдите в свой ​​аккаунт Google Wallet для управления способами оплаты ( wallet.google.com/manage/paymentMethods )
2) Добавить новую карту или изменить настройки по умолчанию платежного инструмента на один с платежный адрес находится внутри желаемую страну
3) Откройте Play магазин и перейдите к любому элементу доступна для загрузки
4) Нажмите, чтобы начать загрузку, пока не достигнете «Принять и купить» экран (нет необходимости для завершения покупки)
5) Закройте магазин Play и ясные данные для магазина Google Play приложений (настройки> приложения> Google Play магазин> Удалить данные) или очистить кэш браузера
6) Re-Play открыть магазин. Теперь вы должны увидеть Play магазина, который соответствует вашей стране биллинга оплаты по умолчанию инструмента.
@kireal
kireal / ufw_docker
Last active June 6, 2021 22:29
ufw docker
Running Docker behind the ufw firewall
Ubuntu ships with a very nice and simple frontend for iptables called ufw (uncomplicated firewall). Ufw makes it possible to setup a firewall without having to fully understand iptables itself. When you however are using Docker and you want to combine Docker with the ufw service. Things do get complicated.
The docker service talks directly to iptables for networking, basically bypassing everything that’s getting setup in the ufw utility and therefore ignoring the firewall. Additional configuration is required to prevent this behavior. The official Docker documentation however, seems to be incomplete.
Configure DEFAULT_FORWARD_POLICY and port 2375
Connections from docker containers get routed into the (iptables) FORWARD chain, this needs to be configured to allow connections through it. The default is to DROP the connections so a change is required:
@kireal
kireal / enable_ufw.sh
Created August 15, 2016 02:14
Reenable ufw (iptables errors)
#!/bin/sh
sudo ufw disable
sudo iptables -F ufw-caps-test
sudo iptables -X ufw-caps-test
sudo iptables -Z ufw-caps-test
sudo ufw enable