Skip to content

Instantly share code, notes, and snippets.

View hrs's full-sized avatar

Harry R. Schwartz hrs

View GitHub Profile
@hrs
hrs / aws-ssh.tf
Created April 11, 2023 17:05
Minimal Terraform configuration to create an SSH server on AWS.
# This builds a publicly available SSH server on EC2.
#
# Make sure to edit the path to your public SSH key.
#
# Log in:
#
# $ ssh ubuntu@$(terraform output -raw public_ip)
terraform {
required_providers {
require "nokogiri"
require "open-uri"
require "optparse"
require "set"
MAX_DEPTH = 2
class Page
def initialize(body:, url:)
@body = body
require "rspec/autorun"
# An implementation of an immutable binary search tree in Ruby, with a small
# suite of tests. Supports #==, #insert, #delete, and #to_a (an in-order
# traversal).
#
# To run the tests, just evaluate the file: `ruby binary_search_tree.rb`
class Leaf
def ==(other)
@hrs
hrs / update.sh
Created July 18, 2017 12:59
Updating your dsss17 repo while preserving your changes
# Supposing that you're starting on the master branch...
# Create a new branch and switch to it:
git checkout -b my-work
# Commit your changes on that branch:
git add .
git commit -m "My work so far!"
# Update the master branch:
@hrs
hrs / fizzbuzz.rb
Created March 31, 2015 21:49
Design Pattern Frolics!
class MessageDispatcher
def initialize
@observers = []
end
def register(observer)
@observers << observer
end
def dispatch(message)
@hrs
hrs / process_tree.rb
Created January 16, 2015 22:36
Generate a graph of the process tree
#!/usr/bin/env ruby
class UnixProcess
attr_reader :uid, :pid, :ppid, :cmd
def initialize(uid:, pid:, ppid:, cmd:)
@uid = uid
@pid = pid
@ppid = ppid
@cmd = cmd
@hrs
hrs / say_repl.rb
Created July 21, 2014 01:25
REPL for Say
#!/usr/bin/env ruby
class SayRepl
attr_reader :voice
def initialize(voice)
@voice = voice
end
def go
@hrs
hrs / pi.rb
Created July 17, 2014 16:38
Probabilistic calculation of pi in 56 characters
p (0..1000000).count{rand<Math.sqrt(1-rand**2)}/250000.0
### Keybase proof
I hereby claim:
* I am hrs on github.
* I am hrs (https://keybase.io/hrs) on keybase.
* I have a public key whose fingerprint is 1B41 8F2C 23DE DD9C 807E A74F 841B 3DAE 25AE 721B
To claim this, I am signing this object:
@hrs
hrs / named_wombat.rb
Last active August 29, 2015 14:02
Using attr_readers, attr_writers, and attr_accessors
# attr_reader/writers/accessors are handy shortcuts for creating
# getter and setter methods. That's all they're for.
# An attr_reader creates a getter method. For example, the following
# two classes have identical effects:
class NamedWombat
attr_reader :name
def initialize(name)