Skip to content

Instantly share code, notes, and snippets.

View jarib's full-sized avatar

Jari Bakken jarib

View GitHub Profile
@bmarini
bmarini / default.vcl.pl
Created June 30, 2011 18:01
A good varnish config for a Rails app
# https://www.varnish-cache.org/docs/2.1/tutorial/vcl.html
# https://www.varnish-cache.org/trac/wiki/VCLExamples
# Summary
# 1. Varnish will poll the backend at /health_check to make sure it is
# healthy. If the backend goes down, varnish will server stale content
# from the cache for up to 1 hour.
# 2. Varnish will pass X-Forwarded-For headers through to the backend
# 3. Varnish will remove cookies from urls that match static content file
# extensions (jpg, gif, ...)
@jarib
jarib / gist:1039225
Created June 21, 2011 23:34
selenium-webdriver downloads (past year)
Total downloads: 215395
linux : 112168 (52.00%)
macosx : 84828 (39.00%)
jruby : 9433 (4.00%)
windows : 8397 (3.00%)
bsd : 526 (0.00%)
solaris : 27 (0.00%)
x86-unknown : 9 (0.00%)
x86_64-unknown : 7 (0.00%)
@jarib
jarib / file.rb
Created June 14, 2011 13:02
selenium-webdriver bug report template
require 'rubygems'
require 'selenium-webdriver'
path = File.expand_path("test.html")
File.open(path, "w") { |io| io << DATA.read }
browser = Selenium::WebDriver.for :firefox # replace :firefox with the browser you're having trouble with
begin
browser.get "file://#{path}"
@mrflip
mrflip / RUNME-demo_of_async_fibers.log
Created April 25, 2011 20:57
A fully-commented demo showing execution flow in the fibers+eventmachine => linear asynchronous code pattern
>> load './RUNME-demo_of_async_fibers.rb'
/Users/flip/ics/backend/son_of_a_batch/RUNME-demo_of_async_fibers.rb:4: warning: already initialized constant FIBER_IDXS
814e5e90 0 f_0 beg main top level
814e5e90 1 f_0 beg em setup this block sets up the eventmachine execution, but no execution-order shenanigans yet
814e5e90 2 f_0 beg fiber stp the end-the-reactor block won't be called for 1.5s, so we get here immediately.
814e5e90 3 f_0 end fiber stp nothing from inside the Fiber.new{} block has run yet.
814e5e90 4 f_0 end fiber stp kick off the fiber...
80d829a0 5 f_1 beg fiber when my_fiber.resume is called, this runs. Now in a new fiber
80d829a0 6 f_1 beg get_result get_result is called from within fiber_1
80d829a0 7 f_1 setup callback set up some code to run 1.5s from now
@jarib
jarib / uname.rb
Created March 31, 2011 00:28
uname() - ruby ffi
require 'ffi'
module Uname
extend FFI::Library
ffi_lib FFI::CURRENT_PROCESS
class UtsName < FFI::Struct
layout :sysname , [:char, 256],
:nodename, [:char, 256],
@jarib
jarib / properties.rb
Created February 28, 2011 19:56
java.util.Properties-like class for Ruby
# encoding: utf-8
# Pure-ruby java.util.Properties-like class
class Properties < Hash
REGEXP = %r{
\A\s* # ignore whitespace at BOL
([^\s\#;]+?) # the variable cannot contain spaces or comment characters
\s*=\s* # ignore whitespace around the equal sign
([^\#;]*?) # the value cannot contain comment characters
\s* # ignore whitespace at end of line
@jarib
jarib / gist:774802
Created January 11, 2011 17:58
fx launch debug script
require "rubygems"
require "selenium-webdriver"
$DEBUG = true
profile = Selenium::WebDriver::Firefox::Profile.new
profile.log_file = File.expand_path("firefox.log")
profile.log_file.gsub!("/", "\\") if Selenium::WebDriver::Platform.windows?
begin
@jarib
jarib / clang.rb
Created December 28, 2010 01:47
Spike of FFI wrapper for libclang
require 'rubygems'
require 'ffi'
module Clang
module Lib
extend FFI::Library
ffi_lib "clang"
attach_function :create_index, :clang_createIndex, [:int, :int], :pointer
Creating the bundled JRuby jar
==============================
Let's say we want to bundle these gems:
- Antwrap
- json_pure
- albacore
1. Check out JRuby HEAD
git clone git://github.com/jruby/jruby.git
@jarib
jarib / browserbot.rb
Created November 23, 2010 23:17
IE driver - reductions
require 'rubygems'
require 'selenium-webdriver'
require 'ext-tempfile'
script = <<S
var browserbot = {
triggerEvent: function(element, eventType, canBubble, controlKeyDown, altKeyDown, shiftKeyDown, metaKeyDown) {
canBubble = (typeof(canBubble) == undefined) ? true: canBubble;
if (element.fireEvent && element.ownerDocument && element.ownerDocument.createEventObject) {
// IE