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 / 20161204173835_create_video.exs
Last active December 17, 2016 18:49
Ecto Migration
defmodule Rumbl.Repo.Migrations.CreateVideo do
use Ecto.Migration
def change do
create table(:videos) do
add :url, :string
add :title, :string
add :description, :text
add :user_id, references(:users, on_delete: :nothing)
@spalenza
spalenza / .vimrc
Created November 24, 2016 01:06
Vim command to ruby new hash notation
command! -range=% RubyNewHashNotation silent execute <line1>.','.<line2>.'s/:\(\w\+\)\s*=>\s*/\1: /g'
@spalenza
spalenza / .irbrc
Created November 22, 2016 21:29
Enable and disable pry
def enable_pry
ENV['DISABLE_PRY'] = nil
end
def disable_pry
ENV['DISABLE_PRY'] = 'true'
end
@spalenza
spalenza / autopgsqlbackup
Created September 28, 2016 00:14 — forked from matthewlehner/autopgsqlbackup
Auto PostgreSQL backup script.
#!/bin/bash
#
# PostgreSQL Backup Script Ver 1.0
# http://autopgsqlbackup.frozenpc.net
# Copyright (c) 2005 Aaron Axelsen <[email protected]>
#
# This script is based of the AutoMySQLBackup Script Ver 2.2
# It can be found at http://sourceforge.net/projects/automysqlbackup/
#
# The PostgreSQL changes are based on a patch agaisnt AutoMySQLBackup 1.9
@spalenza
spalenza / gist:d24200b5cfe0c2e55447
Created February 19, 2016 17:31
vim copy file path
" Convert slashes to backslashes for Windows.
if has('win32')
nmap ,cs :let @*=substitute(expand("%"), "/", "\\", "g")<CR>
nmap ,cl :let @*=substitute(expand("%:p"), "/", "\\", "g")<CR>
" This will copy the path in 8.3 short format, for DOS and Windows 9x
nmap ,c8 :let @*=substitute(expand("%:p:8"), "/", "\\", "g")<CR>
else
nmap ,cs :let @*=expand("%")<CR>
nmap ,cl :let @*=expand("%:p")<CR>
@spalenza
spalenza / clean_concurrent_jobs.rb
Last active June 3, 2019 18:49
Remove Resque Workers
# busca as chaves de um processo específico
Resque.redis.keys('*.DailyReportCachedProcessor')
# => ["concurrent.count.DailyReportCachedProcessor", "concurrent.queue_availability.DailyReportCachedProcessor", "concurrent.queue.high.DailyReportCachedProcessor"]
# verifique quantos jobs dessse processo estao rodando no resque
# utilize a chave concurrent.count.* para setar
Resque.redis.set('concurrent.count.DailyReportCachedProcessor', 8)
# limpar a lista
@spalenza
spalenza / forms.rb
Created January 5, 2016 02:31
Namespace stuff in your app/ folder
# config/initializers/forms.rb
Rails.application.config.to_prepare do
path = Rails.root + "app/forms"
ActiveSupport::Dependencies.autoload_paths -= [path.to_s]
reloader = ActiveSupport::FileUpdateChecker.new [], path.to_s => [:rb] do
ActiveSupport::DescendantsTracker.clear
ActiveSupport::Dependencies.clear
Dir[path + "**/*.rb"].each do |file|
ActiveSupport.require_or_load file
end
@spalenza
spalenza / kill_function.sh
Last active November 23, 2015 18:30
kill process of specifies screen
killRailsCScreen() {
screen_id=`screen -ls | grep $1 | cut -d'.' -f1 | awk '{print $1}'`
if [ ! -z "$screen_id" -a "$screen_id" != " " ]; then
rails_id=`ps elax | grep $screen_id | grep '[r]ails c' | awk '{print $3}'`
if [ ! -z "$rails_id" -a "$rails_id" != " " ]; then
`kill -9 $rails_id`
return 0
else
@spalenza
spalenza / rake_completion.sh
Created October 15, 2015 19:51
rake completion
function _rake_cache_path() {
# If in a Rails app, put the cache in the cache dir
# so version control ignores it
if [ -e 'tmp/cache' ]; then
prefix='tmp/cache/'
fi
echo "${prefix}.rake_t_cache"
}
function rake_cache_store() {
@spalenza
spalenza / remove_resque_jobs.rb
Created October 15, 2015 14:10
Remove Resque jobs
# Reference
# http://stackoverflow.com/questions/10274974/how-can-i-delete-specific-jobs-from-resque-queue-without-clearing-the-whole-queu
# Removes a job from a queue. Expects a string queue name, a
# string class name, and, optionally, args.
#
# Returns the number of jobs destroyed.
#
# If no args are provided, it will remove all jobs of the class
# provided.
#