Skip to content

Instantly share code, notes, and snippets.

View danielvlopes's full-sized avatar

Daniel Lopes danielvlopes

View GitHub Profile
# Assuming you mounted it as attachment...
def update_attributes(attributes)
@previous_attachment = self.attachment
super
end
after_update do
if @previous_attachment && @previous_attachment.file != attachment.try(:file)
@previous_attachment.remove!
end
@lucashungaro
lucashungaro / tips.textile
Created October 29, 2010 02:11
presentation tips
  • Slides com temas, cores e efeitos são muito legais mas, a menos que você saiba exatamente como isso vai ficar no projetor, deixe a “tentação” de lado e faça o simples: slide branco, texto preto
  • Para código fonte, independente de conhecer ou não o lugar onde será apresentado, sempre utilize fundo branco, texto em tamanho grande (22 ou maior) e um tema como esse: http://yfrog.com/735mfp
  • Se utiliza um Mac, uma forma fácil de copiar código fonte com syntax highlighting para os slides é usar o editor TextMate e um bundle chamado Copy as RTF
  • Também no Mac, quando conectado ao projetor, é possível modificar o color profile da saída de vídeo, buscando obter uma reprodução mais fiel ao seu monitor. Para isso, após conectado, acesse System Preferences > Displays > Color (aba na janela de configurações do display secundário) e selecionar um profile que se adeque bem
  • Como último recurso, é possível inverter as co
# Rails developers have long had bad experiences with fixtures for
# several reasons, including misuse.
#
# Misuse of fixtures is characterized by having a huge number of them,
# requiring the developer to maintain a lot of data and creating dependencies
# between tests. In my experience working (and rescuing) many applications, 80%
# of fixtures are only used by 20% of tests.
#
# An example of such tests is one assuring that a given SQL query with
# GROUP BY and ORDER BY conditions returns the correct result set. As expected,
# Hi! I'am rack middleware!
# I was born for show right way to you JavaScript
# My author's name was Aleksandr Koss. Mail him at [email protected]
# Nice to MIT you!
require(File.dirname(__FILE__) + '/../config/environment') unless defined?(Rails)
class RoutesJs
def initialize app, options = {}
# Copyright 2009 Michael Ivey, released to public domain
# Disqus guts lifted from http://github.com/squeejee/disqus-sinatra-importer/tree/master
# I wanted it to run from MySQL and command line, instead of a Sinatra app
require 'rubygems'
require 'rest_client'
require 'json'
require 'sequel'
disqus_url = 'http://disqus.com/api'
@schacon
schacon / example_gist_create.rb
Created August 6, 2008 20:29
gist example api post
require 'net/http'
require 'uri'
# /api/v1/:format/new
# /api/v1/:format/gists/:user
# /api/v1/:format/:gist_id
res = Net::HTTP.post_form(URI.parse('http://gist.github.com/api/v1/xml/new'),
{ 'files[file1.ab]' => 'CONTNETS',
'files[file2.ab]' => 'contents' })