Skip to content

Instantly share code, notes, and snippets.

@brenes
brenes / README.md
Last active June 29, 2020 11:23
ActiveRecord PostgreSQL adapter extension to deal with the Aurora Serverless hanging issue.

There's an issue reported in ruby-pg (ged/ruby-pg#325) where a query hangs and never return results to the application.

This adapter extension controls it with a ruby timeout set to 5 seconds. If the query doesn't return results in 5 seconds it aborts the async_exec method and tries the exec one.

We're not proud of this vut it saved a lot of erratic errors.

@brenes
brenes / pagespeed_code.gs
Last active December 29, 2022 16:23
Page SPeed monitorization through Google Spreadsheet
// This script is based on https://ithoughthecamewithyou.com/post/automate-google-pagespeed-insights-with-apps-script
// STEP 0: Create a spreadsheet document on Google Drive, go to the code editor
// (in spanish "Editor de la secuencia de comandos").
// Then paste this code and modify it.
// STEP 1: Insert your pagespeed API KEY
var pageSpeedApiKey = '';
// STEP 2: Insert the monitored URL
@brenes
brenes / gemas.org
Last active April 3, 2019 14:54
ideas charlas

Formación de crear gemas

¿Qué es una gema?

  • Librería de código
  • Relación con los proyectos
  • ¿Porqué trabajar con gemas?
@brenes
brenes / application.html.erb
Created November 20, 2017 08:33 — forked from Dagnan/application.html.erb
Inline CSS or JS in Rails 5
<!DOCTYPE html>
<html>
<head>
<%= inline_js 'application.js' %>
<%= inline_css 'application.css' %>
</head>
<body>
</body>
</html>
@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')
@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 / 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 / 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

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 / 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: