Skip to content

Instantly share code, notes, and snippets.

jsbain

Block or report user

Report or block jsbain

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
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.
#
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.
View ZoomView.py
import ui
class Touch(object):
''' writable version of ui.Touch'''
def __init__(self,touch):
self.location=touch.location
self.touch_id=touch.touch_id
self.phase=touch.phase
self.prev_location=touch.prev_location
self.timestamp=touch.timestamp
View path_edit.py
'''
useless path editor.
tap to add a point. tap again to add a control point.
then, another control point, and finally another point on the curve.
existing points and control points can be dragged around, to change the curve.
clicking save button saves an image of the path, without the handles.
View world.py
class world (object):
def webview_should_start_load(self,webview, url, nav_type):
if url.startswith('world://'):
print 'country selected:', urlparse.unquote(urlparse.urlparse(url).netloc)
return False
else:
return True
import ui,os
w=ui.WebView()
You can’t perform that action at this time.