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 / .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
@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
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 / 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 Marvel::CharactersController < ApplicationController
before_action :authenticate_user!
def index
@characters = Character.paginate(page: params[:page], per_page: 10)
get_all_characters unless @characters.present?
end
def show
@character = get_character
@phensalves
phensalves / character_manager.rb
Last active December 2, 2016 15:57
Consuming api using NET from ruby
module Api
class CharacterManager
API_CONFIG = YAML.load_file("#{Rails.root.to_s}/config/marvel_configs.yml")["marvel_api"]
def initialize options={}
@ts = "#{API_CONFIG['ts']}"
@api_key = "#{API_CONFIG['api_key']}"
@hash = "#{API_CONFIG['secret_hash']}"
@limit = "#{API_CONFIG['limit']}"
@phensalves
phensalves / delete_local_branches.txt
Last active November 9, 2016 13:39
Snippet to delete all local branches and keep master
git branch | grep -v "master" | xargs git branch -D
{
"bitwise": true,
"camelcase": false,
"curly": true,
"eqeqeq": true,
"es3": false,
"forin": true,
"freeze": true,
"immed": true,
"indent": 4,
{
"excludeFiles": ["node_modules/**", "bower_components/**"],
"requireCurlyBraces": [
"if",
"else",
"for",
"while",
"do",
"try",
%table
%thead
%tr
%th Number
%th Created At
%th Text
%th
%th
%th