Skip to content

Instantly share code, notes, and snippets.

View carpodaster's full-sized avatar

Carsten Zimmermann carpodaster

  • Vim
View GitHub Profile

Coach Guide

You heard about Rails Girls and want to be a coach? Here you’ll find all you need to know what coaching actually means.

What it takes to be a coach

First of all, Coaches are patient, tolerant and open people! This goes for everything, but also for technologies and solutions you might not chose for yourself. Whether or not you like RSpec or TestUnit, ERB or Haml, or whatever text editor you prefer does not matter to students at all. They are in a learning position and whatever gets them started, curious and eager to learn is a perfect tool – no matter your personal preferences. Keep in mind that your preferences – just like "common knowledge of the community" – is a result of a long, long learning process which you, and the community have gone through. Give your students the same chance to discover. Our goal is to get people started, learning and staying excited about coding!

@carpodaster
carpodaster / anonymous_class_name.rb
Created February 16, 2014 12:41
Difficulties accessing an anonymous class' name in its superclass' self.inherited
require 'minitest/autorun'
class BaseBuilder
class << self
attr_accessor :klass
end
def self.inherited(subclass)
super
subclass.klass = (subclass.name || subclass.to_s).gsub(/Builder\z/, '')
@carpodaster
carpodaster / firewall.rb
Last active August 29, 2015 13:56
Spec'ing a Rack middleware-based firewall/blacklist
class Firewall < Struct.new(:app)
class << self
def blacklist
@blacklist ||= ['192.0.2.1'].freeze # Example IP, see RFC 5735
end
end
def call(env)
if self.class.blacklist.include? env['HTTP_X_FORWARDED_FOR']
@carpodaster
carpodaster / in-memory-db.rb
Created November 20, 2013 11:35
Dynamically create an ActiveRecord class with an in-memory database
ActiveRecord::Base.establish_connection adapter: 'sqlite3', database: ':memory:'
ActiveRecord::Base.connection.execute <<-EOSQL
CREATE TABLE in_memory_records(
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
name TEXT
);
EOSQL
Object.const_set 'InMemoryRecord', Class.new(ActiveRecord::Base)
@carpodaster
carpodaster / 999.crlwatch.sh
Last active December 26, 2015 18:49
Periodically checking for CRL validity w/ Event Girl integration
#!/usr/bin/env bash
CRLFILE=/root/certs/crl/crl.pem
DAYS=14
EVENT_GIRL_SITE=https://event-girl.herokuapp.com
EVENT_GIRL_TOKEN=myeventgirlaccesstoken
source /usr/local/rvm/environments/ruby-2.0.0-p247
class ExternalService
include RateLimiter
def self.work_with_users
rate_limit 20, 2.0, User.find_each do |user|
# Do stuff with each user.
# Pause 2 seconds every 20 iterations
end
end
end
@carpodaster
carpodaster / convert_errors_on.sh
Created January 5, 2012 14:52
Converts errors.on(:foo) to errors[:foo] when upgrading to Rails 3
#!/usr/bin/env bash
#
# This small piece of sed converts the obj.errors.on(:foo) calls in
# a single file to the new obj.errors[:foo] syntax as introduced in Rails 3
FILE=$1
function check_and_backup_file() {
if [ -e "$FILE" ]; then
cp $FILE $FILE.orig