Skip to content

Instantly share code, notes, and snippets.

View mzaragoza's full-sized avatar

Moises Zaragoza mzaragoza

View GitHub Profile
# ~/.bashrc
# vim:set ft=sh sw=2 sts=2:
source "$HOME/.hashrc"
# Store 10,000 history entries
export HISTSIZE=10000
# Don't store duplicates
export HISTCONTROL=erasedups
# Append to history file
@mzaragoza
mzaragoza / app-models-user.rb
Created September 2, 2016 14:30
Best way to store bank account information of users?
#file name and path app/models/user.rb
class User
attr_encrypted :bank_account_number, key: ENV['salt']
end
#lib/tasks/db.rake
namespace :db do
desc "Import most recent database dump"
task :import_from_prod => :environment do
puts 'heroku run pg:backups capture --app sushi-prod'
restore_backup 'sushi-prod'
end
def path_to_heroku
['/usr/local/heroku/bin/heroku', '/usr/local/bin/heroku'].detect {|path| File.exists?(path)}
require 'uri'
enc_uri = URI.escape("http://example.com/?a=\111\\115"")
p enc_uri
# => "http://example.com/?a=%09%0D"
p URI.unescape(enc_uri)
# => "http://example.com/?a=\t\r"
class UsersController < ApplicationController
def new
@user = User.new
end
def create
@user = User.new(params[:user])
if @user.save
flash[:notice] = "You have successfully registered, please log in!"
uEgvHsY8YQDukiNnho1xMzJrjSiDXAhWRFwRunhmLfPIHQGayk
https://openid.stackexchange.com/account/affiliate/complete-registration?affId=4&authCode=ehxvsqtS8uKSe8ZnUv4M09og2K8%3d&callback=http%3a%2f%2fstackoverflow.com%2fusers%2fauthenticate&email=gia%40moiseszaragoza.com&realname=Gia+Furn&token=87dd8d6b-bbb7-4e72-8794-baaa25fdfa55
You can add the following code to you .bashrc file:
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
PS1="${debian_chroot:+($debian_chroot)}\u@\h:\w\$(parse_git_branch) $ "
You can move around these component parts to configure to your tastes, for example to prepend $(parse_git_branch) and not show the user@computer part I used:
PS1="\$(parse_git_branch)${debian_chroot:+($debian_chroot)}\w$ "
@mzaragoza
mzaragoza / gist:6501997
Created September 9, 2013 21:48
config/initializers/strings.rb
class String
def map(arg=nil)
if arg
[self].map(arg)
elsif block_given?
[self].map{|i| yield(i)}
else
[self]
end
end
@mzaragoza
mzaragoza / gist:6437267
Created September 4, 2013 13:56
BASHRC
if [[ -s "$HOME/.rvm/scripts/rvm" ]] ; then source "$HOME/.rvm/scripts/rvm" ; fi
[[ -r $rvm_path/scripts/completion ]] && source $rvm_path/scripts/completion
alias bashrc="vim ~/.bashrc.local"
alias remove_all_gems='gem list | cut -d" " -f1 | xargs gem uninstall -aIx'
cat <<INPUTRC >~/.inputrc
set completion-ignore-case On
TAB: menu-complete
INPUTRC