Skip to content

Instantly share code, notes, and snippets.

@jsbain
jsbain / SearchableTable.py
Created December 17, 2017 06:35
objc_classes.py
import ui
from ctypes import py_object
from objc_util import *
import sys
from objc_classes import objcmethod, objcclass
UISearchController=ObjCClass('UISearchController')
class SearchableTableView(ui.View):
'''Works like a tableview, except that search bar is shown.
@jsbain
jsbain / finalizertest.py
Created October 31, 2017 05:27
finalizer
import weakref
class Self_Closing_Automatic(type):
def __call__(cls, *args, **kwargs):
''' called when you call MyClass()
Create the object, then add a weakref finalizer'''
obj = type.__call__(cls, *args, **kwargs)
''' get list of all attribs that have `close`'''
close_list = [getattr(obj,a) for a in dir(obj) if hasattr(getattr(obj,a),'close') and not isinstance(getattr(obj,a),type)]
''' This sort of depends on the close convention... maybe a
@jsbain
jsbain / Untitled_146.py
Created September 28, 2017 04:46
Untitled_146.py
from __future__ import absolute_import
from __future__ import print_function
import requests, urllib.parse
import time,datetime
from six.moves import range
class Quote(object):
DATE_FMT = '%Y-%m-%d'
TIME_FMT = '%H:%M:%S'
@jsbain
jsbain / Untitled_155.py
Created September 22, 2017 15:32
Untitled_155.py
from ctypes import *
COMPRESSION_LZMA = 0x306
c=CDLL(None)
def encode(instr):
outbuf = create_string_buffer(max(32767,len(instr)))
inbuf = create_string_buffer(len(instr))
insz=len(instr)
@jsbain
jsbain / sage_interface.py
Created September 8, 2017 18:09
sage_interface.py
#!python2
"""
A small client illustrating how to interact with the Sage Cell Server, version 2
Requires the websocket-client package: http://pypi.python.org/pypi/websocket-client
"""
import websocket
import json
@jsbain
jsbain / sage.py
Created September 8, 2017 16:43
sage.py
#!python2
"""
A small client illustrating how to interact with the Sage Cell Server, version 2
Requires the websocket-client package: http://pypi.python.org/pypi/websocket-client
"""
import websocket
import json
@jsbain
jsbain / avplayer.py
Created September 2, 2017 10:49
avplayer.py
'''
minimal avplayer example
'''
from objc_util import *
AVPlayerItem=ObjCClass('AVPlayerItem')
AVPlayer=ObjCClass('AVPlayer')
AVPlayerLayer=ObjCClass('AVPlayerLayer')
import photos
def pick_asset():
assets = photos.get_assets(media_type='video')
@jsbain
jsbain / library_browser.py
Created August 26, 2017 17:15
library_browser.py
import sys,re, mmap
'''static libs/syms
with open(sys.executable,'rb') as f:
m=mmap.mmap(f.fileno(),0, access=mmap.ACCESS_READ)
symbols=re.findall(b'@_(\w*)',m)
with open(sys.executable,'rb') as f:
m=mmap.mmap(f.fileno(),0, access=mmap.ACCESS_READ)
frameworks=re.findall(b'(/Sys[\w/\.]*\.framework)',m)
@jsbain
jsbain / Untitled_146.py
Created July 22, 2017 06:41
Untitled_146.py
from __future__ import absolute_import
from __future__ import print_function
import urllib.request, urllib.parse
import time,datetime
from six.moves import range
class Quote(object):
DATE_FMT = '%Y-%m-%d'
TIME_FMT = '%H:%M:%S'
@jsbain
jsbain / objc_location.py
Created April 23, 2017 14:54
objc_location.py
from objc_util import *
from threading import Thread, Condition, Event, current_thread,enumerate
m=ObjCClass('CLLocationManager').sharedManager()
class Location():
def __init__(self,cllocation):
self.altitude=cllocation.altitude()
self.lat=cllocation.coordinate().a
self.lon=cllocation.coordinate().b