Skip to content

Instantly share code, notes, and snippets.

Tarek Ziade tarekziade

View GitHub Profile
tarekziade / mutation.js
Created Mar 21, 2018
Demonstrates how to detect when a button gets enabled
View mutation.js
/* Like for the IntersectionObserver, we're using here the
* Mutation observer to detect when an element attribute is changed
* by some Javascript on the page.
* use case: a button is enabled
function watchMutation(selector, condition) {
var target = document.querySelector(selector);
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
import functools
import logging
import graypy
import json
import time
import random
from collections import defaultdict, deque
from flask import Flask, jsonify, g
app = Flask(__name__)
tarekziade /
Last active Apr 8, 2017
async marionette calls
# see
import functools
import json
from asyncio import open_connection
import asyncio
from molotov import *
class Marionette(object):
def __init__(self, host='localhost', port=2828, loop=None):
tarekziade /
Last active Apr 5, 2017
poutine test
import asyncio
import configparser
import pytest
from smwogger import API
def conf():
config = configparser.ConfigParser()'manifest.ini')
import asyncio
from smwogger import API
async def run_heartbeat():
async with API('__api__.json') as api:
res = await api.__heartbeat__()
body = await res.json()
tarekziade /
Created Mar 18, 2017
White list any 302 locations
from flask import make_response
from urllib.parse import urlparse
# domain:port
def check_redirect(response):
if response.status_code != 302:
tarekziade /
Last active Aug 1, 2018
connexion as an extension
import pathlib
from connexion.api import Api, Resolver
import werkzeug.exceptions
def swagger_blueprint(specification, specification_dir=None, validate_responses=False,
strict_validation=False, resolver_error=None,
base_path='', debug=False):
resolver = Resolver()
swagger_json = False
tarekziade /
Created Jan 9, 2017
Async Workers using Threads
import requests
import asyncio
import sys
from functools import partial
from concurrent.futures import ThreadPoolExecutor
from contextlib import contextmanager
loop = asyncio.get_event_loop()
tarekziade / detect.rst
Created Oct 14, 2016
Detect and kill an idling loads ec2 instance
View detect.rst

On the EC2 instance A few variable to set:

Run a docker with the docker sock linked and a few variables set:

docker run -t -v /var/run/docker.sock:/run/docker.sock -v $(which docker):/bin/docker  -i ubuntu /bin/bash
apt-get update && apt-get install -y python-pip && pip install docker-py==1.6.0

export CID=`cat /proc/self/cgroup | grep -o  -e "docker-.*.scope" | head -n 1 | sed "s/docker-\(.*\).scope/\\1/"`
tarekziade /
Last active Jun 4, 2016
Consistent Distribution of users across servers
""" Consistent load-balancing.
We have a few servers and we want a load-balancer to
distribute incoming requests across them in a deterministic
and consistent way - without keeping any counter to make the
Removing a backend server should not impact users on other
You can’t perform that action at this time.