Skip to content

Instantly share code, notes, and snippets.

View duduribeiro's full-sized avatar

Cadu Ribeiro duduribeiro

View GitHub Profile
@duduribeiro
duduribeiro / br_sp_cel_mask.js
Created August 7, 2012 17:15
new mask for Brazil-São Paulo celphones (jquery)
$('#cel').mask("(99) 9999-9999?9").live('focusout', function(event) {
var target, phone, element;
target = (event.currentTarget) ? event.currentTarget : event.srcElement;
phone = target.value.replace(/\D/g, '');
element = $(target);
element.unmask();
if(phone.length > 10) {
element.mask("(99) 99999-999?9");
} else {
element.mask("(99) 9999-9999?9");
@duduribeiro
duduribeiro / gist:3777294
Created September 24, 2012 17:54 — forked from brunoandradd/gist:3777274
Config nginx com php/ruby
worker_processes 3;
events {
worker_connections 1024;
}
http {
passenger_root /usr/local/lib/ruby/gems/1.8/gems/passenger-3.0.7;
passenger_ruby /usr/local/bin/ruby;

Zero downtime deploys with unicorn + nginx + runit + rvm + chef

Below are the actual files we use in one of our latest production applications at Agora Games to achieve zero downtime deploys with unicorn. You've probably already read the GitHub blog post on Unicorn and would like to try zero downtime deploys for your application. I hope these files and notes help. I am happy to update these files or these notes if there are comments/questions. YMMV (of course).

Other application notes:

  • Our application uses MongoDB, so we don't have database migrations to worry about as with MySQL or postgresql. That does not mean that we won't have to worry about issues with the database with indexes being built in MongoDB or what have you.
  • We use capistrano for deployment.

Salient points for each file:

#!/usr/bin/env ruby
require 'time'
require 'logger'
require 'rubygems'
require 'pingdom-client'
require 'active_support/core_ext/numeric/time' # time extensions, e.g., 5.days
require 'stashboard'
TIME_FORMAT = "%Y-%m-%d %H:%M:%S %Z" # YYYY-MM-DD HH:MM:SS ZZZ
@duduribeiro
duduribeiro / nginx.conf
Created March 12, 2014 15:13
nginx.conf
# User and group that workers will use.
user nginx nginx;
# Number of NGINX workers. Usually it's set, at maximum, 1 worker per CPU core.
# If the server has 2+ CPU cores but it still does not receive many requests,
# it's a good idea to keep the value to 1 so it will avoid creating idle processes.
worker_processes 2;
# NGINX's master process id.
pid /var/run/nginx.pid;
#!/bin/sh
# Sublime Text 3 install with Package Control
# http://simonewebdesign.it/blog/install-sublime-text-3-on-fedora-20/
# Run this script with:
# $ curl LINK_TO_THIS_SCRIPT | sh
curl -o ~/st3.tar.bz2 http://c758482.r82.cf2.rackcdn.com/sublime_text_3_build_3059_x64.tar.bz2

Deploy Rails 4 app with Dokku on DigitalOcean

Install dokku

First create a Ubuntu 13.04 x64 droplet on DigitalOcean Control Panel

Then ssh with root account, run this in termianl:

$ wget -qO- https://raw.github.com/progrium/dokku/master/bootstrap.sh | sudo bash
@duduribeiro
duduribeiro / gist:57453716cbd0aedcd8b4
Created October 6, 2014 19:33
ansible-id_rsa.ym;
---
- name: Configure Ansible
hosts: guests
user: root
tasks:
- name: Install Ansible
action: yum pkg=$item state=installed
with_items:
# Install redis with homebrew :)
$ brew install redis
# Create a deamon
$ sudo vim /Library/LaunchDaemons/io.redis.redis-server.plist
# Paste the following content
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
* {
font-size: 12pt;
font-family: monospace;
font-weight: normal;
font-style: normal;
text-decoration: none;
color: black;
cursor: default;
}