Skip to content

Instantly share code, notes, and snippets.

View passalini's full-sized avatar

Pedro Henrique Passalini passalini

  • Campos dos Goytacazes
View GitHub Profile
@bricker
bricker / promises.md
Last active March 14, 2018 00:33
Promises in Rails callbacks, using after_save and after_commit together.

"Russian-Doll Caching" is great. It embraces the Rails (and Ruby) goal to "make the developer happy". And it does. Not having to worry about cache expiration is superb.

It has its limits, though. If you're trying to avoid any database queries, russian-doll caching will not work for you. If you are trying to represent thousands, or even hundreds, of objects under a single cache fragment, russian-doll caching is not the best option.

We use it whenever it makes sense, but sometimes we just have to bite the bullet and expire a cache fragment manually. When you want to start manually expiring cache on a fairly busy website, you have to start considering race conditions. I recently ran into the following scenario:

class Post < ActiveRecord::Base
  after_save :expire_cache
  
@elgalu
elgalu / .irbrc
Last active January 29, 2018 16:33
IRB / Pry copy last result, a.k.a `_`, to your OSX / Linux / Windows clipboard using the 'clipboard' gem
require 'clipboard' #gem install clipboard
def cbcopy(value)
Clipboard.copy value unless value.empty?
flash_message = value.empty? ? "Sorry, nothing to copy" : "Copied to clipboard"
print "# #{flash_message}: "
puts %Q("#{value}")
end
# Copy last result to the Clipboard
@racheldonovan
racheldonovan / wysihtml5_helper.rb
Created April 18, 2013 21:55
a helper to assit in integration testing (rspec / capybara) wysihtml5 text editors.
module Wysihtml5Helper
def fill_in_wysihtml5(text)
#js must be enabled
page.execute_script("editor.setValue('#{text}')")
end
end
@Mithrandir0x
Mithrandir0x / gist:3639232
Created September 5, 2012 16:15
Difference between Service, Factory and Provider in AngularJS
// Source: https://groups.google.com/forum/#!topic/angular/hVrkvaHGOfc
// jsFiddle: http://jsfiddle.net/pkozlowski_opensource/PxdSP/14/
// author: Pawel Kozlowski
var myApp = angular.module('myApp', []);
//service style, probably the simplest one
myApp.service('helloWorldFromService', function() {
this.sayHello = function() {
return "Hello, World!"
@MohamedAlaa
MohamedAlaa / tmux-cheatsheet.markdown
Last active May 3, 2024 19:09
tmux shortcuts & cheatsheet

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
@krsmurata
krsmurata / rails_admin.pt-BR.yml
Created February 16, 2012 13:09 — forked from lribeiro/rails_admin.pt-PT.yml
Portuguese (pt-BR) translation for RailsAdmin 3.2
pt-BR:
views:
admin:
home:
name: Home
pagination:
previous: "&laquo; Anterior"
next: "Próximo &raquo;"
truncate: "…"
misc:
@hugomaiavieira
hugomaiavieira / clearCache.sh
Last active October 18, 2023 19:41
Script para limpar o cache do seu Linux
#!/bin/sh
#
# Salve este script no diretório /etc/cron.hourly e dê permissão
# de execução a ele. Desse modo a cada hora sera verificada se a
# porcentagem de memória utilizada pelo sistema atingiu o valor definido
# na variável 'percent'. Caso positivo, o script informará ao kernel
# que este deverá alterar o valor da opção 'drop_caches' para 3.
#
# Mais detalhes: 'man proc' -> /proc/sys/vm/drop_caches.
PATH="/bin:/usr/bin:/usr/local/bin"
@zhengjia
zhengjia / capybara cheat sheet
Created June 7, 2010 01:35
capybara cheat sheet
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')