Skip to content

Instantly share code, notes, and snippets.

Carsten Zimmermann carpodaster

View GitHub Profile
View benchmark.txt
Ruby version: 2.6.1
Run with: `ruby pirate_combo.rb`
user system total real
nested map, small array 0.009232 0.000084 0.009316 ( 0.009315)
nested map, huge array 27.279118 0.510522 27.789640 ( 27.790889)
flat map, small array 0.002179 0.000043 0.002222 ( 0.002219)
flat map, huge array 12.483256 0.087956 12.571212 ( 12.571798)
Array#product, small array 0.001514 0.000000 0.001514 ( 0.001513)
Array#product, huge array 5.079583 0.000002 5.079585 ( 5.080144)
View concurrent_csv_exports1.rb
require 'thread'
WORKERS = 3
queue = SizedQueue.new(WORKERS * 2)
# Backlog some work! Using a separate thread since push operation on
# SizedQueue may block when it's "full"
Thread.new { MyModel.find_in_batches { |batch| queue << batch } }
readio, writeio = IO.pipe
View maybe_date.rb
# frozen_string_literal: true
require 'minitest/autorun'
require 'date'
class MaybeDate < SimpleDelegator
include Comparable
def initialize(date = nil, default: 9999)
date = begin
@carpodaster
carpodaster / string_split_vs_rpartition.rb
Created Oct 11, 2018
Benchmarking String#split and String#rpartition
View string_split_vs_rpartition.rb
# frozen_string_literal: true
require 'benchmark'
input = "This::Is::One::Heavily::Nested::Module"
n = 1_000_000
Benchmark.bm do |benchmark|
benchmark.report("String#split") do
@carpodaster
carpodaster / latin1encoding_part1.ex
Created Feb 10, 2017
Elixir: Converting Latin1-encoded HTML to UTF-8
View latin1encoding_part1.ex
defmodule Latin1Convert do
@doc """
Convert an input HTML string to UTF-8 unicode.
"""
@spec call(String.t) :: String.t
def call(html) do
content_type = content_type_from_header(html)
cond do
content_type == :latin1 ->
@carpodaster
carpodaster / downcase_benchmark.rb
Created Dec 1, 2016
Benchmarking German non-ascii downcase
View downcase_benchmark.rb
require 'benchmark'
string = "HELLO WÖRLD WHÜTS ÄP?"
n = 500_000
# Using String#tr in one fell swoop
tr_single = ->(n, str) { n.times { str.tr('A-ZÄÜÖ', 'a-zäüö') } }
# Chaining outputs of String#tr
View keybase.md

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:

@carpodaster
carpodaster / Xmodmap
Created Jun 29, 2015
Original Xmodmap bindings for F7 to F12
View Xmodmap
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
@carpodaster
carpodaster / active_model_lint.rb
Last active Aug 29, 2015
ActiveModel::Lint for rspec
View active_model_lint.rb
# 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 }
View coachguide.md

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!

You can’t perform that action at this time.