Skip to content

Instantly share code, notes, and snippets.

@jonduarte
jonduarte / Gemfile
Created December 3, 2021 14:16 — forked from dhh/Gemfile
HEY's Gemfile
ruby '2.7.1'
gem 'rails', github: 'rails/rails'
gem 'tzinfo-data', '>= 1.2016.7' # Don't rely on OSX/Linux timezone data
# Action Text
gem 'actiontext', github: 'basecamp/actiontext', ref: 'okra'
gem 'okra', github: 'basecamp/okra'
# Drivers
@jonduarte
jonduarte / docker_env_cleanup.sh
Created August 20, 2019 09:51 — forked from iarlyy/docker_clean_up.sh
docker env cleanup
docker rm $(docker ps -q -f status=exited)
docker volume rm $(docker volume ls -qf dangling=true)
docker rmi $(docker images --filter "dangling=true" -q --no-trunc)
docker rmi $(docker images | grep "<none>" | awk "{print $3}") -f
class UserDiscount < ApplicationRecord
belongs_to :user
belongs_to :discount
def self.invalid_user_discounts
UserDiscount.
joins("INNER JOIN discount_segments ON user_discounts.discount_id = discount_segments.discount_id").
joins("INNER JOIN user_segments ON user_discounts.user_id = user_segments.user_id").
where("user_segments.segment_id <> discount_segments.segment_id")
end
require 'typhoeus'
require 'json'
# 1. Get data from http
# 2. Parsing JSON
# 3. Calculate score
# 4. Show score
class Http
attr_reader :client
@jonduarte
jonduarte / parser.rb
Created January 4, 2018 22:16
Parser HTTP em Ruby
class Parser
END_OF_HEADERS = /\r\n\r\n/
attr_accessor :method, :version, :headers, :path
def initialize
@data = ""
@completed = false
@headers = {}
end
@jonduarte
jonduarte / fabricator.rb
Last active December 21, 2017 00:53
How to fabricate hashes and open structures
# spec/fabricators/stuff.rb
Fabricator(:one_stuff, from: :open_struct) do
name 'Pedro'
end
Fabricator(:second_stuff, from: :hash) do
after_build do |s|
s['name'] = 'Jose'
end
eval "$(rbenv init -)"
alias be="bundle exec"
alias gg='git grep -i'
source $(brew --prefix)/etc/bash_completion
export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/latest/bin
GIT_PS1_SHOWDIRTYSTATE=true
export PS1='[\u@mbp \w$(__git_ps1)]\$ '
if [ -n "$DISPLAY" -a "$TERM" == "xterm" ]; then
export TERM=xterm-256color
fi
" Pathogen
execute pathogen#infect()
syntax on
" load ctrlp
set runtimepath^=~/.vim/bundle/ctrlp.vim
" set <Leader> key as "," originally was \
let mapleader=","
@jonduarte
jonduarte / fake-s3-config.rb
Created December 1, 2016 14:55 — forked from ktopping/fake-s3-config.rb
fake s3 config
# Add the following to /etc/hosts:
127.0.0.1 local.s3.endpoint local-bucket.local.s3.endpoint
# Run the following in your rails console, in order to create a bucket:
s3=AWS::S3.new(
:access_key_id => 'anything',
:secret_access_key => 'anything',
:s3_endpoint => 'local.s3.endpoint',
:s3_port => 4567,
:use_ssl => false
@jonduarte
jonduarte / rbenv.sh
Last active August 29, 2015 14:27
Install Rbenv Ubuntu
sudo apt-get update
sudo apt-get install git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev python-software-properties libffi-dev
git clone git://github.com/sstephenson/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc