Skip to content

Instantly share code, notes, and snippets.

View rrader's full-sized avatar
🐧

Roman Rader rrader

🐧
View GitHub Profile
@rrader
rrader / parrots.py
Created April 4, 2019 10:25
TextToParrots
# https://stackoverflow.com/questions/36384353/generate-pixel-matrices-from-characters-in-string
# FONT: https://fontstruct.com/fontstructions/show/1404190/cg-pixel-4x5-1
from PIL import Image
from PIL import ImageFont
from PIL import ImageDraw
import numpy as np
def char_to_pixels(text, path, fontsize):
font = ImageFont.truetype(path, fontsize)
@rrader
rrader / requests_files.py
Created September 20, 2017 09:40
Test open files on requests
import psutil
import requests
def open_files():
proc = psutil.Process()
return proc.open_files()
print 'on start:', open_files()
# coding: utf8
def dijkstra_shortest_path(graph, start, paths={}, visited=[]):
if len(paths) == 0:
paths[start] = {'dist': 0, 'parent': None} # инициализация начального пути
# print "start V: %d, " % (start)
for x in graph[start]:
if (x not in visited and x != start):
if (x not in paths.keys() or (graph[start][x] + paths[start]['dist']) < paths[x]['dist']):
paths.setdefault(x, {'dist': 0, 'parent': None})
paths[x]['dist'] = graph[start][x] + paths[start]['dist']
from rx import Observable, AnonymousObservable
from rx.concurrency import current_thread_scheduler
from rx.internal import extensionclassmethod
@extensionclassmethod(Observable)
def from_iterable_with_interval(cls, period, iterable, scheduler=None):
"""Creates an Observable that polls iterator made from iterable every period millis."""
iterator = iter(iterable)
return Observable.interval(period, scheduler=scheduler).map(lambda v: next(iterator))
@rrader
rrader / generate.py
Created August 17, 2015 13:15
Use DjangoTemplates with custom loader independently of settings.py
engine = DjangoTemplates(
{
'NAME': 'mail',
'APP_DIRS': False,
'DIRS': [],
'OPTIONS': {
'loaders': [
'events.loaders.MyLoader',
],
},
@rrader
rrader / static_jsx.md
Last active August 29, 2015 14:24
Static content serving via aiohttp for development purposes with JSX support

Default aiohttp static handler doesn't support any modification on the fly.

This handler helps to serve static files from directory ./static as is and convert JSX for ReactJS if needed.

import asyncio
import logging
from aiohttp import web
import os
@rrader
rrader / 0_reuse_code.js
Last active August 29, 2015 14:24
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@rrader
rrader / repro.py
Created May 10, 2015 15:33
issue24156
import socket, threading
host = "127.0.0.2"
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_TCP)
remote, peer = None, None
server.bind((host, 0))
server_addr = server.getsockname()
@rrader
rrader / gist:6baf0f4afd532c59fe11
Created August 12, 2014 11:57
Calling super in mixins
class A(object):
def m(self):
print 'A1'
try:
super(A, self).m()
except AttributeError:
print 'A has no super.m()!'
print 'A2'
class B(object):
@rrader
rrader / gist:7974784
Created December 15, 2013 16:08
example vhdl state machine
LIBRARY ieee;
USE ieee.std_logic_1164.all;
LIBRARY work;
ENTITY Custom_FSM IS
PORT
(
clk : IN STD_LOGIC;
init : IN STD_LOGIC;