Skip to content

Instantly share code, notes, and snippets.

View size_aware_cache.cr
class SizeAwareCache
@@cache = {} of String => Hash(Int32, String)
def read(key : String, size : Int32)
if value = @@cache.dig?(key, size)
# Hit! (both key and size)
return value
elsif results = @@cache[key]?
# Key hit, size miss
sorted_results = results.to_a.sort_by(&.first)
View 2.4-bench.rb
require 'benchmark/ips'
def class_integer
0.class == Integer
end
def version_gte
RUBY_VERSION >= '2.4'
end
View caddy.dot
digraph G {
label="Caddy Architecture"
labelloc="top"
fontsize=20
fontname="Helvetica Neue"
node [shape="ellipse", style="filled", fontname="Helvetica Neue"]
edge [fontname="Helvetica Neue"]
peripheries=0
rankdir="LR"
subgraph clusterClient {
View first_to_finish.rb
module Enumerable
def first_to_finish
threads = collect { |args| Thread.new { yield(args) } }
loop until done = threads.detect { |t| !t.alive? }
threads.each(&:kill)
done.value
end
end
puts [5, 3, 1, 2, 4].first_to_finish { |x| sleep x }
View system_ruby_version.markdown

What is the system Ruby?

What version of Ruby shipped by default on Mac OS X?

* Refers to the fully patched version (e.g. 10.5.8, not 10.5.0). Earlier versions may have shipped with different Ruby patchlevels but the RUBY_VERSION has never changed within major Mac OS X releases.
Mac OS X version* Mac OS X release date Default Ruby version
View struct_bench.rb
require 'benchmark/ips'
require 'ostruct'
N = 100
ATTRS = (:aa..:zz).take(N)
HASH = Hash[ATTRS.map { |x| [x, x] }]
CStruct = Struct.new(*ATTRS)
def struct
View 1_class_refactored_solution.rb
def valid?(card_number)
digits = card_number
.split("")
.map { |number| number.to_i }
numbers = []
digits.each_with_index do |digit, index|
if index.even?
numbers << digit * 2
else
View stratus-customization.html
<script type="text/javascript">
$(document).ready(function(){
$.stratus({
auto_play: true,
download: false,
key: "Enter your Client ID here",
links: 'http://soundcloud.com/qotsa',
random: true
});
});
View stratus-installation.html
<script type="text/javascript">
$(document).ready(function(){
$.stratus({
key: "Enter your Client ID here",
links: "https://soundcloud.com/zedsdead/sets/somewhere-else-ep"
});
});
</script>
View exposable.rb
require 'set'
module Lotus
module Action
module Exposable
def self.included(base)
base.extend(ClassMethods)
end
module ClassMethods
You can’t perform that action at this time.