Skip to content

Instantly share code, notes, and snippets.

View cassioscabral's full-sized avatar

Cassio Cabral cassioscabral

View GitHub Profile
@cassioscabral
cassioscabral / gist:5510578
Created May 3, 2013 16:17
Simple example of inflections on Rails
ActiveSupport::Inflector.inflections do |inflect|
inflect.irregular 'noticia', 'noticias'
end

Friendly URLs

By default, Rails applications build URLs based on the primary key -- the id column from the database. Imagine we have a Person model and associated controller. We have a person record for Bob Martin that has id number 6. The URL for his show page would be:

/people/6

But, for aesthetic or SEO purposes, we want Bob's name in the URL. The last segment, the 6 here, is called the "slug". Let's look at a few ways to implement better slugs.

// SASS variable overrides must be declared before loading up Active Admin's styles.
//
// To view the variables that Active Admin provides, take a look at
// `app/assets/stylesheets/active_admin/mixins/_variables.css.scss` in the
// Active Admin source.
//
// For example, to change the sidebar width:
// $sidebar-width: 242px;
// Active Admin's got SASS!
@cassioscabral
cassioscabral / bashrc
Last active December 24, 2015 12:38
bashrc calling bash_prompt with custom setup showing current branch, short PS1 and colored fonts.
export LSCOLORS=gxBxhxDxfxhxhxhxhxcxcx
HISTFILESIZE=100000000
alias ll="ls -la"
alias rss="python manage.py runserver 0.0.0.0:8000"
export PS1="[\u@\w]\$: "
alias cg="cd ~/git/"
alias restart_nginx='/usr/local/Cellar/nginx/1.4.1/bin/nginx -s reload'
alias mysass='sass --watch --sourcemap'
. ~/.nvm/nvm.sh
@cassioscabral
cassioscabral / bash_prompt
Created October 2, 2013 18:54
bash_prompt # @gf3’s Sexy Bash Prompt, inspired by “Extravagant Zsh Prompt” # Shamelessly copied from https://github.com/gf3/dotfiles
# @gf3’s Sexy Bash Prompt, inspired by “Extravagant Zsh Prompt”
# Shamelessly copied from https://github.com/gf3/dotfiles
default_username='username'
if [[ $COLORTERM = gnome-* && $TERM = xterm ]] && infocmp gnome-256color >/dev/null 2>&1; then
export TERM=gnome-256color
elif infocmp xterm-256color >/dev/null 2>&1; then
export TERM=xterm-256color
fi
@cassioscabral
cassioscabral / gitignore
Created October 8, 2013 17:07
gitignore common extensions
node_modules/
local_settings.py
settings_local.py
*.pyc
*.sqlite
/media
.DS_Store
/.idea/
#!/usr/bin/ruby
require 'rss'
# Usage
# $ ./railscasts.rb http://railscasts.com/subscriptions/YOURRAILSCASTRSS/\/
# episodes.rss
# OR
# $ ./railscasts.rb
p 'Downloading rss index'

In your view:

<%= link_to "Load more", posts_path(@posts, page: @posts.current_page+1), id: "load-more-posts", remote: true %>

In your controller:

respond_to :html, :js, only: [:index]

def index
# encoding: utf-8
# Be sure to restart your server when you modify this file.
# Add new inflection rules using the following format
# (all these examples are active by default):
# ActiveSupport::Inflector.inflections do |inflect|
# inflect.plural /^(ox)$/i, '\1en'
# inflect.singular /^(ox)en/i, '\1'
# inflect.irregular 'person', 'people'
# inflect.uncountable %w( fish sheep )