Skip to content

Instantly share code, notes, and snippets.

View ZephiroRB's full-sized avatar
🏠
Working from home

Carlos Montalvo ZephiroRB

🏠
Working from home
View GitHub Profile
@ZephiroRB
ZephiroRB / extract.rb
Last active December 12, 2015 10:29 — forked from abimaelmartell/texto.rb
Ejemplo de Iteración de archivo, gracias a abimael martel
a = File.read './legal.txt'
b = a.force_encoding("ISO-8859-1").encode("utf-8", replace: nil).scan(/inicio([\s\S]+?)fin/)
c = []
b.each do |r|
d = {}
d[:fecha] = r.to_s.scan(/Lima, el (.+?),/).join

Commands examples

If the namespace is not used then the commands will perform on top of the default database. bundle exec rake db:create bundle exec rake db:migrate

By using the namespace we are going to use all the configuration for our alternate DB. bundle exec rake store:db:create bundle exec rake store:db:migrate

module RandomAttribute
def generate_unique_random_base64(attribute, n)
until random_is_unique?(attribute)
self.send(:"#{attribute}=", random_base64(n))
end
end
def generate_unique_random_hex(attribute, n)
until random_is_unique?(attribute)
@ZephiroRB
ZephiroRB / gist:6429304
Last active December 22, 2015 06:09
Install NeoBundle
set nocompatible " Be iMproved
if has('vim_starting')
set runtimepath+=~/.vim/bundle/neobundle.vim/
endif
call neobundle#rc(expand('~/.vim/bundle/'))
" Let NeoBundle manage NeoBundle
NeoBundleFetch 'Shougo/neobundle.vim'
@ZephiroRB
ZephiroRB / warden.rb
Created January 31, 2014 16:49
Config warden Rails 4.0.2
Rails.configuration.middleware.use RailsWarden::Manager do |manager|
manager.default_strategies :remember_token
#manager.failure_app = LoginController
end
# Setup Session Serialization
class Warden::SessionSerializer
def serialize(record)
[record.class, record.id]
end

Ubuntu 12.04, Ruby, Rails, Nginx, Unicorn and git-deploy

In the seemlingly endless search for the actual correct and easy way to deploy a Rails app, we have tried several ways. We tried out using Apache2 and running a cluster of Thin servers. With the built in threading of Puma we decided to use it with Nginx.

Server Setup

  • Create new server
  • Login to new server
    • ssh root@IPaddress (you can also use the domain name if you have the DNS setup already)
    • accept the RSA key
upstream app {
server unix:/srv/app/current/tmp/sockets/unicorn.sock fail_timeout=0;
}
server {
listen 80;
server_name www.app.com;
rewrite ^/(.*) http://app.com/$1 permanent;
}
server {
@ZephiroRB
ZephiroRB / gist:9653646
Created March 19, 2014 23:17
Install Emacs for Ubuntu/Debian/LinuxMint
sudo apt-get install software-properties-common
sudo add-apt-repository ppa:cassou/emacs
sudo apt-get update
#sudo apt-get install emacs-snapshot-el emacs-snapshot-gtk emacs-snapshot
sudo apt-get install emacs24 emacs24-el emacs24-common-non-dfsg
@ZephiroRB
ZephiroRB / Gemfile
Created March 21, 2014 02:42 — forked from pcreux/Gemfile
group :production do
gem 'passenger'
# Enable gzip compression on heroku, but don't compress images.
gem 'heroku-deflater'
# Heroku injects it if it's not in there already
gem 'rails_12factor'
end