Skip to content

Instantly share code, notes, and snippets.

View CarlosCD's full-sized avatar

Carlos A. Carro Duplá CarlosCD

  • Firstup
  • Maryland, USA
View GitHub Profile
@CarlosCD
CarlosCD / echo.rb
Last active December 8, 2022 20:08
Echo server (testing some webhooks locally)
#!/usr/bin/env ruby
# frozen_string_literal: true
%w(json webrick).each do |gem_name|
begin
Gem::Specification.find_by_name(gem_name)
rescue Gem::MissingSpecError
puts "Installing the '#{gem_name}' Ruby gem..."
system "gem install #{gem_name}"
end
@CarlosCD
CarlosCD / ssl_puma.sh
Created June 1, 2021 14:03 — forked from tadast/ssl_puma.sh
localhost SSL with puma
# 1) Create your private key (any password will do, we remove it below)
$ cd ~/.ssh
$ openssl genrsa -des3 -out server.orig.key 2048
# 2) Remove the password
$ openssl rsa -in server.orig.key -out server.key
@CarlosCD
CarlosCD / suppress_ruby_output.rb
Created February 2, 2021 17:08 — forked from moertel/suppress_ruby_output.rb
Temporarily suppress STDOUT and STDERR (ruby)
# Temporarily redirects STDOUT and STDERR to /dev/null
# but does print exceptions should there occur any.
# Call as:
# suppress_output { puts 'never printed' }
#
def suppress_output
original_stderr = $stderr.clone
original_stdout = $stdout.clone
$stderr.reopen(File.new('/dev/null', 'w'))
$stdout.reopen(File.new('/dev/null', 'w'))
@CarlosCD
CarlosCD / safe.md
Created October 2, 2020 15:29 — forked from bryanrite/safe.md
Safe Postgres Operations on High Volume Tables

Originally taken from: Braintree Article and expanded on by me.

Safe

  • Add a new column
  • Drop a column
  • Rename a column
  • Add an index concurrently (Example), Note: it will still take a long time to run the migration, but it won't write-lock the table.
  • Drop a constraint (for example, non-nullable)
  • Add a default value to an existing column
require 'nokogiri'
require 'open-uri'
# Get a Nokogiri::HTML:Document for the page we're interested in...
doc = Nokogiri::HTML(open('http://www.google.com/search?q=tenderlove'))
# Do funky things with it using Nokogiri::XML::Node methods...
####
@CarlosCD
CarlosCD / git_messages.sh
Created July 27, 2018 18:42
Analysis of words used in commit messages
# All by order of frequency:
git log --pretty=format:'%s' | cut -d " " -f 1 | sort | uniq -c | sort -nr
# Angry developers:
git log --pretty=format:'%s' | tr '[:upper:]' '[:lower:]' | tr '[:space:]' '\n' | sort | uniq -c | sort -nr | grep -iE "(fuck|shit|bitch|damn|piss)"
@CarlosCD
CarlosCD / gist:ef55c0ca0b04a671d9be4ae3085bc61f
Last active January 4, 2018 18:52
Array#flatten in Ruby
# Array#flatten in Ruby (exercise).
# Added as an Array instance method, with the name 'flattening'
class Array
def flattening
flat_me(self)
end
private
@CarlosCD
CarlosCD / mongoid-accepts_embedded_resource_for.gemspec
Created January 27, 2016 17:52 — forked from johnbintz/mongoid-accepts_embedded_resource_for.gemspec
Add accepts_embedded_resources_for to Mongoid::NestedAttributes
Gem::Specification.new do |s|
s.name = 'mongoid-accepts_embedded_resource_for'
s.version = '0.1.0'
s.platform = Gem::Platform::RUBY
s.author = 'John Bintz'
s.email = 'john@coswellproductions.com'
s.summary = 'Add accepts_embedded_resources_for to Mongoid::NestedAttributes, so it plays nicer with Carrierwave and embedded documents'
s.description = 'Add accepts_embedded_resources_for to Mongoid::NestedAttributes, so it plays nicer with Carrierwave and embedded documents'
s.files = ['mongoid-accepts_embedded_resource_for.rb']
@CarlosCD
CarlosCD / draper-mongoid.gemspec
Created January 27, 2016 17:48 — forked from johnbintz/draper-mongoid.gemspec
Ensure Mongoid documents work with Draper
Gem::Specification.new do |s|
s.name = 'draper-mongoid'
s.version = '0.1.0'
s.platform = Gem::Platform::RUBY
s.author = 'John Bintz'
s.email = 'john@coswellproductions.com'
s.summary = 'Quick little hack to make Mongoid work with Draper wrt model_name'
s.description = 'Quick little hack to make Mongoid work with Draper wrt model_name'
s.files = ['draper-mongoid.rb']
@CarlosCD
CarlosCD / export_dbs.rb
Last active January 14, 2016 19:19
Migrating local PostgreSQL databases in my laptop, when upgrading the server (in this case 9.4 to 9.5)
#!/usr/bin/env ruby
# See: http://postgresapp.com/documentation/install.html
dumping_folder = 'dump'
expected_header = " List of databases\n" +
" Name | Owner | Encoding | Collate | Ctype | Access privileges \n" +
"-------------------------------------+--------+----------+-------------+-------------+-------------------\n"
databases = `psql --list`