Skip to content

Instantly share code, notes, and snippets.

@brenes
brenes / custom_mini_profiler.rb
Last active August 29, 2015 14:21
Utility class for decorating a method and adding the information to the rach mini profiler summary
# Simple class to decorate a method and send information MiniProfiler
# Usage: CustomMiniProfiler.measure MyClass, :mymethod, "This method takes..."
class CustomMiniProfiler
def self.measure klass, method, message, class_method=false
receptor_class = class_method ? klass.singleton_class : klass
receptor_class.send :define_method, "#{method}_with_mini_profiler" do |*args, &block|
Rack::MiniProfiler.step(message) do
send "#{method}_without_mini_profiler", *args, &block
end
@brenes
brenes / instructions
Created June 8, 2015 09:34
Repairing non-monotic index git error
> git fetch
...
error: non-monotonic index .git/objects/pack/pack-be03d54c63e1a503114461d4c1945b34c7af01c8.idx
...
> rm .git/objects/pack/pack-be03d54c63e1a503114461d4c1945b34c7af01c8.idx
> git index-pack .git/objects/pack/pack-be03d54c63e1a503114461d4c1945b34c7af01c8.pack
{
"browser" : true,
"jquery" : true,
"devel" : true,
"curly" : true,
"latedef" : true,
"maxdepth" : 3,
"newcap" : true,
"noarg" : true,
"noempty" : true,
@brenes
brenes / slack.css
Last active February 12, 2016 12:28
Stylish for slack
@namespace url(http://www.w3.org/1999/xhtml);
@-moz-document domain("slack.com") {
.bot_message {
font-size:12px;
color: #CCC;
}
.bot_message .member_image {
height: 16px;
@brenes
brenes / xargs.md
Created April 14, 2016 10:46 — forked from porras/xargs.md

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:

Delete local merged branches: git branch --merged | xargs -I BRANCH git branch -d BRANCH
Delete remote merged branches: git branch -r --merged | grep -v '^*' | grep -v master | sed 's/origin\///g' | xargs -I BRANCH -P 10 git push origin :BRANCH
@brenes
brenes / libros.md
Last active March 29, 2018 14:17
Lista de libros

Esta lista es el primer paso en mi proceso de deshacerme de libros.

Quien me conoce sabe lo mucho que me importan mis libros y lo que me duele separarme de ellos.

Algunos me han gustado, otros los he abandonado (perdona, Paul Auster). Todos me han hecho como soy, y creo que es hora de que se vayan a otros hogares a formar a otras personas.

Si has llegado aquí y quieres alguno de los libros, soy @brenes en Twitter.

Libros disponibles

@brenes
brenes / character_set_and_collation.rb
Created June 23, 2016 13:33 — forked from tjh/character_set_and_collation.rb
Convert all Rails table column collation and character set
#!/usr/bin/env ruby
# Put this file in the root of your Rails project,
# then run it to output the SQL needed to change all
# your tables and columns to the same character set
# and collation.
#
# > ruby character_set_and_collation.rb
DATABASE = ''
@brenes
brenes / application_controler.rb
Created August 8, 2016 11:42
Rails multiple request variants
# This code is an example to combine different variants from different reasons into the request.variant setting from Rails 4.1
before_action :set_versions
def set_versions
# First, we load all the variants from whatever our variant logic is (mobile support, tests ab, beta versions...)
variants = []
variants << params[:b].to_sym if params[:b]
variants << params[:a].to_sym if params[:a]
@brenes
brenes / sidekiq.rb
Last active August 18, 2021 09:55
Sidekiq configuration pero host type (AWS TAG)
require 'aws-sdk'
Sidekiq.configure_server do |config|
#.....
ec2 = Aws::EC2::Resource.new(region: 'eu-west-1')
# we build the name if the instance, based on the hostname
i = ec2.instance(Socket.gethostname.gsub(/^[^-]*-/, ''))
# we get its tags and check if it's the desired one
if i.tags.map(&:value).includes('priority-batch')