Skip to content

Instantly share code, notes, and snippets.

@shepmaster
shepmaster / README.md
Last active March 11, 2020 05:21 — forked from kelcecil/README.md
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
shepmaster / hello.rs
Created September 22, 2014 00:54 — forked from bgamari/hello.rs
$ rustc hong.rs
hong.rs:34:20: 34:27 error: `cursors` does not live long enough
hong.rs:34 for cur in cursors.iter() {
^~~~~~~
hong.rs:26:68: 47:2 note: reference must be valid for the lifetime 'a as defined on the block at 26:67...
hong.rs:26 (dict: &'a SuffixTree<E>, mut iter: Iter) -> Vec<Match<'a, E>> {
hong.rs:27
hong.rs:28 let mut offset: uint = 0;
hong.rs:29 let mut cursors: Vec<Cursor<E>> = Vec::new();
hong.rs:30 let mut matches = Vec::new();
def new
@transaction_fee = current_company.transaction_fee
@transaction_cost = current_company.transaction_cost
@withdrawal = current_company.withdrawals.new
@available_amount = Withdrawal.available_amount(current_company.id)
@transactions = current_company.transactions.where("payment_status = 'ready_to_pay'")
end
@shepmaster
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 = Hash.new(0)
@shepmaster
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 = Array.new
end
def match(candidates)
candidates.each do |candidate|
if candidate.turning_into_letters == @word.turning_into_letters
@shepmaster
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.
end
@shepmaster
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
FactoryGirl.create(:conversation)
end
end
before :each do
assign(:object, subject)
require 'spec_helper'
describe Api::V1_2::TokensController do
def parsed_response(response)
JSON.parse(response.body)
end
describe "POST create" do
let(:params) { {} }
var x = function(userid) {
return function(resp) {
var user_name = JSON.parse(resp)["full_name"];
console.log(userid);
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);
hide_spinner();
$("#login").hide();
['a','b','c'].each do |char|
it "returns xxx for #{char}" do
process(char).should == 'xxx'
end
end