Skip to content

Instantly share code, notes, and snippets.

View phensalves's full-sized avatar
👾
MCMXC

No More Cookies phensalves

👾
MCMXC
  • London, UK
View GitHub Profile
@phensalves
phensalves / gist:4c932b2ca4344e7ed5a9b71c910c637c
Created December 2, 2016 00:10
script to convert erb to haml using html2haml gem
for file in app/views/**/*.erb; do html2haml -e $file ${file%erb}haml && rm $file; done
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
private
def after_sign_in_path_for(resource_or_scope)
marvel_characters_path
end
@phensalves
phensalves / rb
Created January 5, 2017 16:33
veshe
if params[:user][:current_password] #Changing with password
if resource.update_with_password(params[:user])
if is_flashing_format?
flash_key = update_needs_confirmation?(resource, prev_unconfirmed_email) ?
:update_needs_confirmation : :updated
set_flash_message :notice, flash_key
end
sign_in resource_name, resource, bypass: true
respond_with resource, location: after_update_path_for(resource)
else
@phensalves
phensalves / .rb
Last active January 5, 2017 17:10
N + 1
def list
## FILTER
@dealweekdays = DealWeekday.active
if params[:search_term]
search_name = @dealweekdays.like_name(params[:search_term])
search_district = @dealweekdays.district_by_name(params[:search_term])
joined = search_name + search_district
joined_ids = joined.uniq.map{|bar| bar.id}
@dealweekdays = DealWeekday.where(id:joined_ids)
end
def show
load_deals unless mobile_device? || request.format == :js
@deal_weekday = DealWeekday.by_weekday(Weekday.from_slug(params[:weekday])).by_slug(params[:slug]).active.first
if !@deal_weekday || !@deal_weekday.active
flash[:error] = '<strong>Desculpe!</strong> Não encontramos a pedida que você solicitou.'
redirect_to home_path(@city.slug)
return false
end
def list
## FILTER
@bars = Bar.where("latitude IS NOT NULL").where("longitude IS NOT NULL")
@bars = @bars.running_in(true)
if params[:search_term]
search_name = @bars.like_name(params[:search_term])
search_district = @bars.district_by_name(params[:search_term])
joined = search_name + search_district
joined_ids = joined.uniq.map{|bar| bar.id}
@bars = Bar.where(id:joined_ids)
def list_favorite_bars bar_id
@favorite_bars = get_favorite_bars(params[:bar_id])
respond_to do |format|
format.json { render :json => @favorite_bars}
end
end
private
def get_favorite_bars bar_id
@phensalves
phensalves / rake_query_sample.rb
Created May 11, 2017 15:44
Maneiras de se fazer queries
operations = Operation.all
states = CountryState.all
states.each do |s|
operations.each do |operation|
next if (operation.name == "Teste" || operation.name == "teste" || operation.name == "TESTE")
case s.name
when "Amazonas"
operation.country_state_id = 1 if operation.name == "CDD MANAUS"
module Api
class TweetsApiManager
def initialize options={}
end
def execute
connect_to_twitter_api(ENV['API_ENDPOINT'])
elect_tweets
end
@phensalves
phensalves / controller.rb
Last active May 28, 2017 07:56
controller
class TweetsController < ApplicationController
def most_relevants
process_most_relevants
end
def most_mentions
process_most_mentions
end