Skip to content

Instantly share code, notes, and snippets.

View tcdowney's full-sized avatar

Tim Downey tcdowney

View GitHub Profile
@tcdowney
tcdowney / atom?.ss
Created January 8, 2013 16:28
Definition for atom? for The Little Schemer.
(define atom?
(lambda (x)
(and (not (pair? x)) (not (null? x)))))
;; Test code
(atom? (quote ()))
@tcdowney
tcdowney / lat?.scm
Created January 9, 2013 15:58
Definition for lat? for The Little Schemer. #myversion
;; A lat is a list of atoms.
(define lat?
(lambda (l)
(cond
((null? l) #t)
((not (atom? (car l))) #f)
(else (lat? (cdr l))))))
@tcdowney
tcdowney / member?.scm
Created January 9, 2013 18:10
The definition for member? for The Little Schemer. Returns #t if the first argument (an atom) is found in the second argument (a list of atoms).
(define member?
(lambda (a lat)
(cond
((null? lat) #f)
(else (or (eq? (car lat) a) (member? a (cdr lat)))))))
@tcdowney
tcdowney / free?.scm
Created January 21, 2013 02:12
Scheme snippet that returns true if the variable is a free variable in the expression. Taken from C311 notes and uses pmatch library.
(define free?
(lambda (y e ce)
(pmatch e
[,x (guard (symbol? x)) (and (eq? x y) (not (memq y ce)))]
[(lambda (,x) ,body) (free? y body (cons x ce))]
[(,rator ,rand) (or (free? y rator ce)(free? y rand ce))])))
void ds_gyro_read(uint8_t* pBuffer, uint8_t ReadAddr, volatile uint16_t NumByteToRead) {
if (NumByteToRead > 0x01) {
ReadAddr |= (uint8_t)(0x80 | 0x40); // If sending more that one byte set multibyte commands
}
else {
ReadAddr |= (uint8_t) (0x80); // Else just set the read mode
}
GYRO_CS_LOW();
//GPIO_ResetBits(GPIOE, GPIO_Pin_3);
@tcdowney
tcdowney / primeperms.rb
Last active August 29, 2015 14:00 — forked from baweaver/primeperms.rb
Use the sieve :)
def eratosthenes(n)
nums = [nil, 1, *2..n]
(2..Math.sqrt(n)).each do |i|
(i**2..n).step(i){|m| nums[m] = nil} if nums[i]
end
nums
end
primes_to_million = eratosthenes(1_000_000)
@tcdowney
tcdowney / missing_translations.rb
Created October 10, 2014 02:39
Missing Translations RSpec Matcher
# spec/support/missing_translations.rb
require 'rspec/expectations'
RSpec::Matchers.define :have_missing_translations do
match do |actual|
missing_i18n_js = /\[missing ".*" translation\]/
missing_i18n_ruby = /class="translation_missing"/
!!(actual.body.match(missing_i18n_ruby) || actual.body.match(missing_i18n_js))
end
@tcdowney
tcdowney / raspbian-sd-longetivity.sh
Created June 3, 2018 03:13
Raspbian SD Longetivity Commands
# Inspired by https://raspberrypi.stackexchange.com/questions/169/how-can-i-extend-the-life-of-my-sd-card
# Gonna see if I can get by with just disabling swap for now
# Disable SWAP
sudo dphys-swapfile swapoff && \
sudo dphys-swapfile uninstall && \
sudo update-rc.d dphys-swapfile remove
@tcdowney
tcdowney / rename_ga.rb
Created May 21, 2019 01:55
Hacky rename of Intro to Graduate Algorithms videos to get sorted correctly on Kindle Fire
leading_digit_regex = /\d+\s+/
path = '/Users/tcdowney/Downloads/ga-vids'
Dir.glob("#{path}/*.mp4") do |mp4_file|
filename = File.basename(mp4_file, File.extname(mp4_file))
leading_digits = filename.match(leading_digit_regex)[0].to_i
padded_digits = sprintf('%03d', leading_digits)
padded_filename = filename.gsub(leading_digits.to_s, padded_digits)
#puts padded_filename + File.extname(mp4_file)
File.rename(mp4_file, padded_filename + File.extname(mp4_file))

Keybase proof

I hereby claim:

  • I am tcdowney on github.
  • I am tcdowney (https://keybase.io/tcdowney) on keybase.
  • I have a public key whose fingerprint is 90C8 2606 77B1 FF63 34C1 1DEE 301B 9993 40D5 E292

To claim this, I am signing this object: