Skip to content

Instantly share code, notes, and snippets.

shepmaster /
Last active March 11, 2020 05:21 — forked from kelcecil/
Implementation of binary search tree in OCaml and Rust (modeled after the OCaml solution).

Here's two implementations of a binary search tree in OCaml and Rust. The Rust version was written to deliberately look as close to the OCaml as possible (and it'd get pretty close if I used match instead of OCaml's variants). I'm pretty sure my OCaml implementation is idiomatic, and I'd like some advice on what steps I'd probably take to make the Rust example more idiomatic. My objective is to talk about how close the examples can be to each other as well as how different the examples can be (hopefully demonstrating strengths for both.)

Any other thoughts or ideas are also helpful and super appreciated!

shepmaster /
Created September 22, 2014 00:54 — forked from bgamari/
$ rustc 34:27 error: `cursors` does not live long enough for cur in cursors.iter() {
^~~~~~~ 47:2 note: reference must be valid for the lifetime 'a as defined on the block at 26:67... (dict: &'a SuffixTree<E>, mut iter: Iter) -> Vec<Match<'a, E>> { let mut offset: uint = 0; let mut cursors: Vec<Cursor<E>> = Vec::new(); let mut matches = Vec::new();
def new
@transaction_fee = current_company.transaction_fee
@transaction_cost = current_company.transaction_cost
@withdrawal =
@available_amount = Withdrawal.available_amount(
@transactions = current_company.transactions.where("payment_status = 'ready_to_pay'")
shepmaster / dna.rb
Last active December 22, 2015 11:28 — forked from alekst/dna.rb
class DNATest < MiniTest::Unit::TestCase
# You don't have to put your classes inside of the test case, but it
# doesn't hurt for these examples
class DNA
def initialize(string)
@string = string
# You can provide a default value for hashes. This also avoids
# hardcoding the letters here.
@counts =
shepmaster / anagram.rb
Last active December 22, 2015 07:18 — forked from alekst/gist:6436407
class AnagramTest < MiniTest::Unit::TestCase
class Anagram
def initialize(word)
@word = word
@anagram =
def match(candidates)
candidates.each do |candidate|
if candidate.turning_into_letters == @word.turning_into_letters
shepmaster / anagram.rb
Last active December 22, 2015 06:18 — forked from alekst/anagram
class AnagramTest < MiniTest::Unit::TestCase
class Anagram
def initialize(word)
@word = word
# If you create the array here, then the results will be
# collected over multiple calls to `match`. Not sure if that is
# intended or not, so I'll assume it's ok to change.
shepmaster / spec.rb
Last active December 20, 2015 05:39 — forked from enricostano/spec.rb
describe 'conversations/base' do
subject do
Timecop.freeze(10.minutes.ago) do
before :each do
assign(:object, subject)
require 'spec_helper'
describe Api::V1_2::TokensController do
def parsed_response(response)
describe "POST create" do
let(:params) { {} }
var x = function(userid) {
return function(resp) {
var user_name = JSON.parse(resp)["full_name"];
build += "<li><a class='user' id='user-" + userid + "' href='#show-" + userid + "'>" + user_name + "</a></li>";
remaining -= 1;
if (remaining == 0) {
make_users_list(obj, build);
['a','b','c'].each do |char|
it "returns xxx for #{char}" do
process(char).should == 'xxx'