Skip to content

Instantly share code, notes, and snippets.

View btoueg's full-sized avatar

Benjamin Toueg btoueg

View GitHub Profile
@btoueg
btoueg / synthetics_test.yml
Last active March 22, 2019 07:28
Terraform draft
resource "datadog_synthetics" "foo" {
# Every attributes required to create a new Datadog synthetics test
name = "Name for synthetics foo"
type = "api"
message = "Synthetics test failed. Notify: @slack-channel"
options {
tick_every = 60
}
config {
request {
<?php
// Show all information, defaults to INFO_ALL
phpinfo();
?>
@btoueg
btoueg / main.py
Last active January 21, 2019 13:19
An example of asymmetric encryption in python 2.7 - utilizes cryptography library
# -*- encoding: utf-8 -*-
import base64
import logging
from cryptography.exceptions import UnsupportedAlgorithm
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives import serialization
from cryptography.hazmat.primitives.asymmetric import padding
@btoueg
btoueg / main.py
Last active February 24, 2023 07:30
An example of symmetric encryption in python 2.7 using a single known secret key - utilizes cryptography library
# -*- encoding: utf-8 -*-
import os
import base64
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
from cryptography.hazmat.backends import default_backend
backend = default_backend()
secret_key = base64.b64decode(
# generated randomly once, kept secret
@btoueg
btoueg / Readme.md
Last active April 20, 2018 08:28
Demonstration of throttling aiohttp with semaphore

I'm trying to achieve fine-grained throttling with aiohttp.

By fine-grained, I mean that controlling how many requests are simultaneously executed is not enough, I want to rate-limit the number of requests to match 100 requests per 10 seconds interval.

The interesting part resides in throttled_coroutine which acquires/releases a lock at a speed which is exactly the rate-limit I want to enforce by either:

  • waiting a delay once requests performing very quickly are completed
  • releasing lock before completion of requests performing poorly

At the end of a batch of requests, last coroutines tend to wait for no reason. This behaviour amplifies when timeout increases.

@btoueg
btoueg / sellsy.py
Created March 2, 2015 10:08
Sellsy API python with OAuth
# -*- coding: utf-8 -*-
import json
import requests
from requests_oauthlib import OAuth1
from oauthlib.oauth1 import SIGNATURE_PLAINTEXT, SIGNATURE_TYPE_BODY
consumer_token = '***'
consumer_secret = '***'
user_token = '***'