Skip to content

Instantly share code, notes, and snippets.

View carpodaster's full-sized avatar

Carsten Zimmermann carpodaster

  • Vim
View GitHub Profile
@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
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 / 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
@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 / 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 / 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/, '')

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 / active_model_lint.rb
Last active August 29, 2015 14:00
ActiveModel::Lint for rspec
# Provides an rspec version https://github.com/rails/rails/blob/master/activemodel/lib/active_model/lint.rb
# Approaches like https://gist.github.com/msgehard/910773 do not seem to work with
# current versions of minitest.
#
# Usage:
# 1. Put file in spec/support
# 2. Add it_behaves_like 'ActiveModel' in your spec file
shared_examples_for 'ActiveModel' do
let(:model) { subject }
@carpodaster
carpodaster / Xmodmap
Created June 29, 2015 08:13
Original Xmodmap bindings for F7 to F12
keycode 73 = F7 F7 F7 F7 F7 F7 XF86Switch_VT_7 F7 F7 XF86Switch_VT_7 F7 F7 F7 F7 XF86Switch_VT_7
keycode 74 = F8 F8 F8 F8 F8 F8 XF86Switch_VT_8 F8 F8 XF86Switch_VT_8 F8 F8 F8 F8 XF86Switch_VT_8
keycode 75 = F9 F9 F9 F9 F9 F9 XF86Switch_VT_9 F9 F9 XF86Switch_VT_9 F9 F9 F9 F9 XF86Switch_VT_9
keycode 76 = F10 F10 F10 F10 F10 F10 XF86Switch_VT_10 F10 F10 XF86Switch_VT_10 F10 F10 F10 F10 XF86Switch_VT_10
keycode 95 = F11 F11 F11 F11 F11 F11 XF86Switch_VT_11 F11 F11 XF86Switch_VT_11 F11 F11 F11 F11 XF86Switch_VT_11
keycode 96 = F12 F12 F12 F12 F12 F12 XF86Switch_VT_12 F12 F12 XF86Switch_VT_12 F12 F12 F12 F12 XF86Switch_VT_12

Keybase proof

I hereby claim:

  • I am carpodaster on github.
  • I am carpmeister (https://keybase.io/carpmeister) on keybase.
  • I have a public key ASDrqstqUezWWJR9DL24pQkvi4cPxgVRQAj-koCjsUEEtQo

To claim this, I am signing this object: