Skip to content

Instantly share code, notes, and snippets.

@kived
kived / TPython.md
Last active July 3, 2018 10:42
TPython: IPython with a Twisted reactor

Run a Twisted reactor inside IPython.

  1. Copy twist.py to ~/.ipython/twist.py
  2. Copy tpython to ~/bin/tpython
  3. Make tpython executable: chmod +x ~/bin/tpython

You may need to add $HOME/bin to your path.

@kived
kived / sound.py
Last active August 29, 2015 14:02
kivy gstplayer socket leak test
from kivy.app import App
from kivy.uix.button import Button
from kivy.clock import Clock
from kivy.core.audio import SoundLoader
import time
import os
from subprocess import Popen, PIPE
class TestApp(App):
def __init__(self, **kwargs):
@kived
kived / inversecolor.py
Created June 25, 2014 17:29
calling gl functions
from kivy.uix.widget import Widget
from kivy.graphics import Callback
from kivy.graphics.opengl import glBlendFunc, GL_ONE_MINUS_DST_COLOR, GL_ZERO
class InverseColor(Widget):
def __init__(self, **kwargs):
super(InverseColor, self).__init__(**kwargs)
@kived
kived / x11.py
Created June 27, 2014 18:44
x11 reparenting
from Xlib import display, error
import pygame.display
def get_current_window():
wminfo = pygame.display.get_wm_info()
return wminfo.get('window', None)
def swallow(wid, x, y):
handler = error.CatchError()
@kived
kived / immersive.py
Created August 5, 2014 20:37
make immersive (py4a)
from android.runnable import run_on_ui_thread
from jnius import autoclass
mActivity = autoclass('org.renpy.android.PythonActivity').mActivity
View = autoclass('android.view.View')
@run_on_ui_thread
def make_immersive():
view = mActivity.getWindow().getDecorView()
view.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
@kived
kived / intents.xml
Created August 5, 2014 22:15
py4a intents
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.HOME" />
</intent-filter>
Window.bind(on_touch_down=self._on_window_touch_down)
def _on_window_touch_down(self, win, touch):
if self.collide_point(*touch.pos):
return
if any(child.collide_point(*touch.pos) for child in self.children):
return
self._hide_handles()
@kived
kived / scatterdemo.py
Created August 7, 2014 21:44
scatter
import kivy
kivy.require('1.8.0')
from kivy.app import App
from kivy.lang import Builder
root = Builder.load_string('''
BoxLayout:
orientation: 'vertical'
Label:
@kived
kived / closed.py
Created August 14, 2014 19:03
closing fds
import os, sys
sys.stdin.close()
sys.stdout.close()
sys.stderr.close()
os.close(0)
os.close(1)
os.close(2)
import kivy
kivy.require('1.8.1')
@kived
kived / reopen.py
Created August 14, 2014 19:14
reopen fds
import os, sys
sys.stdin.close()
sys.stdout.close()
sys.stderr.close()
os.close(0)
os.close(1)
os.close(2)
sys.stdin = open('/dev/null', 'r')
sys.stdout = open('/dev/null', 'w')