Skip to content

Instantly share code, notes, and snippets.

View ElMassimo's full-sized avatar
🎵

Máximo Mussini ElMassimo

🎵
View GitHub Profile
require 'benchmark'
ITERATIONS = 1_000_000
def rename(source, dest)
{ source: source, dest: dest }
end
def literal_work
ITERATIONS.times do
@ElMassimo
ElMassimo / benchmark_to_proc.rb
Created December 7, 2015 20:53
Benchmark to_proc
require 'benchmark'
class User
def initialize(first_name:, last_name:, email:)
@first_name, @last_name, @email = first_name, last_name, email
end
def to_s
"#{ @first_name } #{ @last_name } (#{ @email })"
end
@ElMassimo
ElMassimo / upgrade_mongo.sh
Created December 11, 2015 16:22
Upgrade to Mongo 3.0.7
#!/bin/bash
echo "Requesting initial permissions (necessary to start and stop services)"
sudo echo "OK"
if [[ "$(uname)" == 'Darwin' ]]; then
platform='osx'
DB_PATH='/usr/local/var/mongodb'
LOG_PATH='/usr/local/var/log/mongodb/mongo.log'
CONFIG_PATH='/usr/local/etc/mongod.conf'
BACKUP_PATH="$HOME/mongobackups"
@ElMassimo
ElMassimo / .git-prompt-colors.sh
Last active August 25, 2016 11:36
Bash Git Prompt
override_git_prompt_colors() {
GIT_PROMPT_THEME_NAME="Custom"
PathShort="\W" # Display only the current folder
# Display the current folder first
GIT_PROMPT_START_USER="${Green}${PathShort}"
GIT_PROMPT_START_ROOT="${Green}${PathShort}"
# Skip the default prefix
@ElMassimo
ElMassimo / mongoid_no_heritage.rb
Created October 12, 2015 23:19
Mongoid: No Heritage
module Mongoid
# Public: Allows to use inheritance to reuse logic, without using Single-
# Collection Inheritance, storing the model and superclass in different
# collections.
module NoHeritage
extend ActiveSupport::Concern
included do
# Internal: Preserve the default storage options instead of storing in the
@ElMassimo
ElMassimo / decorated_bands_controller.rb
Created April 3, 2017 10:49
Rails CRUD Controller using Draper
class BandController < ApplicationController
def new
@band = Band.new.decorate
end
def create
@band = Band.new(band_params)
if @band.save
redirect_to(@band)
else
@ElMassimo
ElMassimo / thread_with_context.rb
Last active April 19, 2017 08:07
Thread with access to a shared Request Context
# Public: Module that overrides Thread initialization to preserve the request context.
module ThreadWithContext
# Public: Returns a new Thread that preserves the context of the current request.
def new(*args)
request_id = Thread.current[:request_id]
super(*args) {
Thread.current[:request_id] = request_id
yield *args
}
@ElMassimo
ElMassimo / trailing_spaces_settings.json
Created June 6, 2017 19:09
Trailing Spaces Settings
{
"trailing_spaces_enabled": true,
"trailing_spaces_modified_lines_only": false,
"trailing_spaces_trim_on_save": true
}
@ElMassimo
ElMassimo / convert_all
Created September 7, 2017 18:08
Music Conversion (MP3 to WMA and WAV to MP3)
#!/bin/bash
find . "(" -iname "*.mp3" ")" -print0 | xargs -0 -I file mv file "../music/$file"
find . "(" -iname "*.wma" ")" -print0 | xargs -0 -I file ./convert_file file
@ElMassimo
ElMassimo / bands_controller.rb
Last active December 21, 2017 17:20
Sample Rails CRUD Controller
class BandController < ApplicationController
def new
@band = Band.new
end
def create
@band = Band.new(band_params)
if @band.save
redirect_to(@band)
else