Skip to content

Instantly share code, notes, and snippets.

@jsbain
jsbain / Audio.py
Created June 26, 2016 16:49
Audio.py
from objc_util import *
import ctypes
import numpy as np
import matplotlib.image
import io,ui
AVAudioEngine=ObjCClass('AVAudioEngine')
AVAudioSession=ObjCClass('AVAudioSession')
def setup():
error=ctypes.c_void_p(0)
session=AVAudioSession.sharedInstance()
@jsbain
jsbain / ScreenSimulator.py
Created June 27, 2016 17:11
ScreenSimulator.py
import ui
class Screen(ui.View):
def __init__(self,view):
scale=(min(ui.get_screen_size())-64)/1024.
self.view=view
self.add_subview(view)
self.transform=ui.Transform.scale(scale,scale)
rb=[]
for b in ['ipad','ipad_land','iphone','iphone_land']:
btn=ui.ButtonItem()
@jsbain
jsbain / ping.py
Created June 29, 2016 16:11
ping.py
#!/usr/bin/env python2
"""
A pure python ping implementation using raw socket.
Note that ICMP messages can only be sent from processes running as root.
Derived from ping.c distributed in Linux's netkit. That code is
@jsbain
jsbain / customtableviewcell.py
Created June 30, 2016 20:12
customtableviewcell.py
import ui
#necessary if we want to fool acustomTableViewCell into thinking it is a TableViewCell, mainly for allowing cls.method() type callbacks.
class MockTableCellType(type):
def __instancecheck__(self, other):
if other==ui.TableViewCell:
return True
class CustomTableViewCell(object):
__metaclass__=MockTableCellType
@jsbain
jsbain / customtableviewcell.py
Created June 30, 2016 20:25
customtableviewcell.py
import ui
class CustomTableViewCell(ui.View):
def as_cell(self):
c=ui.TableViewCell()
self.frame=c.content_view.bounds
self.flex='wh'
c.content_view.add_subview(self)
c.set_needs_display()
@jsbain
jsbain / autocomp.py
Created July 4, 2016 14:25
autocomp.py
def getattribstrings_fast(o):
A=[]
itstype=type(o)
for a in dir(o):
if hasattr(itstype,a):
if callable(getattr(itstype,a)):
A.append(a+'()')
else:
A.append(a)
else:
@jsbain
jsbain / poo_1.py
Created August 3, 2016 15:19
poo_1.py
import ui
view_str='''
[ { "class" : "View", "attributes" : {
"custom_class" : "moo",
"tint_color" : "RGBA(0.0,0.5,1.0,1.0)",
"border_color" : "RGBA(0.0,0.0,0.0,1.0)",
"flex" : "" },
"frame" : "{{0, 0}, {240, 240}}", "selected" : false,
@jsbain
jsbain / runme.py
Created August 18, 2016 01:57
savefile.py
print('ran it')
i=1
@jsbain
jsbain / savefile.py
Last active March 1, 2019 07:51
savefile.py
#coding: utf-8
import requests
import appex,console,time,os
unquote=requests.utils.unquote
urlparse=requests.utils.urlparse
url=appex.get_url()
p=urlparse(url)
urlfilename=unquote(unquote(urlparse(appex.get_url()).path.split('/')[-1]))
console.hud_alert('downloading '+urlfilename)
@jsbain
jsbain / Untitled_64.py
Created August 23, 2016 03:01
Untitled_64.py
import ui
from math import pi
v=ui.View(frame=(0,0,576,576))
v.bg_color=(1,1,1)
N=12
for i in range(0,N):
a=ui.Button(image=ui.Image.named('iob:arrow_up_a_256'))
a.height=a.width=64
a.center=v.bounds.center()
a.transform=ui.Transform.translation(0,-(v.height/2-a.height/2)).concat(