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
  • 15:39 (UTC -04:00)
  • X @lsloan_umich
View GitHub Profile
@emsearcy
emsearcy / simple_redis_sentinel.php
Last active November 14, 2017 21:59
Simple PHP Redis Sentinel master request
<?php
/*
* Parse RESP (REdis Serialization Protocol)
*/
function read_resp($fp = null) {
// File descripter to the Redis server connection
// (static to limit recursion stack size)
static $conn = null;
if (!$conn) $conn = $fp;
@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.
"""
@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 / 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 / README.md
Last active February 17, 2016 19:22
A very simple filter intended for use with AngularJS's `ng-repeat`, etc. to use only unique array items.

I wrote this for a project that didn't want to import additional libraries just for this functionality.
It could probably be more efficient and it only supports direct attributes of the item in question.
It would be nice to add support for attr.subattr.etc at some point. (Maybe using AngularJS's $parse()?)

Other similar functions:

@zoharbabin
zoharbabin / addTagsToAllKalturaEntries.py
Last active February 2, 2022 15:36
Kaltura API Python Script for adding tags to all entries in the account
# This script loops through all media entries in a given Kaltura account
# and sets tags to all entries (it also checks if a list of tags is not already set on the entry before adding)
# this script requires the Kaltura Python 2.7 client library: http://www.kaltura.com/api_v3/testme/client-libs.php
import sys
import os
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
from KalturaClient import *

I've noticed when using DefiantJS's XPath features to search a list of Caliper event JSON from OpenLRS that it's necessary to use some special node names that aren't explcitly shown in the data. For example, if the JSON were:

[
    {
        "edApp": {
            "@id": "https://example.com/super-media-tool",
            "@type": "http://purl.imsglobal.org/caliper/v1/SoftwareApplication",
            "name": "Super Media Tool"
 }
@andyshinn
andyshinn / Dockerfile
Created December 24, 2015 19:07
BusyBox cron container example
FROM gliderlabs/alpine:3.3
COPY myawesomescript /bin/myawesomescript
COPY root /var/spool/cron/crontabs/root
RUN chmod +x /bin/myawesomescript
CMD crond -l 2 -f
// 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.loadRepositores = function(username) {
this.html("<span>Querying GitHub for repositories...</span>");
var target = this;
@lsloan
lsloan / composer_notebook.md
Last active December 11, 2015 16:52
My Composer notebook

Composer Notebook

  1. Ignoring the cache: Composer doesn't have an option to make it ignore its cache while running a command. The Composer developers do not believe this is an important feature and they refused an issue opened to request it. However, it can be helpful for debugging dependency installation. To make a single Composer command (e.g., composer update) ignore the cache, use one of the following:

    1. This version generates innocuous, ignorable errors about the cache directory:

      COMPOSER_CACHE_DIR=/dev/null composer update