Skip to content

Instantly share code, notes, and snippets.

View shellista.py
import os, cmd, sys, re, glob, os.path, shutil, zipfile, tarfile, gzip, string, urllib2, ui
# Credits
#
# The python code here was written by pudquick@github
#
# License
#
# This code is released under a standard MIT license.
#
@jsbain
jsbain / gistcheck.py
Last active Dec 15, 2017 — forked from davenicholls/gistcheck.py
updated comment: prevent opening of pyui in editor
View gistcheck.py
# Source: https://gist.github.com/5212628
#
# All-purpose gist tool for Pythonista.
#
# When run directly, this script sets up four other scripts that call various
# functions within this file. Each of these sub-scripts are meant for use as
# action menu items. They are:
#
# Set Gist ID.py - Set the gist id that the current file should be
# associated with.
View h2048.py
# -*- coding: utf-8 -*-
"""
Created on Sat Jul 12 09:33:29 2014
@author: henryiii
"""
import random
import numpy as np
from functools import partial
View h2048.py
# -*- coding: utf-8 -*-
"""
Created on Sat Jul 12 09:33:29 2014
@author: henryiii
"""
import random
import numpy as np
import ui
@jsbain
jsbain / solve-ccc-riddle.py
Created Aug 24, 2014
solve-ccc-riddle.py
View solve-ccc-riddle.py
import datetime, logging
def elapsed_datetime(start_datetime, end_datetime = datetime.datetime.now()):
return end_datetime - start_datetime # returns a datetime.timedelta
def find_day(days_on_earth, ref_datetime=datetime.datetime(2014,8,23), ref_is_start=True):
'''find day (datetime obj) corresponding to days_on_earth, tuple of days, hours, min, sec.
ref_is_start == True means ref date is start, return end date. itherwise, return start date given this end date
'''
dt=datetime.timedelta(**dict(zip(['days','hours','minutes','seconds'],days_on_earth)))
@jsbain
jsbain / pipista.py
Last active Aug 29, 2015 — forked from pudquick/pipista.py
updated v2 to work properly with pythinista 1.5
View pipista.py
# pipista v2, by pudquick, updated for pythonista 1.5 by jsbain
# todo: consolidate unzip, ungzip, unbzip, and untar. tarfile supports compressed archives, so can use that directly. use is_zipfile, is_tarfile rather than magic packet stuff. there is a lot of duplicate code elsewhere that should be modularized
# 2) option to use site-packages rather than pypi-modules
# 3) make sure to cleanup .tmp on errors.
import os, os.path, sys, urllib2, requests, tempfile, zipfile, shutil, gzip, tarfile, xmlrpclib, ConfigParser
__pypi_base__ = os.path.abspath(os.path.dirname(__file__))
View wavexample.py
import numpy as N
import wave, sound, os, ui
def get_signal_data(frequency=440, duration=1, volume=32767, samplerate=44100):
"""Outputs a numpy array of intensities"""
samples = duration * samplerate
period = samplerate / float(frequency)
omega = N.pi * 2 / period
t = N.arange(samples, dtype=N.float)
View reminder.py
import notification, uuid, sys
def reminder(message, delay=3600*24, uid=None,
sound_name='default',
action=None, action_args=(),
interval=3600,
num_reminders=5):
''' call a script after a delay, and keep reminding until the notification is acknowledged.
uses a uid to access all instances of this reminder, for deleting or finding when the next instance is scheduled.
@jsbain
jsbain / propertyListener.py
Created Nov 14, 2014
propertyListener.py
View propertyListener.py
import threading
class propertyListener(threading.Thread):
'''create a listener on one or more of a view's properties, and dispatches a callback whenever those properties change.
NOTE: it is highly recommended that the propertyListener instance is part of s custom view class, and in that class's will_close method, call stop() on the instance. otherwise, it will continue to poll even after the view is closed, and could cause problems later.
cosntructor args:
view - the view to watch
propertylist - list of properties to watch. must be a list even if only one prop, e.g ['frame']
action the callback to call. the function should be of the following form
@jsbain
jsbain / TabbedView.py
Last active Jan 26, 2018
TabbedView.py
View TabbedView.py
import ui
class TabbedView(ui.View):
def __init__(self,tablist=[], frame=(0,0)+ui.get_screen_size()):
'''takes an iterable of Views, using the view name as the tab selector.
empty views sre just given generic names'''
self.tabcounter=0 #unique counter, for name disambiguation
self.buttonheight=30 #height of buttonbar
#setup button bar
self.tabbuttons=ui.SegmentedControl(frame=(0,0,self.width, self.buttonheight))
self.tabbuttons.action=self.tab_action
You can’t perform that action at this time.