Skip to content

Instantly share code, notes, and snippets.

View spalenza's full-sized avatar

Rodolfo Spalenza spalenza

  • RDStation
  • Vitória - ES - Brazil
View GitHub Profile
@spalenza
spalenza / irb.rb
Created July 2, 2019 18:23 — forked from joshuapinter/irb.rb
Activate Authlogic in Console
if defined?(ActiveRecord::Base) && defined?(Authlogic)
controller = ApplicationController.new
require 'action_controller/test_case'
controller.instance_variable_set(:@_request, ActionController::TestRequest.new)
controller.instance_variable_set(:@_response, ActionController::TestResponse.new)
Authlogic::Session::Base.controller = Authlogic::ControllerAdapters::RailsAdapter.new(controller)
end
UserSession.new( User.first )
@spalenza
spalenza / rails_race_condition.rb
Created March 21, 2019 13:10
Rails Race Condition - Pessimistic Locking
def update(i)
ActiveRecord::Base.transaction do
sleep(0.5)
id = 5928598
person = Person.lock.find(id)
person.name = "Rodolfo#{i}"
person.save!
end
end
@spalenza
spalenza / get_recipes.js
Last active October 26, 2018 18:56
List OpsWorks Custom Recipes
function getRecipes(id) {
return $.map($('*[data-region="' + id + '"] li.opaque'), function(elem) {
return $(elem).text().replace('remove', '').trim();
})
};
var setupRecipes = getRecipes('CustomRecipes.Setup');
var configureRecipes = getRecipes('CustomRecipes.Configure');
var deployRecipes = getRecipes('CustomRecipes.Deploy');
var undeployRecipes = getRecipes('CustomRecipes.Undeploy');
@spalenza
spalenza / migration_sql.rb
Last active May 23, 2019 20:33 — forked from xaviershay/migration_sql.rb
Get SQL output from a Rails migration
#!/usr/bin/env ruby
require_relative 'config/environment'
path = ARGV.shift || raise("specify migration as first argument")
require_relative path
filename = File.basename(path, ".rb")
timestamp, name = filename.split("_", 2)
@spalenza
spalenza / dynamic_view_paths.rb
Last active May 7, 2018 17:19
render specific partial
before_filter :set_view_paths
def index
end
private
def set_view_paths
prepend_view_path 'projects/override'
end
@spalenza
spalenza / slides.md
Created November 29, 2017 16:32 — forked from shadowmaru/slides.md
Palestras da RubyConf BR 2017
# config/unicorn.rb
worker_processes Integer(ENV["WEB_CONCURRENCY"] || 3)
timeout 60
preload_app true
before_fork do |server, worker|
Signal.trap 'TERM' do
puts 'Unicorn master intercepting TERM and sending myself QUIT instead'
Process.kill 'QUIT', Process.pid
end
@spalenza
spalenza / mysql-largest-tables.sh
Created March 27, 2017 22:31 — forked from xurizaemon/mysql-largest-tables.sh
Show largest tables (optionally, in a specific DB)
#!/bin/bash
if [ -z $1 ] ; then
SQL="
SELECT
CONCAT(table_schema, '.', table_name) 'Table',
CONCAT(ROUND(( data_length + index_length ) / ( 1024 * 1024 * 1024 ), 2), 'G') 'Tot Size',
CONCAT(ROUND(table_rows / 1000000, 2), 'M') 'Rows',
CONCAT(ROUND(data_length / ( 1024 * 1024 * 1024 ), 2), 'G') 'Data',
CONCAT(ROUND(index_length / ( 1024 * 1024 * 1024 ), 2), 'G') 'Idx',
@spalenza
spalenza / mysql-largest-tables.sh
Created March 27, 2017 22:31 — forked from xurizaemon/mysql-largest-tables.sh
Show largest tables (optionally, in a specific DB)
#!/bin/bash
if [ -z $1 ] ; then
SQL="
SELECT
CONCAT(table_schema, '.', table_name) 'Table',
CONCAT(ROUND(( data_length + index_length ) / ( 1024 * 1024 * 1024 ), 2), 'G') 'Tot Size',
CONCAT(ROUND(table_rows / 1000000, 2), 'M') 'Rows',
CONCAT(ROUND(data_length / ( 1024 * 1024 * 1024 ), 2), 'G') 'Data',
CONCAT(ROUND(index_length / ( 1024 * 1024 * 1024 ), 2), 'G') 'Idx',
@spalenza
spalenza / config.js
Created February 5, 2017 08:49
Rails 5 - Webpack
// Example webpack configuration with asset fingerprinting in production.
'use strict';
var path = require('path');
var webpack = require('webpack');
var StatsPlugin = require('stats-webpack-plugin');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
// must match config.webpack.dev_server.port
var devServerPort = 3808;