Skip to content

Instantly share code, notes, and snippets.

View lsloan's full-sized avatar

Mr. Lance E Sloan «UMich» lsloan

  • Teaching and Learning (@tl-its-umich-edu) at University of Michigan: Information and Technology Services
  • Ann Arbor, Michigan, USA
  • 17:10 (UTC -04:00)
  • X @lsloan_umich
View GitHub Profile
@lsloan
lsloan / Sound Demo.py
Last active August 29, 2015 14:16 — forked from omz/Sound Demo.py
# Simple demo of playing a looping sound using the (currently undocumented) sound.Player class
import sound
import os
from scene import *
class MyScene (Scene):
def setup(self):
self.player = sound.Player(os.path.expanduser('~/Pythonista.app/Beep.caf'))
self.player.number_of_loops = -1 #repeat forever
@lsloan
lsloan / sounder.py
Last active August 29, 2015 14:16 — forked from cclauss/sounder.py
Play each .caf sound inside of Pythonista.app
# sounder.py
# play each of the .caf sounds inside the Pythonista.app
import os, os.path, scene, sound
framesPerSound = 60
pythonistaDir = os.path.expanduser('~/Pythonista.app')
soundFileExtension = '.caf'
wallpaperAppIcon = ('/AppIcon76x76@2x~ipad.png', '/AppIcon60x60@2x.png')
@lsloan
lsloan / pipista.py
Last active August 29, 2015 14:18 — forked from pudquick/pipista.py
'''pipista.py'''
import os, os.path, sys, urllib2, requests
class PyPiError(Exception):
def __init__(self, value):
self.value = value
def __str__(self):
return repr(self.value)
@lsloan
lsloan / ksortRecursive
Last active August 29, 2015 14:20 — forked from cdzombak/README.md
Resursive version of PHP's ksort.
See README.md for details.
@lsloan
lsloan / enum.py
Last active August 29, 2015 14:20
Pure Python implementation of an enumerated type
def enum(*sequential, **named):
enums = dict(zip(sequential, range(len(sequential))), **named)
reverse = dict((value, key) for key, value in enums.iteritems())
enums['reverse_mapping'] = reverse
return type('Enum', (), enums)
def example():
Numbers = enum(ONE=1, TWO=2, THREE='three')
print Numbers.ONE
print Numbers.THREE
@lsloan
lsloan / JsonSortTest.php
Last active August 29, 2015 14:20
My attempt to recursively sort data in nested arrays and objects. This is helpful for sorting data in JSON by key.
<?php
class JsonSortTest extends PHPUnit_Framework_TestCase {
public $fixtureFilename = 'fixture.json';
public $outputFilename = 'output.json';
public $fixtureJson;
function ksortObjectsRecursive(&$data, $sortFlags = SORT_REGULAR) {
if (!function_exists('ksortObjectsRecursiveCallback')) {
function ksortObjectsRecursiveCallback(&$data, $unusedKey, $sortFlags) {
@lsloan
lsloan / getNewGUID.php
Created May 12, 2015 17:39
A method for creating GUIDs for PHP, even if com_create_guid() isn't available.
private function getNewGUID($wrapWithBraces = false) {
if (function_exists('com_create_guid')) {
return com_create_guid();
} else {
mt_srand((double)microtime() * 10000); //optional for php 4.2.0 and up.
$charid = strtoupper(md5(uniqid(rand(), true)));
$uuid = ($wrapWithBraces ? '{' : '')
. substr($charid, 0, 8) . '-'
. substr($charid, 8, 4) . '-'
. substr($charid, 12, 4) . '-'

This is a list of tips for the Vim editor

<?php
/**
* Class ClassUtil
*
* Provide useful methods to overcome OOP shortcomings in some versions of PHP.
*/
class ClassUtil {
/**
* The "::class" notation isn't available until PHP 5.5. This method is a workaround for
* older versions of PHP.