Skip to content

Instantly share code, notes, and snippets.

View amatai's full-sized avatar

Ajay Matai amatai

View GitHub Profile
@amatai
amatai / mktmpenv.txt
Last active February 20, 2020 04:49
Python Temporary Virtualenv
$ mktmpenv -p `which python3.7`
Running virtualenv with interpreter /usr/bin/python3.7
Using base prefix '/usr'
/usr/lib/python3/dist-packages/virtualenv.py:1086: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
import imp
New python executable in /home/ajay/.virtualenvs/tmp-bf135004fa2bf83f/bin/python3.7
Also creating executable in /home/ajay/.virtualenvs/tmp-bf135004fa2bf83f/bin/python
Installing setuptools, pkg_resources, pip, wheel...done.
This is a temporary environment. It will be deleted when you run 'deactivate'.
(tmp-bf135004fa2bf83f) [~/.virtualenvs/tmp-bf135004fa2bf83f]$
db.things.aggregate([{$project: {arrayofkeyvalue: {$objectToArray: "$$ROOT"}}}, {$unwind:"$arrayofkeyvalue"}, {$group:{_id:null, allkeys:{$addToSet:"$arrayofkeyvalue.k"}}}])
@amatai
amatai / python_shutdown_asyncio.py
Last active March 17, 2021 21:05
Python asyncio: how to cleanly handle sighandlers and close all pending tasks
#!/usr/bin/env python3.6
import asyncio
import signal
async def taskX(task_name, loop):
while True:
try:
# simulate long running task
@amatai
amatai / kafka.md
Last active November 8, 2017 07:26
Kafka Commands

Run Kafka, ZK in container

docker run -d -p 2181:2181 --name zookeeper jplock/zookeeper
docker run -d -p 9092:9092 --name kafka --link zookeeper:zookeeper ches/kafka

List topics

./kafka-topics --zookeeper localhost:2181 --list

Console consumer in docker

# kafka, zk all running as containers

sudo docker run --rm --link zookeeper:zookeeper ches/kafka kafka-console-consumer.sh --topic audit --from-beginning --zookeeper zookeeper:2181

@amatai
amatai / ElasticSearch Useful Commands.md
Last active November 20, 2017 14:42
ElasticSearch

Cluster

  • Basic Cluster Info

curl http://localhost:9200/?pretty

  • Cluster status

curl http://localhost:9200/_cluster/health?pretty

  • List of nodes
@amatai
amatai / DDoS.md
Last active September 1, 2016 18:36
DDoS Mitigation Ideas

Layer 3 level

  • TCP vs UDP
  • Do we need any UDP at all ? NTP/DNS ?
  • Open Ports 443, 80, 25, 465, 587, 2525

Known Problem:

  • ELBs don't scale very fast. What happens during DDoS?

Mitigations by AWS

  1. Route53 monitors health of ELB instances and if it is fails because DDoS targetting particular instance, it will remove it from pool, good traffic continues.