Skip to content

Instantly share code, notes, and snippets.

View lucapette's full-sized avatar

Luca Pette lucapette

View GitHub Profile
it:
errors:
messages:
not_found: "non trovato"
already_confirmed: "è stato già confermato"
not_locked: "non era bloccato"
devise:
failure:
unauthenticated: "Devi accedere o registrarti per continuare."
@pairing
pairing / active_model_lint.rb
Created October 21, 2010 19:03
RSpec ActiveModel Lint shared example
# adapted from rspec-rails http://github.com/rspec/rspec-rails/blob/master/spec/rspec/rails/mocks/mock_model_spec.rb
shared_examples_for "ActiveModel" do
require 'test/unit/assertions'
require 'active_model/lint'
include Test::Unit::Assertions
include ActiveModel::Lint::Tests
# to_s is to support ruby-1.9
ActiveModel::Lint::Tests.public_instance_methods.map{|m| m.to_s}.grep(/^test/).each do |m|
@dhedlund
dhedlund / gist:1561873
Created January 4, 2012 20:13
Palindrome Iteration

Discovered an interesting algorithm for finding longest palindrome by playing with sequences in a text editor. Anyone know if there's a name for this algorithm?

Worst running time is O(n^2), which is better than the naive implementation of O(n^3) but not as efficient as some O(n) implementations (http://www.akalin.cx/longest-palindrome-linear-time). In general, assuming a non-pathological case, running time is around 2n * m where n is the length of the string and m is the mean length of all palindromes. For non-pathological cases (i.e. human sentences), n is often logarithmic (log n) and fast approaches 1 as n increases. This puts the average case complexity at around n log n and best-case n.

Developed as a solution to: http://www.therubygame.com/challenges/4

Algorithm

Original hand-work to discover a pattern:

#!/usr/bin/tclsh8.5
#
# Usage: git-unmerged branch1 branch2
#
# Shows all the non-common commits in the two branches, where non-common
# commits means simply commits with a unique commit *message*.
proc getlog branch {
lrange [split [exec git log $branch --oneline] "\n"] 0 400
}
@txus
txus / Readme.md
Created March 11, 2012 17:19
RubyScript - A transcompiler transforming a subset of Ruby to JavaScript

RubyScript

A ~400LOC transcompiler transforming a subset of Ruby to JavaScript.

Installing and usage

curl https://raw.github.com/gist/2017173/efebd33d6ff430347ddb953c587318c8934cfd1e/rubyscript.rb > rubyscript
chmod +x rubyscript
./rubyscript my_file.rb > my_file.js
chflags nohidden ~/Library
defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool true
defaults write com.apple.desktopservices DSDontWriteUSBStores -bool true
defaults write com.apple.dock autohide -bool true
defaults write com.apple.dock autohide-delay -float 0
defaults write com.apple.dock launchanim -bool false
defaults write com.apple.dock magnification -bool false
defaults write com.apple.dock mru-spaces -bool false
defaults write com.apple.dock show-process-indicators -bool true
defaults write com.apple.dock size-immutable -bool true
# an example Monit configuration file for delayed_job
#
# To use:
# 1. copy to /var/www/apps/{app_name}/shared/delayed_job.monitrc
# 2. replace {app_name} and {environment} as appropriate
# 3. add this to your /etc/monit/monitrc
#
# include /var/www/apps/{app_name}/shared/delayed_job.monitrc
check process delayed_job with pidfile /var/www/apps/{app_name}/shared/pids/delayed_job.pid

This allows you to use the following video streaming services outside of the US from your Mac without having to use a proxy or VPN, so no big bandwidth issues:

  • Hulu / HuluPlus
  • CBS
  • ABC
  • MTV
  • theWB
  • CW TV
  • Crackle
  • NBC

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:

@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')