Skip to content

Instantly share code, notes, and snippets.

View komuw's full-sized avatar

Komu Wairagu komuw

View GitHub Profile
@komuw
komuw / compression.py
Created June 27, 2018 07:26
different compression sizes
# pre-requistes:
# pip install brotli ; from https://github.com/google/brotli/tree/master/python
# pip install zstandard ; from https://github.com/indygreg/python-zstandard
# pip install python-lzo ; from https://github.com/jd-boyd/python-lzo
# zlib is in the python stdlib
import json
import zlib
import brotli
import zstandard
@komuw
komuw / Golang_PR.md
Last active October 18, 2018 11:20
create PR to a golang project
@komuw
komuw / goproxy.py
Last active April 9, 2022 20:31
Go module proxy implemented in python/django
import json
from django.http import HttpResponse
class Modules(APIView):
"""
For documentation, see; https://github.com/golang/go/blob/master/src/cmd/go/internal/modfetch/proxy.go
call this like;
sudo rm -rf ~/go/src/mod/ && \
export GOPROXY=http://localhost:4000 && \
@komuw
komuw / lambda.py
Created September 26, 2018 16:03
lambda shim
import subprocess
import json
proc = subprocess.Popen(['./main'],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
universal_newlines=True,
bufsize=1)
def id_generator():
@komuw
komuw / leak_detector.go
Last active February 19, 2020 09:27
A Goroutines leak detector
package main
// or just use:
// 1. https://github.com/uber-go/goleak
// 2. github.com/cockroachdb/cockroach/pkg/util/leaktest
import (
// "bytes"
"fmt"
"os"
@komuw
komuw / python_named_pipe.py
Created November 1, 2018 15:23
python named pipe
import os
import errno
import time
"""
The linux pipe buffers are implemnted as circular buffers[1].
A consequence of the circular buffer is that when it is full and a subsequent write is performed:
(a) then it starts overwriting the oldest data[2].
(b) Alternatively, the routines that manage the buffer could prevent overwriting the data and return an error or raise an exception.
@komuw
komuw / blocking_async.py
Created November 25, 2018 06:39
calling blocking code in async code
import asyncio
import requests
import concurrent
import functools
loop = asyncio.get_event_loop()
def reqq(timeout):
@komuw
komuw / client.go
Last active January 4, 2019 14:13
client and server odd behaviour
package main
import (
"bytes"
"io"
"log"
"net"
"time"
)
@komuw
komuw / iterable.py
Created March 22, 2019 15:59
convert list to iterable
import asyncio
import collections
class Iterable:
def __init__(self, my_list):
self.pool = collections.deque(my_list, maxlen=None)
self.len = len(self.pool)
self.index = 0