Skip to content

Instantly share code, notes, and snippets.

View lucianosousa's full-sized avatar
💭
🏊 🚴‍♂️ 🏃

Luciano Sousa lucianosousa

💭
🏊 🚴‍♂️ 🏃
View GitHub Profile
@lucianosousa
lucianosousa / formtastic.pt-BR.yml
Created September 10, 2014 01:40
Brazilian Portuguese locale for formtastic
pt-BR:
formtastic:
:yes: 'Sim'
:no: 'Não'
:create: 'Criar %{model}'
:update: 'Atualizar %{model}'
:submit: 'Salvar %{model}'
:cancel: 'Cancelar %{model}'
:reset: 'Resetar %{model}'
:required: 'obrigatório'
@lucianosousa
lucianosousa / gist:0b42a418b95bd7eedeea
Created September 10, 2014 01:35
Brazilian Portuguese locale for formtastic
pt-BR:
formtastic:
:yes: 'Sim'
:no: 'Não'
:create: 'Criar %{model}'
:update: 'Atualizar %{model}'
:submit: 'Salvar %{model}'
:cancel: 'Cancelar %{model}'
:reset: 'Resetar %{model}'
:required: 'obrigatório'
@lucianosousa
lucianosousa / gist:b482b3af57188e0ab497
Created September 8, 2014 03:44
namespace example
namespace :admin do
resources :users, only: [:show] do
collection do
get :search
end
end
end
@lucianosousa
lucianosousa / gist:3398c9aa760aa113faa2
Created September 1, 2014 22:37
stress test example from somewhere else
@retained = []
@rand = Random.new(999)
MAX_STRING_SIZE = 100
def stress(allocate_count, retain_count, chunk_size)
chunk = []
while retain_count > 0 || allocate_count > 0
if retain_count == 0 || (@rand.rand < 0.5 && allocate_count > 0)
chunk << " " * (@rand.rand * MAX_STRING_SIZE).to_i
# config/unicorn.rb
worker_processes Integer(ENV["WEB_CONCURRENCY"] || 3)
timeout 15
preload_app true
before_fork do |server, worker|
Signal.trap 'TERM' do
puts 'Unicorn master intercepting TERM and sending myself QUIT instead'
Process.kill 'QUIT', Process.pid
end
WARNING: Please be aware that you just installed a ruby that is no longer maintained (2014-02-23), for a list of maintained rubies visit:
http://bugs.ruby-lang.org/projects/ruby/wiki/ReleaseEngineering
Please consider upgrading to ruby-2.1.2 which will have all of the latest security patches.
@lucianosousa
lucianosousa / gist:6efea313b6f737282b29
Created August 10, 2014 22:33
prevent double submission on forms
jQuery.fn.preventDoubleSubmission = function() {
$(this).on('submit',function(e){
var $form = $(this);
if ($form.data('submitted') === true) {
e.preventDefault();
} else {
$form.data('submitted', true);
}
});
class Post
def as_indexed_json(options={})
self.as_json(
only: [ :id, :title, :published ],
filter: {
bool: {
should: {
term: { published: true }
}
}
location ~ ^/(assets)/ {
root /path/to/public;
gzip_static on; # to serve pre-gzipped version
expires max;
add_header Cache-Control public;
}
@lucianosousa
lucianosousa / gist:b7f819954e31be28f46f
Created May 10, 2014 13:54
rio startups like button
<div class="fb-like" data-href="https://www.facebook.com/riostartups" data-layout="button_count" data-action="like" data-show-faces="false" data-share="false"></div>
<div id="fb-root"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en/sdk.js#xfbml=1&appId=227914187387923&version=v2.0";
fjs.parentNode.insertBefore(js, fjs);