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
  • 10:58 (UTC -04:00)
  • X @lsloan_umich
View GitHub Profile
@lsloan
lsloan / Trello_searches.md
Last active November 11, 2016 17:48
My Trello (un)saved searches. Most of these URLs are specific to me because they include my username, "lsloan". From: https://trello.com/c/xTnrLpKf, https://trello.com/lsloan
@lsloan
lsloan / prompt_escape_sequences.md
Last active June 10, 2016 15:15
Notes about bash prompt settings and terminal escape sequences.
@lsloan
lsloan / numericStringArrayKeys.php
Created May 29, 2016 15:39
PHP converts strings of numeric characters to numbers when used as array indices or keys. Some tricks to get around that.
<?php
$key = '11'; // A key to be used in both examples
// Usual behavior: numeric strings are converted to numbers
$data = [];
$data[$key] = 38;
$data['12'] = 37;
echo var_export($data, 'return') . PHP_EOL; // notice keys are numbers
echo var_export(array_key_exists('12', $data), 'return') . PHP_EOL; // true
echo $data['12'] . PHP_EOL; // 37
<a href="http://lemonly.com/work/42-towel-day-infographic" title="42: Life, the Universe and Everything – A Towel Day Infographic by Lemonly">
<img src="http://lemonly.com/wp-content/uploads/2013/05/Towel_Day-42-Infographic-960x2178.jpg"style="max-width: 100%" alt="42: Life, the Universe and Everything – A Towel Day Infographic Design by Lemonly" />
</a>
Learn more about <a href="http://lemonly.com/work/42-towel-day-infographic">Towel Day </a> and <a href="http://lemonly.com">Infographic Design</a> from Lemonly.
<a href="http://lemonly.com/work/celebrating-towel-day-may-25-2012" title="Don't Panic, Use a Towel Day Infographic">
<img src="http://lemonly.com/wp-content/uploads/2012/05/Towel-day-Infographic2.jpg"style="max-width: 100%" alt="Don't Panic, Use a Towel Day Infographic; Design by Lemonly" />
</a>
Learn more about <a href="http://lemonly.com/work/celebrating-towel-day-may-25-2012">Towel Day</a> and <a href="http://lemonly.com">Infographic Design</a> from Lemonly.
@lsloan
lsloan / iso8601TimestampWithMilliseconds.php
Last active January 17, 2023 07:40
Get PHP DateTime objects with fractional seconds and format them according to ISO 8601.
/*
* The `DateTime` constructor doesn't create objects with fractional seconds.
* However, the static method `DateTime::createFromFormat()` does include the
* fractional seconds in the object. Finally, since ISO 8601 specifies only
* millisecond precision, remove the last three decimal places from the timestamp.
*/
// DateTime object with microseconds
$now = DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''));
@lsloan
lsloan / OAuth_example.php
Last active May 19, 2016 17:15
An example of using a popular PHP OAuth package (eher/oauth) to generate the value of the HTTP Authorization header for a request.
<?php
require_once 'vendor/autoload.php';
/**
* Why doesn't PHP already have these defined?
*/
class HttpMethods {
const
HTTP_METHOD_DELETE = 'DELETE',
HTTP_METHOD_GET = 'GET',
// http://aboutcode.net/2010/11/11/list-github-projects-using-javascript.html
jQuery.githubUserRepositories = function(username, callback) {
jQuery.getJSON("https://api.github.com/users/" + username + "/repos?callback=?", callback);
}
jQuery.fn.loadRepositories = function(username) {
this.html("<span>Querying GitHub for repositories...</span>");
var target = this;
@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'
@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)