Skip to content

Instantly share code, notes, and snippets.

#!/bin/sh
rm -f /tmp/legion*.aiff
say -v ? | cut -c 1-20 | sed 's/ *$//' | while read voice
do say -v "$voice" $1 -o "/tmp/legion-$voice.aiff"
done
sox -m /tmp/legion-*.aiff /tmp/legion.aiff
rm -f /tmp/legion-*.aiff
play /tmp/legion.aiff
@jstanley0
jstanley0 / git_nuke.sh
Created March 12, 2013 15:10
searches for git repositories under the given directory and resets them to the latest master e.g., to reset all plugins to the latest: git_nuke.sh vendor/plugins or to reset the current repository and all git repos under it: git_nuke.sh .
#!/bin/bash
if [ -z $1 ]
then
echo "this thing will reset all nested git repos to HEAD/master"
echo "specify a starting point"
exit 1
fi
if [ -d $1 ]
then
repos=`find $1 -name .git`
@jstanley0
jstanley0 / carpool app
Last active December 17, 2015 09:09
ideas for a carpool app
there are a bunch of carpool apps in the google play store, but they're not quite what I'm looking for. they help arrange ad-hoc trips. they use gps and such to compute how much each participant owes. they don't generally work across platforms (I have iOS and Android participants)
in my carpool, participants don't pay each other; they just take turns driving. that sounds pretty simple, but schedules being what they are, participants miss days, and often the driver is determined only by last-minute texting.
so a few things I'd look for in an app are:
- a carpool consists of a route, a schedule, and two or more drivers.
- counting rides given vs. rides received. the next driver for a carpool will be the one with the lowest ratio.
- calendar. at a glance, you can see who will be driving on which day.
- reminders. the app notifies (possibly just texts) you when it's your turn.
- confirmation. you can tell the app that you're confirmed-in, or out.

We need an API for the module sequence footer (the navigation at the bottom of an assignment, discussion, etc., that links to the previous and next items in the course module sequence).

How should we specify the object we want sequence information for?

The non-API endpoint takes an asset tag. An API call like this would look something like:

(A) GET /api/v1/courses/123/module_sequence/assignment_456

Or maybe we would rather see:

@jstanley0
jstanley0 / api search query analysis
Created August 23, 2013 19:53
explain analyze for api searches
discussion topics
matched term
beta7.cluster7=> SELECT * FROM "discussion_topics" WHERE ((((LOWER(discussion_topics.title) LIKE '%pwn%')) AND ("discussion_topics"."type" IS NULL)) AND ((((LOWER(discussion_topics.title) LIKE '%pwn%')) AND ("discussion_topics"."type" IS NULL)) AND ("discussion_topics".context_id = 782370 AND "discussion_topics".context_type = 'Course' AND (discussion_topics.workflow_state != 'deleted')))) ORDER BY discussion_topics.position DESC, discussion_topics.created_at DESC, discussion_topics.position DESC, discussion_topics.created_at DESC LIMIT 10 OFFSET 0
beta7.cluster7-> ;
beta7.cluster7=>
beta7.cluster7=>
beta7.cluster7=> explain analyze SELECT * FROM "discussion_topics" WHERE ((((LOWER(discussion_topics.title) LIKE '%pwn%')) AND ("discussion_topics"."type" IS NULL)) AND ((((LOWER(discussion_topics.title) LIKE '%pwn%')) AND ("discussion_topics"."type" IS NULL)) AND ("discussion_topics".context_id = 782370 AND "discussion_topics".context_type = 'Course' AND (discussion_topics.wo
@jstanley0
jstanley0 / gist:6323984
Created August 23, 2013 21:02
with / without trigram indexes
no trigram index:
cluster2.cluster2=> explain analyze SELECT * FROM "discussion_topics" WHERE ((((LOWER(discussion_topics.title) LIKE '%data%')) AND ("discussion_topics"."type" IS NULL)) AND ((((LOWER(discussion_topics.title) LIKE '%data%')) AND ("discussion_topics"."type" IS NULL)) AND ("discussion_topics".context_id = 245134 AND "discussion_topics".context_type = 'Course' AND (discussion_topics.workflow_state != 'deleted')))) ORDER BY discussion_topics.position DESC, discussion_topics.created_at DESC, discussion_topics.position DESC, discussion_topics.created_at DESC LIMIT 10 OFFSET 0;
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
QUERY PLAN
Limit (cost=70.57..70.58 rows=
@jstanley0
jstanley0 / uctf-convert.rb
Created February 20, 2014 04:01
Convert microcorruption memory dump to binary
buffer = "".force_encoding("BINARY")
ARGF.each_line do |line|
addr, data = line.split(':', 2)
next unless data
addr = addr.to_i(16)
data = data[/(?:\h\h\h\h )+/]
next unless data
data = [data.gsub(' ', '')].pack("H*")
buffer << ("\0" * (addr - buffer.size))
@jstanley0
jstanley0 / lagos-search.rb
Created February 22, 2014 21:39
Naive but effective searcher for a short series of numbers comprised of alphanumeric characters that sum to a specific value, and intermediate values satisfy a bitwise constraint
require 'Set'
def search_helper(nums, partial_sum, list, target, length, constraint)
if list.length >= length - 1
last = target - partial_sum
if nums.include?(last)
list << last
return list
end
else
@jstanley0
jstanley0 / fake_analytics.rb
Last active March 20, 2017 17:14
Fake Analytics for Canvas
# this will create a course and populate it with synthetic analytics data
# (early / late / missing submissions, grades, messages, page views and participations)
# to use: in a canvas rails console
# > load 'fake_analytics.rb'
# > FakeAnalytics.create_course!(teacher)
# where teacher is the user to enroll as teacher in the new course
class FakeAnalytics
ASSIGNMENT_COUNT = 7
@jstanley0
jstanley0 / extract_tentacle.rb
Last active September 6, 2020 20:24
Thing that extracts files from Day of the Tentacle: Remastered (`tenta.cle`) and probably similar things
require 'bindata'
require 'pathname'
require 'fileutils'
require 'optparse'
class Header < BinData::Record
endian :little
uint32 :magic
float :version