Skip to content

Instantly share code, notes, and snippets.

Yorick Peterse YorickPeterse

Block or report user

Report or block YorickPeterse

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
YorickPeterse /
Created Mar 3, 2014
Universal Ruby Environment/Mode Variables

This Gist aims to get some discussion going and throw some ideas around about introducing a more universal way to configure the environment/mode of Ruby applications and libraries (where applicable).

When speaking about the environment/mode (referred to as "environment" from this point on) we're speaking about the variable/option that specifies a alternative set of configuration options to use. That is, separate database options, hostnames and so on. A basic example of this is the standard Rails database configuration file:

YorickPeterse / syntax.rake
Created Mar 7, 2014
Checking the syntax of various Ruby related files in a Rails project.
View syntax.rake
namespace :syntax do
desc 'Checks the syntax of ERB files'
task :erb do
require 'action_view'
Dir['app/views/**/*.erb'].each do |file|
template =
ActionView::Template::Handlers::Erubis \
View gist:9652463
with Rubinius.synchronize:
$ ./bin/benchmark core/file/bench_each_byte.rb
=== rbx ===
File#each_byte with a small file
29.1 (±0.0%) i/s - 146 in 5.023101s (cycle=2)
File#each_byte with a medium file
3.3 (±0.0%) i/s - 17 in 5.228034s (cycle=1)
File#each_byte with a large file
0.3 (±0.0%) i/s - 2 in 6.110730s (cycle=1)
View mri_211.out
desc: (none)
cmd: ruby rss_growth_during_redis_publish.rb -n 1000000
time_unit: i
View growth.patch
diff --git a/rss_growth_during_redis_publish.rb b/rss_growth_during_redis_publish.rb
index f6d1526..cecfdef 100755
--- a/rss_growth_during_redis_publish.rb
+++ b/rss_growth_during_redis_publish.rb
@@ -8,6 +8,14 @@ require 'celluloid/io' # Unclear if this is required, or if Celluloid will hand
require 'celluloid/redis'
require 'celluloid/autostart' do
+ loop do
YorickPeterse / basic_lexer.rl
Last active Aug 29, 2015
Basic boilerplate for Ragel and Ruby, extracted from Oga.
View basic_lexer.rl
# Since public domain doesn't exist everywhere in the world and people might
# actually want to use this snippet here's the license (you can leave out
# the lines preceding it):
# Copyright (c) 2014, Yorick Peterse
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
View gist:190a87a31634eea5ef07
#!/usr/bin/env bash
# Small wrapper around the actual command used to start the daemon. This
# wrapper allows us to set various environment variables before Ruby is
# started.
# See the following URLs for more information on these options and their
# values:
View gist:f848b62a81e249067f3b
[yorickpeterse in oga]$ pry -r ./lib/oga
2.1.2p95 >'/div[@class="container"]/div[@class="review"]').parse
=> (xpath
(name nil "div")
(axis "attribute" "class")
(string "container")))
(name nil "div")
View gist:29db9183c79f6ffd7844
2.1.2p95 > require 'csv'
=> true
2.1.2p95 > headers = %w{foo bar}
=> ["foo", "bar"]
2.1.2p95 > row =, [10, 20])
=> #<CSV::Row "foo":10 "bar":20>
2.1.2p95 >
=> [true, true]
2.1.2p95 > headers.first.upcase!
RuntimeError: can't modify frozen String
View gist:c861d7140f836f6c622b
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x0 pc=0x418efd]
goroutine 16 [running]:
runtime.panic(0x668940, 0x80ae73)
/build/go/src/go-1.3/src/pkg/runtime/panic.c:279 +0xf5
main.(*typeConv).Type(0xc20804e160, 0x7f06feab87c8, 0xc208d700c0, 0x53203, 0xc208d2b801)
/build/go/src/go-1.3/src/cmd/cgo/gcc.go:1288 +0x1f2d
main.(*typeConv).Type(0xc20804e160, 0x7f06feab8730, 0xc208d70060, 0x53203, 0x0)
You can’t perform that action at this time.