Skip to content

Instantly share code, notes, and snippets.

import redis
import time
import json
r = redis.Redis(host='localhost', port=6379, db=0)
for i in range(100):
print(i)
r.rpush('tasks', json.dumps({'task': i}))
time.sleep(0.5)
import redis
import time
import json
r = redis.Redis(host='localhost', port=6379, db=0)
for i in range(100):
print(i)
r.rpush('tasks', json.dumps({'task': i}))
time.sleep(0.5)
import threading
from ctypes import cdll
lib = cdll.LoadLibrary('./liblib.so')
class Foo(object):
def __init__(self):
self.obj = lib.Foo_new()
def bar(self):
load: 0.369427308000013
find: 0.03731154500019329
sample 1: ['6.19889798576753', '306.03317783754981', 'NCV']
sample 2: ['6.19889798576753', '306.03317783754981', 'NCV']
@lega911
lega911 / client_and_worker.py
Last active December 17, 2019 21:59
RPC example
# client.py
import requests
print(requests.post('http://127.0.0.1:8001/test/command', json={'id': 1, 'params': 'Hello'}).json())
# worker.py
import requests
while True:
req = requests.post('http://127.0.0.1:8001/test/command', headers={'Type': 'get'}).json()
response = {
'id': req['id'],
import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import java.io.IOException;
import java.util.UUID;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.TimeoutException;
@lega911
lega911 / xkb.symbols.se
Created October 30, 2019 11:15
keyboard layout se for ubuntu 19+
// file /usr/share/X11/xkb/symbols/se
partial alphanumeric_keys
xkb_symbols "se" {
name[Group1]="Swedish";
// tool: xev
// mapping key file: /usr/share/X11/xkb/keycodes/evdev
// reload conf: setxkbmap -layout se
// key <code> {[ default, +shift, +altGr, +shit +altgr ]};
words = ['abc', 'ubuntu', 'linux', 'ubuntu 16 LTS', 'redhat', 'unix', 'windows', 'macos X']
def tre(w):
w = w.lower()
r = {'__' + w[0], '_' + w[:2]}
for i in range(len(w)):
k = w[i:i+3]
while len(k) < 3:
k += '_'
r.add(k)
# xkbcomp 2.xkb $DISPLAY
# xkbcomp $DISPLAY - > init.2
# xmodmap
xkb_keymap {
xkb_keycodes {
include "evdev+aliases(qwerty)"
<LALT> = 108;
<RALT> = 64;
@lega911
lega911 / malina-app.html
Last active September 19, 2020 22:29
Small benchmark
<script>
let todos = [];
let duration = '';
function timeit(fn) {
let start = Date.now();
fn();
setTimeout(() => {
duration += ' + ' + (Date.now() - start);
}, 10);