Skip to content

Instantly share code, notes, and snippets.

View timhodson's full-sized avatar

Tim Hodson timhodson

View GitHub Profile
@timhodson
timhodson / month-dirs.sh
Last active December 3, 2019 10:20
Create directories names for each month of a year
# if using zsh you need to get the strftime function to be available
zmodload zsh/datetime
# We're using bash version 4 range expansion
# to generate number of seconds between the 10th day of each month since unix epoch time `0`
# - we use the 10th day to miss months of unequal length
# - we start from 0 seconds. Every year since 1970 has had the same number of months.
# We then pass those seconds to strftime to build our dirname
# which is then used to create the directory
for seconds in {864000..31556952..2629746}
@timhodson
timhodson / quotemeta.sh
Created April 18, 2019 16:19
Quote meta characters in a string to be used in a regex.
#!/bin/bash
# quote meta characters
python -c "import sys,re; [sys.stdout.write(re.escape(line)) for line in sys.stdin]" < <(echo -n "$1")
@timhodson
timhodson / make-linking-table.sh
Created December 17, 2018 10:09
Make a linking table for list URI to Hierarchy URI.
# Utility called csvfix https://bitbucket.org/neilb/csvfix
# first pick the two columns we are interested in - list link, and hierarchy link.
# then split the hierarchy link (which is now colomn 2) on the semi-colon SPACE that is used to delimit.
# then unflatten - i.e. make a record(row) with the first column as key and each of the split columns as value.
# e.g.
# <key>,<val1>,<val2>,<val3>
# becomes
# <key>,<val1>
# <key>,<val2>
@timhodson
timhodson / awslookup
Created May 10, 2018 12:22
awslookup - add to your ~/.profile
# uses aws cli to lookup instances based on a filter on the Name tag
# $1 is the profile to use
# $2 is the filter to use
# $3 is optional, the value doesn't matter but if passed in will result
# in this function printing out the raw command its about to run
# for debugging purposes
awslookup() {
cmd="aws --profile $1 ec2 describe-instances --filters \"Name=tag:Name,Values=$2\" --query 'Reservations[].Instances[].[InstanceId,PublicDnsName,PrivateDnsName,State.Name,InstanceType,join(\`,\`,Tags[?Key==\`Name\`].Value)]' --output table"
if [ $# -eq 3 ]
then
@timhodson
timhodson / example.sh
Created October 13, 2017 09:35
While loop reading a file example
# for each line read of the file
while read line
do
echo "$line"
done < input_file.txt
@timhodson
timhodson / IIFE-examples.js
Last active November 16, 2016 13:28
IIFE Javascript Immediately-Invoked Function Expression and passing jQuery
/**
* Basic IIFE construction is like this.
*/
(function () { console.log('hello world')})();
/**
* Basic IIFE which passes in the jQuery object as the $ symbol.
*/
(function ($) { $('div.classname')})(jQuery);
@timhodson
timhodson / runCommandAllDockers.sh
Created August 17, 2016 09:13
Run a command on all docker containers
for container in `docker ps -q`; do
# show the name of the container
docker inspect --format='{{.Name}}' $container;
# run the command (date in the case)
docker exec -it $container date;
done
@timhodson
timhodson / TARL-Search-Box.html
Created August 12, 2016 11:44
Talis Aspire Reading Lists Search box for external websites
<div id="tarlSearchBox">
<h2 id="tarlSearchTitle">Search for reading lists by module name</h2>
<p id="tarlSearchDescription"></p>
<form id="tarlSearch" method="get" action="https://{{tenantShortCode}}.rl.talis.com/search.html">
<div>
<label for="q" class="invisible sr-only">Search</label>
<input id="q" type="text" name="q" size="50" maxlength="1000">
<input id="tarlBtnSearch" type="submit" value="Search">
</div>
</form>
@timhodson
timhodson / BasicLTIConfigForTalisAspireReadingLists.xml
Created August 11, 2016 16:25
Basic LTI XML config for Talis Aspire Reading Lists
<?xml version="1.0" encoding="UTF-8"?>
<basic_lti_link xmlns="http://www.imsglobal.org/xsd/imsbasiclti_v1p0"
xmlns:lticm ="http://www.imsglobal.org/xsd/imslticm_v1p0"
xmlns:lticp ="http://www.imsglobal.org/xsd/imslticp_v1p0"
xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation = "http://www.imsglobal.org/xsd/imsbasiclti_v1p0 http://www.imsglobal.org/xsd/lti/ltiv1p0/imsbasiclti_v1p0.xsd
http://www.imsglobal.org/xsd/imslticm_v1p0 http://www.imsglobal.org/xsd/lti/ltiv1p0/imslticm_v1p0.xsd
http://www.imsglobal.org/xsd/imslticp_v1p0 http://www.imsglobal.org/xsd/lti/ltiv1p0/imslticp_v1p0.xsd">
<title>Talis Reading Lists</title>
<description>Talis Aspire Reading Lists LTI Integration</description>
@timhodson
timhodson / persona-token-example
Last active April 19, 2016 20:02
Use the persona-token script in a sub shell to get the token for your request.
# Here we assume that $TALIS_API_CLIENT_ID and $TALIS_API_CLIENT_SECRET are set in your environment
# A sub shell runs the persona-token script and will return the token we need in the Authorization Bearer header.
curl -v -X GET -H "Authorization: Bearer $(persona-token $TALIS_API_CLIENT_ID $TALIS_API_CLIENT_SECRET)"\
-H "Cache-Control: no-cache"\
"https://rl.talis.com/2/$TENANT_SHORT_CODE/lists/$LIST_GUID"