Skip to content

Instantly share code, notes, and snippets.

View filipechagas's full-sized avatar
🏖️
OOO

Filipe Chagas filipechagas

🏖️
OOO
View GitHub Profile
@filipechagas
filipechagas / gist:01f09e89927dc8806510
Created August 26, 2015 20:05
Elastic Search Utils
# List all entries in an index
> http://localhost:9200/project_environment_users/_search?pretty=true&q=*:*
# Delete an index
> curl -XDELETE http://localhost:9200/project_environment_users
@filipechagas
filipechagas / gist:8712851
Created January 30, 2014 16:40
Rails - Change view path based on subdomain
# AppicationController...
before_filter :subdomain_view_path
private
def subdomain_view_path
prepend_view_path "app/views/#{request.subdomain}_subdomain" if request.subdomain.present?
end
@filipechagas
filipechagas / gist:8783133
Created February 3, 2014 12:38
Dynamic session expiration time in Rails 3
# source: http://augustl.com/blog/2010/dynamic_session_expiration_time_in_rails_3/
cookies[:thing] = {:value => {:normal => "session stuff"}, :expires => 2.hours.from_now}
# Signed cookies are encrypted with the apps secret_token.
cookies.signed[:login] = {:value => @user.id, :expires => 1.day.from_now}
# These calls are equivalent.
cookies[:foo] = {:value => "bar", :expires => 20.years.from_now}
cookies.permanent[:foo] = "bar"
@filipechagas
filipechagas / gist:8815535
Created February 5, 2014 00:56
Reset mysql root password
#Kill all mysql running instances
$ mysql --skip-grant-tables --skip-networking
$ mysql
mysql> UPDATE mysql.user SET Password=PASSWORD('MyNewPass') WHERE User='root';
mysql> FLUSH PRIVILEGES;
@filipechagas
filipechagas / gist:9231605
Created February 26, 2014 15:27
Class utility method for setting menu groups
class Base
def self.set_menu_group(group_name)
class_eval <<-EOF
def menu_group
"#{group_name}"
end
EOF
end
end
@filipechagas
filipechagas / controller_piece.rb
Created March 17, 2014 13:36
Using JSON to handle redirects on ajax calls
def attempt_login
if authorized_user
if request.xhr?
render :json => {
:location => url_for(:controller => 'jobs', :action => 'index'),
:flash => {:notice => "Hello #{authorized_user.name}."}
}
else
redirect_to(:controller => 'jobs', :action => 'index')
@filipechagas
filipechagas / gist:9786024
Last active August 29, 2015 13:57
Rails ActiveRecord - Overwrite attribute accessors
def attribute_name
read_attribute(:attribute_name)
end
def attribute_name= (value)
write_attribute(:attribute_name, value)
end
@filipechagas
filipechagas / gist:9896597
Created March 31, 2014 16:44
Sed command to generate a new css file with "store_name" in the urls entries
sed -e 's/\(background.*url.*\)\.\./\1\/assets\/#{store_name}\//' public.css > temp.css
@filipechagas
filipechagas / gist:10291572
Created April 9, 2014 16:55
Ubuntu - Change timezone
# List the timezones
ls /usr/share/zoneinfo/
# ls /usr/share/zoneinfo/America or ls /usr/share/zoneinfo/US
# Edit the file with the timezone name
sudo vi /etc/timezone
# America/Sao_Paulo for example
sudo dpkg-reconfigure --frontend noninteractive tzdata
@filipechagas
filipechagas / gist:11058087
Created April 18, 2014 18:32
Ruby Sed inline - Search replace *.css files
-> % ruby -e 'Dir.glob("*.css").each{|f| system("sed -i -e \"s/img\\//images\\//g\" #{f} && rm #{f}-e")}'