Skip to content

Instantly share code, notes, and snippets.

View trishume's full-sized avatar

Tristan Hume trishume

View GitHub Profile
@trishume
trishume / collatz.rb
Created July 6, 2011 22:26
Collatz conjecture chains in ruby
# small recursive version
def collatzr(num,arr = [])
return arr if arr.unshift(num)[0] == 1
num.even? ? collatzr(num / 2,arr) : collatzr(num * 3 + 1,arr)
end
# pretty looping version
def collatz(num,arr = [])
while num != 1
arr << num
num = num.even? ? num / 2 : num * 3 + 1
@trishume
trishume / burn.rb
Created July 18, 2017 19:31
CPU load tester for Sublime
# Sublime load test for https://github.com/SublimeTextIssues/Core/issues/1820
# On my 15" 2016 rMBP:
# 4 is not noticeable
# 8 is noticeable and just barely keeps up with typing
# 20 lags way behind my typing
NUM_PROCS = 20
def compute_things()
sum = 0
10_000.times do |i|
@trishume
trishume / lib.rs
Created July 5, 2017 15:53
Faster Rust benchmark that still gives no information
pub fn suffix_vec_ref(s: &str) -> Vec<&str> {
let mut vec = Vec::with_capacity(s.len());
let mut slice = &s[1..];
while !slice.is_empty() {
vec.push(slice.clone());
slice = &slice[1..];
}
vec
}
@trishume
trishume / unix201.txt
Created March 22, 2017 23:36
CS Club Unix 201 Content
Unix 201:
Introduction:
☐ Man pages (including searching)
☐ The internet
Customizing your prompt:
☐ Basic PS1
☐ Fancy stuff
Ranger:
☐ Basics
☐ ranger-cd
@trishume
trishume / pjc_and_nix.md
Last active January 4, 2017 23:32
PackageJsonForCompilers/Esy and Nix

This is a response to a tweet by @jordwalke asking me about Nix and PackageJsonForCompilers. Twitter is too short form to answer well, so I wrote up some thoughts here. I might turn this into a blog post at some point.

Nix

Nix is a package manager, but also a meta-build system and deployment system. It works based off a global /nix/store/ folder where everything is stored keyed by a hash of its description and the description of all its dependencies. This way you can have multiple versions of any package, and not only that different copies of the same version compiled against different versions of its dependencies or with different compile flags. All dependencies must be fully specified and the way the building works enforces this completely. This way completed binaries can be served from a "cache" with no issue. This gives the best of source-based package managers and binary ones.

The way it handles build vs. runtime depe

@trishume
trishume / calculations.md
Created August 8, 2016 00:43
Canada Basic Income Calculations

Basic Income

Calculations done by Tristan Hume for a public policy class report.

basic income = $10,000/year

number of adult citizens = 27131010 => 27,131,010 total cost = number of adult citizens * basic income => $271,310,100,000/year

Stuff in Canada that could be eliminated

@trishume
trishume / liquid_shell.rb
Created August 30, 2013 21:03
Liquid Templating Language REPL
require 'liquid'
require 'readline'
require 'colorize'
$state = {'test' => 5, 'wat' => "yup"}
def eval_liquid(str)
temp = Liquid::Template.parse(str)
temp.render($state)
end
@trishume
trishume / FittsTaskTwo.cfg
Created July 22, 2016 22:17
My Fitts' law applet settings
# Above goes participant \n condition \n block
# ----------------------------------------
# Configuration arguments for FittsTaskTwo
# ----------------------------------------
# -----
# PARTICIPANT CODE (part of output data file names)
# P21
@trishume
trishume / datasummary.rb
Created March 24, 2016 18:25
Summarize FittsTaskTwo task output data
# Summarizes data produced by my FittsTaskTwo fork
require "csv"
data = []
Dir["FittsStudy/FittsTaskTwo-P*-C*-B*-sd2.csv"].each do |f|
_, p, c, b = /FittsTaskTwo-P(.*)-C(.*)-B(.*)-sd2\.csv/.match(f).to_a
table = CSV.read(f, headers: true)
tps = table["TP(bps)"].map { |e| e.to_f }
avg_tp = (tps.inject(:+) / tps.size).round(3) unless tps.empty?
data << [c, p, b, avg_tp]
@trishume
trishume / eyetribe.h
Created January 27, 2016 23:26
TheEyeTribe protocol reverse engineering
// Reversing notes
// Tristan Hume
// trying to figure out what packets to send to get the lights to turn on for a TheEyeTribe tracker
// Steps so far:
// debug the server so I can figure out how to log all UVC control requests sent using
// the mechanism in https://github.com/HBehrens/CamHolderApp/blob/master/CamHolderApp%2FUVCCameraControl.h
// I've managed to figure out where the IOUSBDevRequestDesc is in registers at one point
// Next step is to create a debugger script that logs it whenever that method is called.
//