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
  • 06:56 (UTC -04:00)
  • X @lsloan_umich
View GitHub Profile
@lsloan
lsloan / Python-cx_Oracle-OSX.md
Last active March 23, 2016 18:32
A few notes about installing cx_Oracle for Python under OS X

Info about installing cx_Oracle under OS X can be found at: https://gist.github.com/thom-nic/6011715

cx_Oracle must be installed because it doesn't come pre-installed with Python. Don't use pip! Instead of using pip, following the directions located here: http://joelvasallo.com/?p=276

When the instructions from the above link have been followed and completed, it is possible that you can update the cx_Oracle module with pip

@lsloan
lsloan / decimal_rounding.js
Created March 24, 2016 13:27
Decimal rounding with Math.round() in JavaScript
// From: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/round#Decimal_rounding
// Closure
(function() {
/**
* Decimal adjustment of a number.
*
* @param {String} type The type of adjustment.
* @param {Number} value The number.
* @param {Integer} exp The exponent (the 10 logarithm of the adjustment base).
* @returns {Number} The adjusted value.
@lsloan
lsloan / float_bug.js
Last active May 13, 2024 23:25
JavaScript floating point math bug example
/*
* Demonstrate JavaScript floating point math bugs by showing
* which two-decimal-place numbers between 0.00 and 1.00 inclusive
* have fractional parts after being multiplied by one hundred.
*/
var i = 0.00;
for (n = 0; n <= 100; ++n) {
j = i * 100;
if (Math.round(j) != j) {
@lsloan
lsloan / basic_class_new_method.py
Last active July 2, 2016 15:08
Python: A basic implementation of `__new__()` that invokes the same method in the superclass.
"""
Whenever I want to implement my own __new__() for a class, I've usually forgotten
the incantation for calling the method in the superclass, so I'm making note of it
here.
"""
class Fubar(object):
def __new__(cls, *args, **kwargs):
"""
To use, replace `Fubar` in the call to `super()` with the name of this class.
"""
import console
import editor
import os
import shutil
DOCUMENTS = os.path.expanduser("~/Documents")
old_name = editor.get_path()
new_name = os.path.join(DOCUMENTS, console.input_alert("Duplicate File", "Enter new name", os.path.relpath(old_name, DOCUMENTS)))
@lsloan
lsloan / inconsistent_try_finally.php
Last active March 28, 2016 18:11
PHP: Inconsistent try...finally blocks are expected to return the same value, but don't.
<?php
function fubar1($foo = 1){
_($foo, 1);
try{
$foo++; // even works when $foo modified in this block
_($foo);
return $foo; // only works when bare $foo returned
} finally {
_($foo);
$foo++;
@lsloan
lsloan / QuickViewer.py
Last active March 30, 2016 19:31
Pythonista program to open a URL (given via iOS share sheet) in Safari. May require iOS 9. (Untested.)
# coding: utf-8
# from: https://forum.omz-software.com/topic/2271/beta-suggestion-safariviewcontroller/9
from objc_util import *
import appex
SFSafariViewController = ObjCClass('SFSafariViewController')
def open_in_safari_vc(url):
vc = SFSafariViewController.alloc().initWithURL_entersReaderIfAvailable_(nsurl(url), True)
@lsloan
lsloan / SessionEventSampleApp.php
Created April 1, 2016 21:22
PHP example of "use" keyword to shorten references' namespaces.
<?php
use
IMS\Caliper\Client,
IMS\Caliper\Options,
IMS\Caliper\Sensor,
IMS\Caliper\actions\Action,
IMS\Caliper\entities\agent\Person,
IMS\Caliper\entities\agent\SoftwareApplication,
IMS\Caliper\entities\reading\EPubVolume,
IMS\Caliper\entities\reading\Frame,
@lsloan
lsloan / iterable_differentiation_test.py
Created April 4, 2016 13:27
Attempting to find a common differentiation between strings and other iterable collections.
# Attempting to find a common differentiation
# between strings and other iterable collections.
import collections
testSubjects = [
'asdf',
1,
[1, ],
(1,),
@lsloan
lsloan / typehint.php
Last active April 8, 2016 16:35
PHP: Developers often want scalar/basic type hints. This drop-in class enables type hints through the use of a custom error handler.
<?php
define('TYPEHINT_PCRE', '/^Argument (\d)+ passed to (?:(\w+)::)?(\w+)\(\) must be an instance of (\w+), (\w+) given/');
class Typehint {
private static $Typehints = array(
'boolean' => 'is_bool',
'integer' => 'is_int',
'float' => 'is_float',
'string' => 'is_string',
'resrouce' => 'is_resource'