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"
@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:

@porras
porras / .bash_profile
Created June 25, 2013 08:29
Changing terminal color in MacOSX when SSHing
# Changing terminal color in MacOSX when SSHing (so you know at a glance that you're no longer in Kansas)
# Adapted from http://www.rngtng.com/2011/01/14/mac-os-x-terminal-visual-indication-for-your-ssh-connection/
# 1. Create a theme in your terminal setting with the name "SSH" and the desired colors, background, etc.
# 2. Add this to your .bash_profile (or .bashrc, I always forget the difference ;))
# 3. Optional but useful: in the terminal, go to Settings > Startup and set "New tabs open with" to
# "default settings" (otherwise, if you open a new tab from the changed one, you get a local tab with
# the SSH colors)
function tabc() {
NAME=$1; if [ -z "$NAME" ]; then NAME="Default"; fi # if you have trouble with this, change

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
class A
private
def self.a
:a
end
end
class B
class << self