Skip to content

Instantly share code, notes, and snippets.

Avatar

Rafael Oliveira rafaelcgo

View GitHub Profile
View heroku-metrics-daemon.sh
#!/bin/bash
# From: https://github.com/heroku/heroku-buildpack-metrics/blob/master/.profile.d/heroku-metrics-daemon.sh
setup_metrics() {
# don't do anything if we don't have a metrics url.
if [[ -z "$HEROKU_METRICS_URL" ]] || [[ "${DYNO}" = run\.* ]]; then
return 0
fi
STARTTIME=$(date +%s)
@rafaelcgo
rafaelcgo / 1_definitions.rb
Last active Sep 24, 2015
Group_by with same attribute name or new attribute name
View 1_definitions.rb
date_start = Time.parse('11/08/2015').beginning_of_day
date_end = Time.parse('11/08/2015').end_of_day
created_at_day_tz = "date(created_at AT TIME ZONE \'UTC\'
AT TIME ZONE \'#{Time.zone.tzinfo.identifier}\')"
users = User.where("users.created_at BETWEEN ? AND ?", date_start, date_end)
View postgresql_timezones.rb
User.find(885).created_at
"Sun, 31 Aug 2014 22:10:54 BRT -03:00"
User.select('created_at as created_at').where(id: 885)
[#<User id: nil, created_at: "2014-09-01 01:10:54">]
User.select('date(created_at) as created_at').where(id: 885)
[#<User id: nil, created_at: "2014-09-01">]
!!!!!!!!! NÃO! haha. Era pro date ser 2014-08-31. !!!!!!!!!!!
@rafaelcgo
rafaelcgo / queries-users_from_activities_of_organization.rb
Last active Aug 29, 2015
queries-users_from_activities_of_organization.rb
View queries-users_from_activities_of_organization.rb
Organization.first.activities.map(&:users)
User.where(id: Organization.first.activity_users.pluck(:user_id))
User.includes(activity_users: {activities: :organizations}).where(organization_id: Organization.first)
User.includes(activity_users: {activity: :organization}).where(activities: {organization_id: Organization.first})
@rafaelcgo
rafaelcgo / gist:7adb887bf100bb2236df
Created Apr 28, 2015
Preferences.sublime-settings
View gist:7adb887bf100bb2236df
{
"auto_complete": true,
"auto_complete_commit_on_tab": true,
"color_scheme": "Packages/User/SublimeLinter/Monokai (SL).tmTheme",
"copy_with_empty_selection": true,
"ensure_newline_at_eof_on_save": true,
"font_size": 12,
"ignored_packages":
[
"Vintage"
@rafaelcgo
rafaelcgo / application.rb
Created Feb 25, 2015
Rails loading config from yaml
View application.rb
config.before_configuration do
env_file = File.join(Rails.root, 'config', 'local_env.yml')
YAML.load(File.open(env_file)).each do |key, value|
ENV[key.to_s] = value
end if File.exists?(env_file)
end
@rafaelcgo
rafaelcgo / .bashrc
Created Feb 10, 2015
.bashrc Formatting PS1 with RVM and Date
View .bashrc
# FORMATACAO FOLDER \W FORMATACAO
export PS1="\[\e[1m\]\W\[\e[0m\] \$ "
# adding RVM ruby information
# FORMATACAO RVM FORMATACAO
export PS1="[\[\e[31;1m\]\$(~/.rvm/bin/rvm-prompt i v p g)\[\e[0m\]]\[\e[0m\]:$PS1"
# adding Timestamp
# DIA DA SEMANA \D HORARIO \t
export PS1="[\[\e[31;1m\]\D{%d}\[\e[0m\]]\[\e[0m\][\[\e[31;1m\]\t\[\e[0m\]]\[\e[0m\]$PS1"
View shared_controller_examples.rb
# INDEX
shared_examples 'a index request' do |model|
it "renders the :index view" do
get :index
expect(response).to render_template("index")
end
it "populates an array of #{model.to_s}" do
get :index
obj = create(model.to_s.downcase.to_sym)
expect(assigns(model.to_s.downcase.pluralize.to_sym)).to match_array(model.all)
@rafaelcgo
rafaelcgo / offline_template.rb
Last active Aug 29, 2015
Offline template renderer to use with rake tasks (or any background worker)
View offline_template.rb
class OfflineTemplate < AbstractController::Base
include AbstractController::Logger
include AbstractController::Rendering
include AbstractController::Layouts
include AbstractController::Helpers
include AbstractController::Translation
include AbstractController::AssetPaths
include ActionDispatch::Routing::UrlFor
include Rails.application.routes.url_helpers
Rails.application.routes.default_url_options = { :host => 'www.yoursite.com' }
@rafaelcgo
rafaelcgo / KURIRANOTIFIER
Last active Aug 29, 2015
Notificador de ingressos para a Copa do Mundo 2014
View KURIRANOTIFIER
Para MAC OS! (O som só funciona em MacOs)
Faça download do script.
Edite ele de acordo com suas necessidades (jogos, categorias)
Abra o terminal.
Vá até a pasta do script.
execute com:
ruby kurira_ticket_notifier.rb