Skip to content

Instantly share code, notes, and snippets.

Ole Zorn omz

View GitHub Profile
@omz
omz / CoreML Image Recognition.py
Created Jul 8, 2018
CoreML Image Recognition.py
View CoreML Image Recognition.py
#!python3
'''
This is a demo of how you can use the CoreML framework (via objc_util) to classify images in Pythonista. It downloads the trained 'MobileNet' CoreML model from the Internet, and uses it to classify images that are either taken with the camera, or picked from the photo library.
'''
import requests
import os
import io
import photos
import dialogs
@omz
omz / DownloadPhotosFromCloud.py
Created Apr 4, 2018
DownloadPhotosFromCloud.py
View DownloadPhotosFromCloud.py
# Quick workaround for photos module (Pythonista) not downloading photos from iCloud
import photos
from objc_util import ObjCClass, ObjCInstance, ObjCBlock
def download_cloud_asset(asset):
PHImageManager = ObjCClass('PHImageManager')
PHImageRequestOptions = ObjCClass('PHImageRequestOptions')
ph_asset = ObjCInstance(asset)
ph_image_mgr = PHImageManager.defaultManager()
@omz
omz / core_image.py
Last active Feb 27, 2018
core_image.py
View core_image.py
'''
This module provides a Python wrapper around CIImage and CIFilter for using CoreImage filters from Pythonista more easily.
How to use:
1) Create a CImage object. The constructor accepts either a file path, a ui.Image, PIL.Image.Image, or photos.Asset object. Example:
>>> # From a photo:
>>> img = CImage(photos.pick_asset())
>>> # From a ui.Image:
@omz
omz / Geotag Photos.py
Last active Jan 20, 2018
Geotag Photos.py
View Geotag Photos.py
#!python3
'''
This is a proof-of-concept script for tagging photos with location data on iOS.
* First, it shows all photos that have no location data *and* are editable.
* Then, a grid of photos in temporal proximity is shown. You can pick multiple photos here.
* When you tap Done, the photo you selected first will get tagged with the average location of the photos you picked in the second step.
'''
import photos
@omz
omz / UI Debugging Overlay.py
Last active Nov 30, 2017
UI Debugging Overlay.py
View UI Debugging Overlay.py
# Pythonista script to show the UI Debugging overlay (private API) described in this blog post:
# http://ryanipete.com/blog/ios/swift/objective-c/uidebugginginformationoverlay/
from objc_util import ObjCClass, on_main_thread
UIDebuggingInformationOverlay = ObjCClass('UIDebuggingInformationOverlay')
@on_main_thread
def toggle_overlay():
UIDebuggingInformationOverlay.prepareDebuggingOverlay()
UIDebuggingInformationOverlay.overlay().toggleVisibility()
View motion.py
# `motion` module from Pythonista
# This is missing in the current App Store versions (in Pythonista 3.x, it's only missing in Python 2 mode).
# As a temporary workaround, you can put this file in the "site-packages" folder (under "Modules" or "Modules & Templates").
import _motion
shared_manager = _motion.MotionManager()
def start_updates():
shared_manager.start()
@omz
omz / Add Playground Page.py
Created Jun 17, 2016
Add Playground Page.py
View Add Playground Page.py
#! python3
# Share sheet extension script for adding new pages to Swift Playgrounds (experimental)
# HOW TO USE:
# 1. Add this script as a shortcut to the Pythonista extension (either from Pythonista's settings or the share sheet extension itself)
# 2. Tap the "Share" button in the Playground app's library.
# 3. Select the playground that you want to add a page to
# 4. Select "Run Pythonista Script" in the share sheet
# 5. Run this script, to select the chapter and page title.
View pythonista_cc_mandelbrot_shader
import scene, ui
shadercode_text = '''
// Modified Mandelbrot code from shadertoy.com
// https://www.shadertoy.com/view/XdtSRN
// used make_color function from ccc (pythonista forum)
// https://github.com/cclauss/fractal_hacks/blob/master/cc_mandelbrot.py
precision highp float;
varying vec2 v_tex_coord;
View photopicker2.py
# Experimental photo picker using the Photos framework via objc_util. Compared to the photos module, this has the advantage of showing all photos, including iCloud photo library. Not very well tested!
from objc_util import *
import threading
from io import BytesIO
from PIL import Image
import sys
import ui
import ctypes
@omz
omz / Spellcheck word.py
Created Mar 10, 2016
Spellcheck word.py
View Spellcheck word.py
# coding: utf-8
from objc_util import ObjCClass
UITextChecker = ObjCClass('UITextChecker')
def check_word(word, lang='en_US'):
c = UITextChecker.new().autorelease()
check = c.rangeOfMisspelledWordInString_range_startingAt_wrap_language_
misspelled_range = check(word, (0, len(word)), 0, False, lang)
return (misspelled_range.location != 0)
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.