Skip to content

Instantly share code, notes, and snippets.

View pidpawel's full-sized avatar

Paweł Kozubal pidpawel

View GitHub Profile
@pidpawel
pidpawel / redirected_stdout.py
Created December 7, 2016 18:04
Redirected stdout mock, mostly for testing purposes
import sys
import io
class RedirectedStdout:
def __init__(self):
self.old_stdout = sys.stdout
self.file = io.StringIO()
def __enter__(self):
@pidpawel
pidpawel / graphite_proxy.py
Created July 9, 2015 16:40
Supersimple proxy for graphite allowing to inject data without timestamp.
#!/usr/bin/env python2
from twisted.internet.protocol import Factory
from twisted.protocols.basic import LineReceiver
from twisted.internet import reactor
import socket
import time
class UplinkConnection:
def __init__(self, host, port):
#!/usr/bin/python3
from cffi import FFI
f = FFI()
@f.callback("int(int)")
def pytest(a):
return a*a
00:00
00:11
00:22
00:33
00:44
00:55
01:01
01:10
02:02
02:20
#!/usr/bin/python3
hour_lambdas = [
lambda h, m: h==m,
lambda h, m: len(set("%.2d%.2d" % (h,m))) == 1,
lambda h, m: "%.2d" % h == ("%.2d" % m)[::-1],
lambda h, m: h==13 and m==37,
lambda h, m: len(set("%.2d" % h)) == 1 and len(set("%.2d" % m)) == 1
]
#!/usr/bin/python3
import serial
import random
import re
printer = serial.Serial('/dev/ttyUSB0', 9200)
if not printer.isOpen():
printer.open()
#!/usr/bin/python2
import pylab as plt
import collections
import random
import time
import serial
maxsamples = 1000
Y1 = collections.deque([0] * maxsamples)
Y2 = collections.deque([0] * maxsamples)
TARGET=main
ADDITIONAL=
LIBS=src/startup_stm32f10x_md.o src/core_cm3.o src/system_stm32f10x.o
PERIPH=src/stm32f10x_adc.o src/stm32f10x_bkp.o src/stm32f10x_can.o src/stm32f10x_cec.o src/stm32f10x_crc.o src/stm32f10x_dac.o src/stm32f10x_dbgmcu.o src/stm32f10x_dma.o src/stm32f10x_exti.o src/stm32f10x_flash.o src/stm32f10x_fsmc.o src/stm32f10x_gpio.o src/stm32f10x_i2c.o src/stm32f10x_iwdg.o src/stm32f10x_pwr.o src/stm32f10x_rcc.o src/stm32f10x_rtc.o src/stm32f10x_sdio.o src/stm32f10x_spi.o src/stm32f10x_tim.o src/stm32f10x_usart.o src/stm32f10x_wwdg.o
OBJS=$(LIBS) $(PERIPH) $(ADDITIONAL) $(TARGET).o
LD_SCRIPT=misc/stm32_flash.ld
INCPATH=inc/
OPTIMIZE = O2
TARGET_CPU=cortex-m3
@pidpawel
pidpawel / gist:8133890
Created December 26, 2013 13:31
repeatable timer in python
def repeatable_timer(delay, func, args=[], kwargs={}):
func(*args, **kwargs)
t = Timer(delay, repeatable_timer, [delay, func, args, kwargs])
t.start()
def hello(ar):
print("Hello %s!" % ar)
repeatable_timer(1, hello, ["World"])