Skip to content

Instantly share code, notes, and snippets.

@jsbain
jsbain / shellista.py
Created June 19, 2014 11:03
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 / h2048.py
Created July 21, 2014 04:42 — forked from henryiii/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
@jsbain
jsbain / h2048.py
Last active August 29, 2015 14:04 — forked from henryiii/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 August 24, 2014 07:27
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 August 29, 2015 14:06 — forked from pudquick/pipista.py
updated v2 to work properly with pythinista 1.5
# 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__))
@jsbain
jsbain / reminder.py
Created November 11, 2014 11:56
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 / ZoomView.py
Created November 25, 2014 10:06
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
@jsbain
jsbain / path_edit.py
Created January 8, 2015 08:40
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.
@jsbain
jsbain / world.py
Created February 18, 2015 15:56
world
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()
@jsbain
jsbain / gistcheck.py
Created March 25, 2015 06:15
updated for ios8
# 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.