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
  • 16:04 (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 / string_comparison_example.php
Last active June 15, 2016 19:36
PHP: Avoid the equal ("==") comparison operator for comparing strings that may be numeric.
<?php
/*
* When using the equal comparison operator ("==") to compare a number with a string or
* the comparison involves numeric strings, each string is converted to a number and the
* comparison performed numerically. These rules also apply to the switch statement. The
* type conversion does not take place when using the identical comparison operator
* ("===") as that involves comparing the type as well as the value.
*
* It's safer to always use strcmp() or the identical comparison operator ("===") for
* string comparisons.
@lsloan
lsloan / Vim Markdown support.md
Last active June 21, 2016 20:38
My vim environment that does a pretty good job with showing formatting as one edits markdown and keeps my preferred behavior.

An example of configuring Vim to support Markdown.

@lsloan
lsloan / get-get-pip.py
Created June 23, 2016 18:53
Get get-pip.py. (Helpful for Pythonista.)
#!/usr/bin/env python
import requests
OUTPUT_FILE = 'get-pip.py'
URL = 'https://bootstrap.pypa.io/' + OUTPUT_FILE
file(OUTPUT_FILE, 'w').writelines(requests.get(URL))
@lsloan
lsloan / caliper_post.sh
Created June 27, 2016 16:36
Post a rudimentary Caliper event to an endpoint. Assumes USER and HOSTNAME environment variables are available.
#!/bin/sh --
NOW=$(date -u +"%Y-%m-%dT%H:%M:%SZ") # ISO 8601 format, UTC
CURL_STDIN='@-' # cURL's notation for stdin
curl "https://endpoint.example.org/caliper" \
--request POST \
--header "Content-Type: application/json" \
--capath /etc/pki/tls/certs/ \
--data ${CURL_STDIN} << EOT
@lsloan
lsloan / hash_hmac.sh
Created June 27, 2016 16:54
A (Bash) shell function for creating digest values.
#!/bin/sh --
function hash_hmac {
digest="$1"
data="$2"
key="$3"
shift 3
echo -n "$data" | openssl dgst "-$digest" -hmac "$key" "$@"
}
@lsloan
lsloan / jython_explore_java.md
Last active August 12, 2016 21:46
A guide to using Jython for exploring the Java environment of a project managed with Maven.

Use Jython To Explore Java

When I develop with Python, I like to use its interactive interpreter to experiment with code samples quickly and in real time. It allows me to import the code I've been developing so I can test it in a controlled environment. Java doesn't include this ability outnatively, but there are a number of ways to accomplish something similar with additional software. With my preference for Python, I chose Jython to do this.

  1. Install Jython. See jython.org for details. It may be as simple as, for example, on OS X with Homebrew:
brew install jython
@lsloan
lsloan / urltidy.py
Created July 8, 2016 20:45
Python experiments in removing contiguous slashes from URLs. The `urlparse` module should do this.
"""
Experiments in removing contiguous slashes in URLs.
Why doesn't urlparse do this for us?
"""
import posixpath
import re
import urlparse
apiBaseURL = 'http://example.org//api/v1/'
@lsloan
lsloan / stringContainsCharacters.py
Created July 26, 2016 20:22
Python: A couple of methods to check whether a string contains any or all of the characters from a second string.
def stringContainsAnyCharacters(string, characters):
"""
Check whether 'string' contains any characters from string 'characters'.
:param string: String to check for wanted characters
:type string: str
:param characters: String of characters to be found
:type characters: str
:return: True if any characters are found, False otherwise
:rtype: bool
@lsloan
lsloan / requests_extension.py
Created July 26, 2016 21:33
Python: This seemed like a clever way to allow my extension to requests to accept a URI containing named parameters. If the URI still contained the parameters by the time it received them, it would use the method's keyword arguments to replace them. However, being careful to pass along `**kwargs` turned out to be a problem. If the keyword argume…
def get(self, apiQueryURI, params=None, **kwargs):
"""
Append the specified query URI to the base URL, which is then sent to the REST API.
Results are returned as a requests.Response object.
:param apiQueryURI: URI for the query, to be appended to the base URL
:type apiQueryURI: str
:return: requests.Response
:rtype: requests.Response
"""