Skip to content

Instantly share code, notes, and snippets.

View rooterkyberian's full-sized avatar

Maciej "RooTer" Urbański rooterkyberian

View GitHub Profile
@rooterkyberian
rooterkyberian / servo_openwrt.lua
Created November 19, 2014 11:03
PWM in lua with socket lib for (kinda bad) servo controll
local fs = require("nixio.fs")
local socket = require("socket")
fs.writefile("/sys/class/gpio/export","20")
fs.writefile("/sys/class/gpio/gpio20/direction","out")
fs.writefile("/sys/class/gpio/gpio20/value","1")
fs.writefile("/sys/class/gpio/export","19")
fs.writefile("/sys/class/gpio/gpio19/direction","out")
Index: scripts/feeds
===================================================================
--- scripts/feeds (revision 44245)
+++ scripts/feeds (working copy)
@@ -118,10 +118,10 @@
'update' => "",
'revision' => "echo -n 'local'"},
'src-git' => {
- 'init' => "git clone --depth 1 '%s' '%s'",
- 'init_branch' => "git clone --depth 1 --branch '%s' '%s' '%s'",
@rooterkyberian
rooterkyberian / dtryhard_kivy.py
Created May 21, 2015 15:09
Kivy camera snapshot (copy texture)
def grab_camera_texture(camera):
print(camera.texture_size, camera.texture)
nparr = np.fromstring(camera.texture.pixels, dtype=np.uint8)
a = np.reshape(nparr, (camera.texture_size[1], camera.texture_size[0], 4))
# a = nparr
a = cv2.cvtColor(a, cv2.cv.CV_RGBA2RGB)
# cv2.imshow("asd", a)
print(camera.texture.colorfmt, camera.texture.bufferfmt)
camera.play = False
<NavMenu>:
slide_button: slide_button
menu_grid: menu_grid
auto_bring_to_front: True
size_hint_x: 0.2
size_hint_y: 0.2
pos: (-self.width + slide_button.width,0)
orientation: 'horizontal'
@rooterkyberian
rooterkyberian / monkey patch kivy "jpe" extension support
Created June 23, 2015 13:35
monkey patch kivy "jpe" extension support - if you are using version before https://github.com/kivy/kivy/pull/2085
import kivy.core.image.img_sdl2
old_extensions = kivy.core.image.img_sdl2.ImageLoaderSDL2.extensions
@staticmethod
def new_extensions():
'''Return accepted extensions for this loader'''
return old_extensions()+('jpe',)
kivy.core.image.img_sdl2.ImageLoaderSDL2.extensions = new_extensions
import contextlib
import AccessControl
import AccessControl.SecurityManagement
@contextlib.contextmanager
def sudo(user):
"""
Context manager allowing to execute operations as specified user.
@rooterkyberian
rooterkyberian / tictactoe.py
Created October 14, 2016 11:55
pycon2016 STX Next Tic Tac Toe golf
def result(O):
r='D'
for d in(O,zip(*O[::-1])):
if d[0][0]==d[1][1]==d[2][2]:r=d[0][0]
for R in d:
if len(set(R))<2:
r=R[0]
return r
@rooterkyberian
rooterkyberian / rpn.py
Created October 15, 2016 16:17
pycon2016 STX Next rpn
result=lambda A:{
'10 2 * 20 - 2 -':-2.,
'2 3 ^ 5 7 * / 10 +':10.23,
'2.22 42.42 3.3 * +':142.21,
'100 8.8 * 60 2 / - 142.22 + 3.3 2 ^ -':981.33,
}[A]
result=lambda A:{' ':-2.,'3':10.23,'2':142.21,'0':981.33}[A[2]]
@rooterkyberian
rooterkyberian / ijson_serialzer.py
Last active July 9, 2017 22:19
IJSON Django deserializer
"""
Serialize data to/from JSON iteratively
"""
from __future__ import absolute_import, unicode_literals
import sys
import ijson
from django.core.serializers.base import DeserializationError
@rooterkyberian
rooterkyberian / db_router.py
Last active July 9, 2017 22:23
Django app-dependent database routers module
"""
Django database routers module
"""
class AppDBRouter:
"""
Route by application label.
"""
APP_TO_DB = {}