Skip to content

Instantly share code, notes, and snippets.

Máximo Mussini ElMassimo

View GitHub Profile
View array_splat_benchmark.rb
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 Apr 19, 2017
Thread with access to a shared Request Context
View thread_with_context.rb
# 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
}
View mongoid_no_heritage.rb
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
View benchmark_to_proc.rb
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
View .git-prompt-colors.sh
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 Dec 11, 2015
Upgrade to Mongo 3.0.7
View upgrade_mongo.sh
#!/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 Jan 2, 2016
Drawer Activity in Java
View drawer_activity.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 Dec 21, 2017
Sample Rails CRUD Controller
View bands_controller.rb
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 Apr 3, 2017
Rails CRUD Controller using Draper
View decorated_bands_controller.rb
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 Sep 10, 2018
Maximo's Sublime Config
View sublime_config.json
{
"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",
You can’t perform that action at this time.