Skip to content

Instantly share code, notes, and snippets.

@bbuchalter
bbuchalter / case_test.rb
Last active May 25, 2022 11:31
Ruby can only parse 2498 case statement branches
case_statements = 10000
program = <<-RUBY
case(ARGV[1])
#{case_statements.times.map { |n| "when #{n+1} \n puts #{n+1}"}.join("\n")}
end
RUBY
File.write('test.rb', program)
puts "RUBY_VERSION=#{RUBY_VERSION}"
puts system('ruby test.rb')
@bbuchalter
bbuchalter / results.txt
Last active October 25, 2020 20:58
Are exceptions still slow in Ruby 2.7?
Warming up --------------------------------------
exception 74.658k i/100ms
break 588.320k i/100ms
return 551.993k i/100ms
Calculating -------------------------------------
exception 751.437k (±10.5%) i/s - 3.733M in 5.024957s
break 5.778M (± 1.2%) i/s - 29.416M in 5.091806s
return 5.444M (± 1.2%) i/s - 27.600M in 5.070550s
SET pagesize 30
set linesize 300
column "Tablespace" format a13
column "Used MB" format 99,999,999
column "Free MB" format 99,999,999
column "Total MB" format 99,999,999
column "Tablespace path" format a50
ttitle center 'Application tablespace' skip 2
SELECT fs.tablespace_name "Tablespace",
(df.totalspace - fs.freespace) "Used MB",
@bbuchalter
bbuchalter / where_is.rb
Created January 26, 2020 14:13 — forked from wtaysom/where_is.rb
A little Ruby module for finding the source location where class and methods are defined.
module Where
class <<self
attr_accessor :editor
def is_proc(proc)
source_location(proc)
end
def is_method(klass, method_name)
source_location(klass.method(method_name))
@bbuchalter
bbuchalter / README.md
Last active March 8, 2018 06:35
TILbot

TILbot

TILbot helps you reinforce what you learn. Get started by giving TILbot a question and answer, just like you were creating a flashcard. TILbot calls these TILcards. Congrats, this is your first act of learning reinforcement!

Your First TILcard

Let's say this is your first TILcard:

Question: What is the meaning of life, the universe and everything?

Answer: 42

@bbuchalter
bbuchalter / car.c
Created March 2, 2018 17:15
Infections, Hoare triples, and debugging by printouts
public class Car {
Seat[] seats;
//...
public int numEmptySeats() {
int count = 0;
int i;
// { count = 0 }
for(i = 0; i < this.seats.length; i++);
# Given a file containing order line items in the form [User ID]: [Medications] where medications are separated by commas, determine the pairs of medications that appear most frequently together.
# For example:
# Given two line items
# Zestril, atorvastatin, Levoxine
# Zestril, atorvastatin, Orasone
# The function should output the pair Zestril, atorvastatin.
# Create a calculator that takes integers separated by the basic mathematical operators (+,-,*,/) and returns the result.
# You can use Ruby's mathamatical methods(+, -, *, /).
# The priority is on working code, not brevity.
# 7 + 2 - 3 / 4 * 5 = 5.25
#math_characters = '7 + 2 - 3 / 4 * 5'
# magic
require 'minitest/autorun'
class TestMyFlatten < Minitest::Test
def test_deeply_nested_arrays
assert_equal [1,2,3,4], MyFlatten.new([[1,2,[3]],4]).flatten
end
def test_argument_error
assert_raises ArgumentError do
MyFlatten.new("not an array")
---
BUNDLE_GEM__COC: "false"
BUNDLE_GEM__TEST: "rspec"
BUNDLE_CONSOLE: "pry"
BUNDLE_JOBS: "4"
BUNDLE_DISABLE_LOCAL_BRANCH_CHECK: "true"
BUNDLE_PATH: "vendor/bundle"
BUNDLE_DISABLE_SHARED_GEMS: "1"
BUNDLE_BUILD__EVENTMACHINE: "--with-cppflags=-I/usr/local/opt/openssl/include"
BUNDLE_GEM__MIT: "false"