Skip to content

Instantly share code, notes, and snippets.

@porras
porras / triple_dots.rb
Created January 10, 2020 17:40
Example of a usecase of Ruby 2.7 triple dot notation for writing method wrappers
def original_method(a, b)
puts "Called with #{a} and #{b}"
if block_given?
puts "Calling the block"
yield
end
end
def wrapper1(*args) # WRONG: doesn't pass the block
puts "Hi I'm wrapper1"

New beginners group starting next Monday (2018-11-05 19:00)

Hi!

We're starting a new beginners group next Monday. Most people that already confirmed that they'll be part of it attended the last Rails Girls Berlin Beginners Workshop, but feel free to join too if you didn't, it doesn't matter. The group will study the basics of programming starting from scratch, and following this curriculum: http://ruby-for-beginners.rubymonstas.org/

The group meets every Monday at 19:00 in Friedrichschain: http://rubymonstas.org/location.html There's more info about the group at http://rubymonstas.org/

The meetup usually lasts until 21:30/22:00, with a break in between. Feel free to bring snacks!

class RespondTo
def initialize(method_name)
@method_name = method_name
end
def ===(object)
object.respond_to?(@method_name)
end
end
@porras
porras / Dockerfile
Created March 20, 2017 13:00
Dockerfile and wrapper script for a nanoc project
FROM ruby:2.4
ADD Gemfile /opt/
ADD Gemfile.lock /opt/
WORKDIR /opt
RUN bundle install
CMD bundle exec nanoc -v
@porras
porras / config.ru
Last active February 27, 2017 14:14
require 'sinatra/base'
class A < Sinatra::Base
get '/this' do
'this from A'
end
end
class B < Sinatra::Base
get '/that' do
class CachedEnumerable
include Enumerable
def initialize(wrapped = nil)
@enumerator = case wrapped
when Enumerator
wrapped
when Enumerable
wrapped.to_enum
when NilClass
@porras
porras / xargs.md
Last active August 31, 2021 14:54

This is my best try at transcribing of the lightning talk I gave at RUG::B on April 2016. Due to poor time management (LOL) the delivery was rushed and some examples were skipped, I hope having them posted here makes them more useful.

xargs

xargs is a small but very useful program that is installed in most if not all of your computers¹. Many of you probably know it. Those who don't will learn something really useful, but those who do will learn a couple of cool tricks, too.

Why xargs

You might have heard about the Unix philosophy:

class C
class << self; public :public, :protected, :private; end
private
@porras
porras / randomname.rb
Last active October 6, 2015 18:56
Small ruby script to get a random name from a list (for a raffle or something like that)
# Usage: Save the file somewhere, in a terminal run:
# ruby <path/to/file.rb>
#
puts DATA.each_line.to_a.sample
__END__
Write
The
Names