Skip to content

Instantly share code, notes, and snippets.

View thijsc's full-sized avatar

Thijs Cadier thijsc

View GitHub Profile
class Tosti
def self.validate(*ingredients, preparation_method)
ingredients.include?(:brood) && ingredients.length > 1 && preparation_method == :grill
end
end
class Tosti
def self.validate(*ingredients)
ingredients.include?(:brood) && preparation_method == :grill
end
end
@thijsc
thijsc / gist:2652300
Created May 10, 2012 10:18
Professional delete this code after date x spec
scenario "make sure this feature is removed after July 1st" do
raise('Remove this feature!') if Time.now > Time.parse('2012-07-01')
end
@thijsc
thijsc / example.rs
Last active January 29, 2016 13:08
For Harm
use std::env;
fn main() {
let first = env::args().nth(1);
match first {
Some(ref value) if value == "create" => println!("in create"),
Some(_) => println!("smt else"),
None => println!("No arg given")
}
}
@thijsc
thijsc / Gemfile
Created July 6, 2017 14:58
Sequel standalone example
source 'https://rubygems.org'
gem 'sequel'
gem 'sqlite3'
gem 'appsignal'
@thijsc
thijsc / Gemfile
Created July 10, 2017 19:16
Barebones standalone Ruby app with AppSignal
source 'https://rubygems.org'
gem "appsignal"
@thijsc
thijsc / benchmark.rb
Created December 6, 2017 12:12
Naive Ruby backtrace benchmark
require "benchmark"
puts(Benchmark.measure {
1_000_000.times do
1 + 1
end
})
puts(Benchmark.measure {
1_000_000.times do
@thijsc
thijsc / assignment.rb
Last active August 8, 2020 09:07
Little wrapper script around Kafka command line tools to assign topics.
#!/usr/bin/env ruby
require "fileutils"
require "json"
ZOOKEEPER = raise "Put your zookeeper list here"
DEFAULT_BROKER_LIST = raise "put your broker list here (1,2,3)
FileUtils.rm_f "/tmp/topics.json"
FileUtils.rm_f "/tmp/assignment.json"
@thijsc
thijsc / screenshots.rake
Last active February 3, 2021 22:38
Example of creating screenshots of your site using Capybara and Selenium, for details: http://blog.appsignal.com/blog/2015/07/21/automated-screenshots-using-capybara.html
BROWSER_WIDTH = 1600
BROWSER_HEIGHT = 1200
Capybara.default_driver = :selenium
include Capybara::DSL
def take_screenshot(path, name, convert_options={})
# Wait for JS to load data and so on
sleep 2
retinafy_screen
@thijsc
thijsc / gist:1391107
Created November 24, 2011 11:08
Select item from chosen js select with Capybara and Selenium
def select_from_chosen(item_text, options)
field = find_field(options[:from])
option_value = page.evaluate_script("$(\"##{field[:id]} option:contains('#{item_text}')\").val()")
page.execute_script("$('##{field[:id]}').val('#{option_value}')")
end