Skip to content

Instantly share code, notes, and snippets.

View jomido's full-sized avatar
🎯
Focusing

Jonathan Dobson jomido

🎯
Focusing
View GitHub Profile
@jomido
jomido / main.py
Last active December 27, 2017 16:11
asyncio pools (threaded and subprocessed)
import asyncio
import time
from pools import threads, processes
in_thread = threads(10)
in_process = processes(4)
def fib(n):
@jomido
jomido / README.md
Last active July 6, 2017 20:29
Requests Google TaskQueue Insert (& auth via service file)

Do: pip install -r requirements.txt Do: python taskqueue.py

You will need a service file. Amend the location in the entry point in taskqueue.py.

@jomido
jomido / README.md
Created July 19, 2017 14:44
Messing About with Elasticsearch (in Python)
@jomido
jomido / doit.sh
Created September 19, 2017 13:56
Docker on Debian 9
apt-get update
apt-get install -y \
apt-transport-https \
ca-certificates \
curl \
gnupg2 \
software-properties-common
curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add -
@jomido
jomido / README.md
Last active October 13, 2017 16:41
Dedupe and limit HTTP request with NGINX

NGINX conf:

# limit_req_zone   $request_uri zone=per_uri_2s:10m rate=30r/m;
limit_req_zone $limit_post zone=per_uri:10m rate=30r/m;
limit_req_status 429;

location ~ ^/v\d+/tasks/.*/claim$ {
 limit_req zone=per_uri_2s;
 [...]
@jomido
jomido / gcloud-script-box.sh
Created October 13, 2017 14:52
Idempotent Gcloud Compute Create
#!/bin/bash
# BEGIN SANITY BOX------------------------------------------
set -e # immediately exit if any command fails |
set -u # immediately fail on undefined variables |
set -o pipefail # show error of last failed command |
IFS=$'\n\t' # control what word splitting means |
# END SANITY BOX--------------------------------------------
# delete
@jomido
jomido / index.js
Created January 31, 2018 20:46
Node Blocking Readline
// THIS WILL NOT WORK UNTIL NODE implements `Atomics` :) Soon?
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
function msleep(n) {
@jomido
jomido / timeit.js
Created May 5, 2020 15:25
v8 ser/deser vs "parsify"
const v8 = require('v8')
const iterations = 1000
const getData = () => {
// return a large data blob
return [
{
@jomido
jomido / fnf.py
Last active November 19, 2021 13:12
# fire-n-forget
#
# https://bugs.python.org/issue44665
# https://bugs.python.org/issue42538
import asyncio
import functools
running_tasks = set()
@jomido
jomido / solution.py
Last active July 12, 2022 16:42
CodeSignal: Descending/Ascending Towers
cases = [
([], 0),
([10], 0),
([1, 2, 3, 4], 0),
([1, 1, 1, 1], 6),
([1, 3, 2, 1], 3),
([1, 7, 1, 4], 13),
]