Skip to content

Instantly share code, notes, and snippets.

View dmke's full-sized avatar

Dominik Menke dmke

View GitHub Profile
@dmke
dmke / README.md
Last active August 29, 2015 14:22
Ruby Symbol GC

Just a small benchmark to clear up the myth, Ruby wouldn'd garbage collect any Symbols. In fact, MRI 2.2.0 introduced Symbol GC in December 2014 (see notable changes in the release announcement).

The benchmark is quite simple: It basically cretes a bunch of Symbols via String#to_sym and counts Symbol::all_symbols afterwards.

I've used rbenv to test the Symbol GC (or the lack thereof) of these interpreter implementations:

  • 1.9.3-p551
  • 2.0.0-p645
  • 2.1.6
  • 2.2.2
@dmke
dmke / example.rb
Last active August 29, 2015 14:15
Hexdump in Ruby
random_twitter_message = (1..140).map{ rand 0xFF }.pack("C*")
hexdump random_twitter_message
# 0000: af 98 02 2b 25 13 01 42 b8 cd 3a a5 23 07 c2 43 |...+%..B ..:.#..C|
# 0010: c0 af bd 65 3e a7 c0 4c 26 b9 1e 54 cc c3 5b 3f |...e>..L &..T..[?|
# 0020: db d6 86 76 22 d4 31 ab 32 fe b6 32 f4 d4 1c 01 |...v".1. 2..2....|
# 0030: f6 5d 25 8c 64 9b 18 3a 9d 50 14 a2 86 79 a6 f2 |.]%.d..: .P...y..|
# 0040: da 50 f3 70 b6 bc e4 76 15 db 2f b7 f6 9c 88 d0 |.P.p...v ../.....|
# 0050: 63 95 23 66 b3 20 f6 ab 62 a6 28 92 c7 6d a9 e0 |c.#f. .. b.(..m..|
# 0060: 1c 2d fe 12 3e fd 8b 95 47 4d b2 14 07 e8 6b 6c |.-..>... GM....kl|
@dmke
dmke / edit.html.haml
Created March 31, 2014 15:23
Devise registration form, prepared for Bootstrap 3 (w/o Simple Form)
-# app/views/devise/registrations/edit.html.haml
%h1.page-header
Edit
= resource_name.to_s.humanize
= form_for resource, as: resource_name, url: registration_path(resource_name), html: { method: :put, class: 'form-horizontal' } do |f|
= devise_error_messages!
.form-group
$ ruby -v
ruby 2.1.1p76 (2014-02-24 revision 45161) [x86_64-linux]
$ ruby re_bench.rb
Rehearsal --------------------------------------------------------
(?-mix:^[a-zA-Z]$) 0.780000 0.000000 0.780000 ( 0.783924)
(?i-mx:^[a-z]$) 0.790000 0.000000 0.790000 ( 0.789410)
(?-mix:\A[a-zA-Z]\z) 0.370000 0.000000 0.370000 ( 0.373894)
(?i-mx:\A[a-z]\z) 0.370000 0.000000 0.370000 ( 0.373349)
----------------------------------------------- total: 2.310000sec