Skip to content

Instantly share code, notes, and snippets.

View telendt's full-sized avatar
🔧
solving one problem at a time

Tomasz Elendt telendt

🔧
solving one problem at a time
View GitHub Profile
@telendt
telendt / iterators-benchmark
Last active April 25, 2017 19:37
Iterators benchmark
$ go test -bench=.
BenchmarkIterIndex-4 3000 478589 ns/op
BenchmarkIterIndexNoPanic-4 3000 469209 ns/op
BenchmarkIterSlice-4 2000 664497 ns/op
PASS
ok _/private/tmp/slice 5.353s
@telendt
telendt / merge_two.py
Created April 24, 2017 10:12
Merging iterators (coroutine)
def merge_two(i: Iterator[T], j: Iterator[T]) -> Iterator[T]:
"""
>>> list(merge_two(iter([1, 2, 4]), iter([0, 1, 3, 4])))
[0, 1, 1, 2, 3, 4, 4]
"""
try:
x = next(i)
except StopIteration:
yield from j
return
@telendt
telendt / uniq.py
Created March 22, 2017 13:56
Sliding window uniq...
#!/usr/bin/env python
import collections
import sys
MAX_SIZE = 50
if __name__ == '__main__':
d = collections.OrderedDict()
@telendt
telendt / hot_threads_1.txt
Last active April 5, 2017 09:15
ES hot threads
::: {Baphomet}{bTq1hGDTQy-AJpWTjTpVbw}{OBFUSCATED}{OBFUSCATED:9300}{rack_id=k13}
Hot threads at 2016-09-24T14:27:12.584Z, interval=10s, busiestThreads=3, ignoreIdleThreads=true:
19.8% (1.9s out of 10s) cpu usage by thread 'elasticsearch[Baphomet][search][T#15]'
2/10 snapshots sharing following 38 elements
org.apache.lucene.index.TermContext.build(TermContext.java:94)
org.apache.lucene.search.TermQuery.createWeight(TermQuery.java:192)
org.apache.lucene.search.IndexSearcher.createWeight(IndexSearcher.java:904)
org.apache.lucene.search.BooleanWeight.<init>(BooleanWeight.java:57)
org.apache.lucene.search.BooleanQuery.createWeight(BooleanQuery.java:239)
@telendt
telendt / common_query_1.json
Created September 21, 2016 12:43
ES queries
{
"bool": {
"must": {
"dis_max": {
"queries": [
{
"match": {
"common": {
"query": "USER_QUERY",
"type": "boolean",
@telendt
telendt / output.txt
Last active December 7, 2015 13:47
Serializable
{
"b": {
"param": "yello!"
},
"a": "test"
}
@telendt
telendt / cycle.go
Last active August 29, 2015 14:21
Iterator
package main
import (
"fmt"
"sync/atomic"
"unsafe"
)
type Iterator interface {
Next() string
@telendt
telendt / solution.py
Last active October 26, 2015 23:47
Crypto Puzzle
$ python3 solution.py
AMAZON ECHO IS DESIGNED AROUND YOUR
VOICE. IT'S ALWAYS ON - JUST ASK FOR
INFORMATION, MUSIC, NEWS, WEATHER, AND
MORE. ECHO BEGINS WORKING AS SOON AS IT
DETECTS THE WAKE WORD. YOU CAN PICK
ALEXA OR AMAZON AS YOUR WAKE WORD. ECHO
IS ALSO AN EXPERTLY TUNED SPEAKER THAT
CAN FILL ANY ROOM WITH IMMERSIVE SOUND.
PLEASE VISIT WWW.AMAZON.COM/ECHO IF YOU
@telendt
telendt / test_server.py
Last active December 29, 2015 21:49
aiohttp pipelining
$ time echo 'GET /first?delay=1 HTTP/1.1
Host: localhost:8080
Connection: keep-alive
GET /last?delay=1 HTTP/1.1
Host: localhost:8080
Connection: close
' | unix2dos | nc localhost 8080 > /dev/null
real 0m2.018s
#!/usr/bin/env python
"""Simple static server written using an event loop."""
import argparse
import contextlib
import errno
import functools
import logging
import mimetypes
import os