Skip to content

Instantly share code, notes, and snippets.

@jstanley0
jstanley0 / nalbinding_needle.scad
Last active February 4, 2023 22:58
nalbinding needle
length = 100;
width = 12;
thickness = 5;
flat_ratio = 0.5;
build_plate = true;
hole_width = 8;
hole_stretch = 0.9;
hole_chamfer = 1.25;
pointiness = 25;
$fn = 25;
@jstanley0
jstanley0 / canvas-time-travel.md
Last active February 17, 2022 17:07
Canvas Time Travel HOWTO

Canvas time travel HOWTO

How to get a historic version of Canvas up and running. Other than a few specific points, these tips may be useful for other Rails apps.

0. preparation

  • provision a linux VM (see MACOS_NOTE at the end of this document)
    • if you are using Multipass, be sure to set up adequate disk space (e.g. multipass launch --disk 30G), since the 5GB default will not be sufficient and there is no way to increase it after the fact. don't ask me how I know this. also use --mem 8G or thereabouts because the 1GB default is also not enough (you can change this after the fact, but it involves editing a json file buried in a directory you need sudo to get into)
  • pull down the repo
  • set up rvm and chruby
# this function repairs a blueprint course and its associations when they are broken by a shard split.
# since migration ids depend on the shard number, they will all change after a split. fortunately,
# MasterContentTag remembers the original migration_id so we can use it to build a mapping from old
# to new migration_id, and then go through and replace ids in the blueprint and its associations.
# symptoms of a blueprint that is broken by a shard split include:
# 1. content that is updated in the blueprint gets duplicated instead of updated in
# the associated courses
# 2. content that was locked in the blueprint remains locked in associated courses
# but does not appear locked in the blueprint (and toggling the lock doesn't appear to work)
def repair_master_template!(template_id, dry_run: true)
@jstanley0
jstanley0 / aftershocks.rb
Created March 25, 2020 17:24
create data for a scatter plot of aftershocks from the Magna, UT earthquake on 2020-03-18
require 'date'
require 'net/http'
QUERY = "https://earthquake.usgs.gov/fdsnws/event/1/query?format=text&latitude=40.751&longitude=-112.078&maxradiuskm=50&starttime=2020-03-18"
data = Net::HTTP.get(URI(QUERY)).lines
header = data.shift.split('|')
ts_col = header.index("Time")
raise "Time column not found" unless ts_col
mag_col = header.index("Magnitude")
raise "Magnitude column not found" unless mag_col
@jstanley0
jstanley0 / project-box.scad
Last active September 13, 2019 01:12
Parametric project box
inside_width=57;
inside_length=48;
inside_height=27;
wall_thickness=1.5;
floor_thickness=1;
overlap_thickness=1.5;
overlap_delta=0.25;
pcb_level=16;
@jstanley0
jstanley0 / parse_colloquy.rb
Last active May 15, 2019 16:23
convert colloquy transcripts into plain text
require 'nokogiri'
require 'uri'
INTERESTING_EVENTS = %w(memberJoined memberParted memberNewNickname)
def format_ts(ts)
ts.sub(/ [+-]\d\d\d\d/, '')
end
Nokogiri::XML(ARGF).css('log').each do |log|
@jstanley0
jstanley0 / get-slack-dms.rb
Created May 11, 2019 02:04
Script to download Slack DMs
require 'slack-ruby-client'
require 'pg'
Slack.configure do |config|
config.token = File.read(File.expand_path('~/.slack/token')).strip
end
client = Slack::Web::Client.new
me = client.auth_test
@jstanley0
jstanley0 / pg_ps.rb
Created August 28, 2018 16:24
list and kill Postgres queries from a Rails console
# list pid, execution time, and query text for running queries
def pg_ps
now = Time.now
ActiveRecord::Base.connection.execute("SELECT pid, query, query_start FROM pg_stat_activity WHERE state='active'").to_a.each do |q|
printf "%8d %10.2f %s\n", q['pid'], now - DateTime.parse(q['query_start']), q['query']
end
nil
end
# cancel the current query for the given process
@jstanley0
jstanley0 / sigcheck.rb
Created January 25, 2018 20:54
detect webpack brokenness
require 'digest'
SIG_FILE = File.expand_path("~/.sigcheck")
def read_sig_file
$sig_hashes = {}
if File.exists?(SIG_FILE)
File.open(SIG_FILE, 'r') do |file|
file.each_line do |line|
hashes = line.split
@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