Skip to content

Instantly share code, notes, and snippets.

View rgm's full-sized avatar

Ryan McCuaig rgm

View GitHub Profile
(define (fib n)
(if (< n 2)
n
(+ (fib (- n 1)) (fib (- n 2)))))
;; becomes
(controller
(assign continue (label fib-done))
fib-loop
@rgm
rgm / explicit-control.scm
Created June 19, 2014 06:14
The explicit-control evaluator from SICP §5.4
;; Explicit control evaluator from SICP 5.4
;; required "machine" operations from underlying Scheme
(define eceval-operations
(list (list 'self-evaluating? self-evaluating)
(list 'variable? variable)
;... etc
;self-evaluating?
;variable?
;quoted?
@rgm
rgm / .vimrc
Last active August 29, 2015 14:04
Alternate file finder for Meteor
function! MeteorOpenAlternate(opener, type)
let alternate = system("meteor_find_alternate " . expand("%:p") . " " . a:type)
execute a:opener . " " . alternate
endfunction
nnoremap <leader>mU :call MeteorOpenAlternate("e", "test")<CR>
nnoremap <leader>mu :call MeteorOpenAlternate("vsplit", "test")<CR>
nnoremap <leader>mT :call MeteorOpenAlternate("e", "template")<CR>
nnoremap <leader>mt :call MeteorOpenAlternate("vsplit", "template")<CR>

Keybase proof

I hereby claim:

  • I am rgm on github.
  • I am rgm (https://keybase.io/rgm) on keybase.
  • I have a public key whose fingerprint is 0CD9 C99D 37E0 3EA1 B9BD 4BC2 8E4A CF9B DAC2 D396

To claim this, I am signing this object:

@rgm
rgm / arith.rb
Last active August 29, 2015 14:06
TAPL ch. 3, but with more Ruby!
# The untyped calculus of booleans and numbers
#
# TaPL, Pierce 2002, ch. 3 & 4
#
# IRB examples:
#
# if true then false else 0
# arith_eval make_if(predicate: make_yep, consequent: make_nope, alternative: make_zero)
# => nope
#
@rgm
rgm / gist:e670f333ae91553031a8
Last active November 10, 2023 21:33
FizzBuzz in the untyped λ-calculus, as approximated by Ruby stabby procs. courtesy of @tomstuart.
-> k { -> f { -> f { -> x { f[-> y { x[x][y] }] }[-> x { f[-> y { x[x][y] }] }]
} [-> f { -> l { -> x { -> g { -> b { b }[-> p { p[-> x { -> y { x } }]
}[l]][x] [-> y { g[f[-> l { -> p { p[-> x { -> y { y } }] }[-> p { p[-> x { ->
y { y } }] } [l]] }[l]][x][g]][-> l { -> p { p[-> x { -> y { x } }] }[-> p {
p[-> x { -> y { y } }] }[l]] }[l]][y] }] } } } }][k][-> x { -> y { -> f {
f[x][y] } } }[-> x { -> y { x } }][-> x { -> y { x } }]][-> l { -> x { -> l {
-> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { ->
f { f[x][y] } } } [x][l]] } }[l][f[x]] } }] } }[-> f { -> x { f[-> y { x[x][y]
}] }[-> x { f[-> y { x[x][y] }] }] }[-> f { -> m { -> n { -> b { b }[-> m { ->
n { -> n { n[-> x { -> x { -> y { y } } }][-> x { -> y { x } }] }[-> m { -> n {
def login_as (tenant, role)
unless $logged_in_as == [tenant, role]
step 'I am on the login page'
step 'I sign in as a ' + tenant + ' ' + role
step 'I click "Log In"'
step 'I sign in as a ' + tenant + ' ' + role
step 'I click "Log In"'
find 'div.dashboard'
$logged_in_as = [tenant, role]
end
# https://www.youtube.com/watch?v=FITJMJjASUs
puts ->() {
pred = ->(n) { n - 1 } # let's pretend no operators
fact_improver = ->(partial) {
->(n) { n.zero? ? 1 : n * partial.(pred.(n)) }
}
require 'test_helper'
class PermanentRedirectTest < ActionDispatch::IntegrationTest
# in all cases, no matter how byzantine the setup, the goals are:
# 1. get new episodes without the user having to re-subscribe
# 2. don't fire out duped episodes if we can help it.
test "gentlemanly df-style itunes redirect" do
podcast = create_itunes_redirected_podcast \
#!/usr/bin/env xcrun swift
protocol SomeType { }
extension SomeType {
func maybeGreeting(noReally: Bool) -> String? {
return (noReally ? "howzit" : nil)
}
}