Skip to content

Instantly share code, notes, and snippets.

import turtle
from collections import namedtuple
from math import sin
from random import choice, randint as ri
import time
WIDTH_BASE = [1, 10]
WIDTH_PERIOD = [1, 100]
WIDTH_AMP = [0, 20]
from droidhelper import DroidHelper
import socket
import struct
import time
SMOOTH = 2
COEFF = 10000/20.0/SMOOTH
readings = [0] * SMOOTH
ind = 0
import os
def cat(f):
return open(f).read()
def ls():
return os.listdir('.')
def pwd():
return os.getcwd()
@Sorseg
Sorseg / problem.py
Created September 9, 2015 00:16
Mocking await calls in python 3.5 is a problem
async def some_coroutine():
await another_coroutine()
async def another_coroutine():
pass
#!/usr/bin/env python3
import wmi, time
def watch():
c=wmi.WMI()
pss = c.query("select WorkingSetSize from win32_Process"
" where Name='chrome.exe'")
killed = [p.Terminate(0) for p in pss if int(p.WorkingSetSize) > 1800*1e6]
import json
class DispatcherBase:
switch = 'what'
def __call__(self, act):
if not isinstance(act, dict):
act = json.loads(act)
what = act.pop(self.switch, None)
import os
import tkinter as tk
import random
from collections import namedtuple
WIDTH, HEIGHT = 300, 300
PROG = WIDTH//10
root = tk.Tk()
canvas = tk.Canvas(root, width=WIDTH, height=HEIGHT, bg='white')
img = tk.PhotoImage(width=WIDTH, height=HEIGHT)
""" Thanks to http://speakrus.ru/dict/ """
import random
f = open('pldf-win.txt', encoding='cp1251')
words = f.read().split('\n')
def gen():
message = ' '.join(random.choice(words) for _ in range(random.randint(2, 6)))
message = message[0].upper()+message[1:]
img = gimp.image_list()[0]
n = len(img.layers)
for i, l in enumerate(img.layers):
l.opacity = 100.0/(n-i)
from queue import Empty, Queue
import subprocess
import sys
import threading
if sys.version[0] > '2':
import tkinter
else:
import Tkinter as tkinter