Skip to content

Instantly share code, notes, and snippets.

@amcaplan
amcaplan / 2.5.9-results.txt
Created September 5, 2021 18:24
Surprising Ruby benchmark results for Array#unshift: 2.5.9 vs 2.6.0
Warming up --------------------------------------
Array#unshift 1.000 i/100ms
Array#push 16.000 i/100ms
Calculating -------------------------------------
Array#unshift 0.428 (± 0.0%) i/s - 3.000 in 7.014513s
Array#push 178.573 (± 9.0%) i/s - 896.000 in 5.064291s
Comparison:
Array#push: 178.6 i/s
Array#unshift: 0.4 i/s - 417.41x (± 0.00) slower
@amcaplan
amcaplan / life_world_wrap_gliders.rb
Created November 18, 2020 12:54
RubyConf 2020 demo code: Conway's Game of Life with and without caching intermediates
require 'get_process_mem'
require 'curses'
initial_map = <<~MAP
............................
............................
.....O......O......O......O.
......O......O......O......O
....OOO....OOO....OOO....OOO
............................
@amcaplan
amcaplan / keybase.md
Created June 21, 2018 20:56
keybase.md

Keybase proof

I hereby claim:

  • I am amcaplan on github.
  • I am amcaplan (https://keybase.io/amcaplan) on keybase.
  • I have a public key ASAFHXSVvATC51ryFNZVN6jlYOELqTwuJRiP8YLAcRxJSgo

To claim this, I am signing this object:

@amcaplan
amcaplan / migration_rails_versions.sh
Last active March 12, 2018 16:03
Fill in ActiveRecord Migration Rails Versions by shell script (tested on Mac OS X)
# Instructions
#
# 1. Backup your repo somewhere!
# 2. Make sure `git stash list` is empty - that'll help debugging in case things go wrong.
# 3. Make sure `git status` shows that you've made no changes; that'll break things right away.
# 4. Copy and paste the code below.
# 5. Run the `update_timestamps` function and LET IT FINISH!
# 6. Check the results, make sure they look reasonable, and commit!
#
# P.S. I take no responsibility for your use of the script; I recommend understanding what it does before running it.
@amcaplan
amcaplan / script.rb
Created July 3, 2017 18:58
.gitmodules generation script
# Assumes all your submodules are accessed via SSH, not HTTPS
template = <<-TEMPLATE
[submodule "%{submodule}"]
path = vim/.vim.symlink/bundle/%{submodule}
url = %{submodule_url}
ignore = dirty
TEMPLATE
puts Dir.foreach('.').reject { |i| %w(. .. script.rb).include? i }.map { |dir|
@amcaplan
amcaplan / rails_engine_notes.md
Last active November 5, 2015 19:00
Rails Engines

Setting Up

$ rails plugin new forget --mountable --skip-test-unit --dummy-path=spec/dummy
$ git init
$ git add .
$ git commit -m "Initial commit - generate a Rails Engine called Forget"
@amcaplan
amcaplan / collatz.rb
Last active August 29, 2015 14:00
Collatz Conjecture (aka Project Euler Problem 14) using Benchmark library - don't copy, the point is to solve it yourself!
require 'benchmark'
class Collatz
@@collatzes = {1 => 1}
def self.max_chain_starter_under(highest)
(1...highest).max_by { |option| Collatz.new(option).length }
end
def initialize(num)
<!-- Begin Student -->
<li class="home-blog-post">
<div class="blog-thumb">
<a href="students/student_name.html">
<img width="304" height="304" class="prof-image" src="img/students/Caplan_headshot.png" class="attachment-blog-thumb wp-post-image" alt="student_name">
</a>
</div>
<div class="blog-title">
<div class="big-comment">