Skip to content

Instantly share code, notes, and snippets.

View singulared's full-sized avatar
💭
🐧

Maxim Belousov singulared

💭
🐧
View GitHub Profile
@singulared
singulared / lpt.py
Created December 11, 2017 17:26
loop per thread
import threading
import asyncio
async def task(count, stime):
await asyncio.sleep(stime)
print('%s: %s' % (threading.current_thread().name, count), flush=True)
def multi_event_loops():
import asyncio
from asyncio.futures import Future
loop = asyncio.get_event_loop()
async def wait_for_result(fut):
await asyncio.sleep(5)
fut.set_result('result')

Keybase proof

I hereby claim:

  • I am singulared on github.
  • I am singulared (https://keybase.io/singulared) on keybase.
  • I have a public key ASDxSxS7kYVUvh4uwdGUrXTRYJpMBAndotgJ7TV8AgY9ogo

To claim this, I am signing this object:

Метапрограммирование

В одной из начальных лекций мы говорили о том, что в языке Python всё является объектом. Настало время разобраться в этом чуть глубже.

Для начала давайте посмотрим действительно ли в Python всё является объектом и самое важное, объектами каких классов.

uwsgi:
http: 0.0.0.0:8000
wsgi-file: /data/www/flask/wsgi.py
callable: app
pidfile: uwsgi.pid
processes: 2
master: 1
workers: 2
auto-procname: 1
daemonize: uwsgi.log
@singulared
singulared / Item.py
Last active September 15, 2015 16:04
class Item(models.Model):
name = models.CharField(max_length=255)
def get_options(self):
topics = {}
for item_option in ItemOption.objects.select_related().all():
option = item_option.option
topic = option.topic
if topic not in topics:
from telnetlib import Telnet
from caesarcipher import CaesarCipher
tn = Telnet('54.209.5.48', 12345)
tn.read_until(b'psifer text: ')
psifer = tn.read_until(b'\n').decode().strip()
cipher = CaesarCipher(psifer)
message = cipher.cracked
print('Cracked:', message)
tn.write(message.split()[-1].encode() + b'\n')
@singulared
singulared / 99-mali-devices.rules
Created March 28, 2013 11:18
Set /dev/mali* permission to mali group from udev.
# From /etc/udev/rules.d/99-mali-devices.rules
# Graphic devices
KERNEL=="mali*" OWNER="root" GROUP="mali" MODE="0660"
@singulared
singulared / gist:5204314
Created March 20, 2013 12:33
Chromium build for armhf
SYSROOT="/opt/qemu/chroot/armhf"
CFLAGS=$CFLAGS" -I${SYSROOT}/usr/include -I${SYSROOT}/usr/include/arm-linux-gnueabihf"
CXXFLAGS=$CXXFLAGS" -I${SYSROOT}/usr/include -I${SYSROOT}/usr/include/arm-linux-gnueabihf -L${SYSROOT}/usr/lib/arm-linux-gnueabihf"
LDFLAGS=$LDFLAGS" -L${SYSROOT}/usr/lib/arm-linux-gnueabihf"
export -n CFLAGS CXXFLAGS LDFLAGS
GYP_DEFINES="\
sysroot=${SYSROOT} \
werror= \