Skip to content

Instantly share code, notes, and snippets.

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):
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)
@lega911
lega911 / example.py
Created August 30, 2018 01:48
run callback on stop loop
import asyncio
async def main():
print('start')
async def on_stop():
try:
await asyncio.sleep(10**10)
except asyncio.CancelledError:
pass
Type Trial 1 Trial 2 Trial 3
%: 0.273233943000 0.268914790000 0.273714235000
str.format(): 0.7942503730000681 0.793637686999773 0.7926878570001463
str.Template(): 3.3321329630002765 3.3256752329998562 3.315622544999769
f-string: 0.1914799450000828 0.18900782099990465 0.19004946999984895
7a8,9
> import hashlib
>
48a51
> self.lcache = {}
449c452
< return json.dumps({'id': identifier, 'results': _definitions})
---
> return json.dumps(_definitions)
560,565c563,584
{
# comments are useful
# specify rate in requests/second
"rate": 1000
// maybe you prefer js style comments
/* or if you feel old fashioned */
# key names do not need to be placed in quotes
key: "value"
class Connect(object):
def describe(self):
return some_code2(self)
def check(self):
r = self.describe()
return some_code3(self, r)
def find(self):
r = some_code1(self)
@lega911
lega911 / 0_result
Last active February 3, 2018 21:46
-O3
* C: 100% (~1.14sec)
* C++: 99.73%
* C++ exception: 84.6%
-O2
* C: 100% (~2.12sec)
* C++: 100.51%
* C++ exception: 74.02%
from sqlalchemy import *
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
engine = create_engine(connection_args)
metadata = MetaData(bind=engine)
class Tblname(Base):
__table__ = Table('tblname', metadata, autoload=True)