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 / 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 / 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 / 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 / .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 / 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 / drawer_activity.java
Created January 2, 2016 21:08
Drawer Activity in Java
package com.maximomussini.anko;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.NavigationView;
import android.support.design.widget.Snackbar;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
@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
@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 / sublime_config.json
Last active September 10, 2018 18:34
Maximo's Sublime Config
{
"always_show_minimap_viewport": true,
"auto_complete": false,
"bold_folder_labels": true,
"color_scheme": "Packages/Material Theme/schemes/Material-Theme-Darker.tmTheme",
"draw_white_space": "none",
"ensure_newline_at_eof_on_save": true,
"find_selected_text": true,
"font_face": "Fira Code",
"font_face": "Fira Code",