Skip to content

Instantly share code, notes, and snippets.

@omz
omz / Audio Recorder.py
Created February 3, 2015 00:07
Audio Recorder.py
from ctypes import c_void_p, c_char_p, c_double, c_float, c_int, cdll, util, c_bool
import os
import time
# Load Objective-C runtime:
objc = cdll.LoadLibrary(util.find_library('objc'))
objc.sel_getName.restype = c_char_p
objc.sel_getName.argtypes = [c_void_p]
objc.sel_registerName.restype = c_void_p
objc.sel_registerName.argtypes = [c_char_p]
@omz
omz / Color picker.py
Created February 7, 2015 03:23
Color picker.py
import ui
from random import randint
import console
import clipboard
# Generate some random hex colors:
colors = ['#%X%X%X' % (randint(0,255), randint(0,255), randint(0,255)) for i in xrange(25)]
def tapped(sender):
r, g, b, a = sender.background_color
hex_color = '#%X%X%X' % (int(r*255), int(g*255), int(b*255))
@omz
omz / PythonistaBackup.py
Last active January 6, 2024 05:44
PythonistaBackup.py
# coding: utf-8
'''Creates a zip archive of your Pythonista files and serves them via HTTP in your local network.'''
import sys
if sys.version_info[0] >= 3:
from http.server import SimpleHTTPRequestHandler, HTTPServer
else:
from SimpleHTTPServer import SimpleHTTPRequestHandler
from BaseHTTPServer import HTTPServer
@omz
omz / DispatchGroupMail.py
Created April 23, 2015 17:09
DispatchGroupMail.py
# coding: utf-8
# Starting point for emailing a group of people via Dispatch...
# The people in the group are identified by a unique string in the Notes field.
# TODO: Support setting the group identifier with an argument when launching the script via URL scheme (LCP...) - subject, body etc. could also be passed as arguments.
# Change this:
group_note = 'Group1'
@omz
omz / HowOld.py
Created May 1, 2015 10:43
HowOld.py
# coding: utf-8
# Batch-upload script for how-old.net (Pythonista)
import photos
import requests
import json
import ui
from io import BytesIO
result_size = 320
@omz
omz / PythonistaFTP.py
Last active May 17, 2023 12:43
PythonistaFTP.py
'''FTP server for Pythonista (iOS)
You can use this to exchange files with a Mac/PC or a file management app on the same device (e.g. Transmit).
If you use a Mac, you can connect from the Finder, using the "Go -> Connect to Server..." menu item.
'''
import os
from socket import gethostname
@omz
omz / Mask Example.py
Created July 19, 2015 22:43
Mask Example.py
# Minimal example for ui.Image.clip_to_mask
# Note: Due to the changed image names, this requires Pythonista 1.6 (beta), but it could work in 1.5bwith different image names.
import ui
with ui.ImageContext(256, 256) as ctx:
mask_img = ui.Image.named('iow:beaker_256')
img = ui.Image.named('test:Peppers')
mask_img.clip_to_mask()
img.draw()
@omz
omz / CFNetworkProxySettings.py
Created July 26, 2015 13:25
CFNetworkProxySettings.py
# Print system proxy settings using CFNetwork
# NOTE: Requires Pythonista 1.6 (currently in beta)
from objc_util import *
CFNetworkCopySystemProxySettings = c.CFNetworkCopySystemProxySettings
CFNetworkCopySystemProxySettings.restype = c_void_p
CFNetworkCopySystemProxySettings.argtypes = []
proxy_settings = ObjCInstance(CFNetworkCopySystemProxySettings())
@omz
omz / Map View Demo.py
Created July 28, 2015 21:36
Map View Demo.py
# coding: utf-8
'''
NOTE: This requires the latest beta of Pythonista 1.6 (build 160022)
Demo of a custom ui.View subclass that embeds a native map view using MapKit (via objc_util). Tap and hold the map to drop a pin.
The MapView class is designed to be reusable, but it doesn't implement *everything* you might need. I hope that the existing methods give you a basic idea of how to add new capabilities though. For reference, here's Apple's documentation about the underlying MKMapView class: http://developer.apple.com/library/ios/documentation/MapKit/reference/MKMapView_Class/index.html
If you make any changes to the OMMapViewDelegate class, you need to restart the app. Because this requires creating a new Objective-C class, the code can basically only run once per session (it's not safe to delete an Objective-C class at runtime as long as instances of the class potentially exist).
'''
@omz
omz / CodeEditor Demo.py
Created July 28, 2015 22:18
CodeEditor Demo.py
# coding: utf-8
'''
NOTE: This requires the latest beta of Pythonista 1.6 (build 160022)
Demo of using Pythonista's own internals to implement an editor view with syntax highlighting (basically the exact same view Pythonista uses itself)
IMPORTANT: This is just for fun -- I was curious if it would work at all, but I don't recommend that you rely on this for anything important. The way Pythonista's internals work can change at any time, and this code is *very* likely to break in the future.
'''
import ui