Skip to content

Instantly share code, notes, and snippets.

View yorickpeterse's full-sized avatar

Yorick Peterse yorickpeterse

View GitHub Profile
@yorickpeterse
yorickpeterse / env_madness.md
Created March 3, 2014 10:34
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
yorickpeterse / syntax.rake
Created March 7, 2014 14:35
Checking the syntax of various Ruby related files in a Rails project.
namespace :syntax do
desc 'Checks the syntax of ERB files'
task :erb do
require 'action_view'
Dir['app/views/**/*.erb'].each do |file|
template = File.read(file)
begin
ActionView::Template::Handlers::Erubis \
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)
desc: (none)
cmd: ruby rss_growth_during_redis_publish.rb -n 1000000
time_unit: i
#-----------
snapshot=0
#-----------
time=0
mem_heap_B=0
mem_heap_extra_B=0
mem_stacks_B=0
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'
+Thread.new do
+ loop do
@yorickpeterse
yorickpeterse / basic_lexer.rl
Last active August 29, 2015 13:59
Basic boilerplate for Ragel and Ruby, extracted from Oga.
# 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
#!/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:
#
# http://samsaffron.com/archive/2014/04/08/ruby-2-1-garbage-collection-ready-for-production
[yorickpeterse in oga]$ pry -r ./lib/oga
2.1.2p95 > Oga::XPath::Parser.new('/div[@class="container"]/div[@class="review"]').parse
=> (xpath
(path
(name nil "div")
(eq
(axis "attribute" "class")
(string "container")))
(path
(name nil "div")
2.1.2p95 > require 'csv'
=> true
2.1.2p95 > headers = %w{foo bar}
=> ["foo", "bar"]
2.1.2p95 > row = CSV::Row.new(headers, [10, 20])
=> #<CSV::Row "foo":10 "bar":20>
2.1.2p95 > headers.map(&:frozen?)
=> [true, true]
2.1.2p95 > headers.first.upcase!
RuntimeError: can't modify frozen String
require 'gir_ffi-gtk3'
require 'sequel'
GirFFI.setup :GtkSource
Gtk.init
Thread.abort_on_exception = true
client = Sequel.connect(