Skip to content

Instantly share code, notes, and snippets.

@vagnerzampieri
vagnerzampieri / generate_articles.rb
Created November 26, 2022 02:20
rspec sidekiq_retries_exhausted without gem
# frozen_string_literal: true
module Books
class GenerateArticlesJob
include Sidekiq::Worker
sidekiq_options retry: 1
sidekiq_retries_exhausted do |message, exception|
Rollbar.error(exception, message)
# Watermarking image with another image using Imagemagick 'composite', 'watermark' and 'dissolve'.
require "rmagick"
Dir.entries("./target").each_slice(7) do |group|
group.each do |target_photo|
next if target_photo == "." || target_photo == ".."
# This is necessary to don't explode your memory
GC.start
GC.disable
@vagnerzampieri
vagnerzampieri / Makefile
Created September 11, 2015 15:02
Install dependencies in Mac with brew
# Dependencies
# Usage:
# make
default: install
install: dependencies mysql memcached elasticsearch redis
dependencies: qt5
brew tap homebrew/services
@vagnerzampieri
vagnerzampieri / all_spec.ssh
Created September 4, 2015 21:36
Pegar todos os arquivos que foram modificados no git, olhar dentro deles por paths do VCR, encontrar os paths reais, deletar e depois rodar as specs
#!/bin/bash
vcr='(VCR)'
all_bettewen_quotes='(\".+\")'
declare -a files
count=0
# Read file and get all cassettes from VCR
while read line; do
if [[ $line =~ $vcr ]]; then
[[ $line =~ $all_bettewen_quotes ]]
@vagnerzampieri
vagnerzampieri / .bashrc
Last active August 29, 2015 14:13
Docker rails .bashrc
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac
@vagnerzampieri
vagnerzampieri / migration.rb
Created October 31, 2014 18:06
Migration with constraint to foreign_key.
class CreateComments < ActiveRecord::Migration
def change
create_table :comments do |t|
t.references :post, null: false
t.references :user, null: false
t.text :description
t.timestamps
end
@vagnerzampieri
vagnerzampieri / nginx
Created October 2, 2014 17:07
Script to start nginx
#! /bin/sh
### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the nginx web server
# Description: starts nginx using start-stop-daemon
class DocumentUploader < CarrierWave::Uploader::Base
storage :file
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
def extension_white_list
%w(pdf)
end
@vagnerzampieri
vagnerzampieri / gist:d810a82a25395f3e0772
Created July 25, 2014 17:08
Remove containers and images from docker
#For remove containers
sudo docker ps -a | grep Exit | awk '{print $1}' | sudo xargs docker rm
#For remove images
sudo docker rmi imageid
@vagnerzampieri
vagnerzampieri / .bash_profile
Last active August 29, 2015 14:04
Bash from Dockerfile
export PS1='\[\e[01;30m\]\t `if [ $? = 0 ]; then echo "\[\e[32m\]✔"; else echo "\[\e[31m\]✘"; fi` \[\e[00;37m\]\u@\h\[\e[01;37m\] : `[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit, working directory clean" ]] && echo "\[\e[31m\]" || echo "\[\e[32m\]"`$(__git_ps1 "(%s)\[\e[00m\]")\[\e[01;34m\]\w\[\e[00m\] \n\$ '
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
tmux -2