Skip to content

Instantly share code, notes, and snippets.

View andreapavoni's full-sized avatar
🎧
❤️‍🔥🪩🕺🏻🚀

Andrea Pavoni andreapavoni

🎧
❤️‍🔥🪩🕺🏻🚀
View GitHub Profile
@andreapavoni
andreapavoni / realty_request_controller.rb
Created July 6, 2010 12:04
Rails 3: An improved Search agnostic model using Arel
class RealtyRequestController < ApplicationController
#... other actions ...
def search
@s = Search.new(RealtyRequest,params[:search]) do |s|
s.contract_id :eq # value to search defaults to params[:search][:contract_id]
s.price_max :lteq # same here
s.price_min :gteq
s.zone :matches, "%#{params[:search][:zone]}%" # here I look for '%param%'
s.province :matches, "%#{params[:search][:province]}%"
s.municipality :matches, "%#{params[:search][:municipality]}%"
@andreapavoni
andreapavoni / git_bash_prompt.sh
Created March 29, 2011 16:18
my custom colored bash prompt with current git branch status
# git dirty bash prompt (mostly ripped from http://henrik.nyh.se/2008/12/git-dirty-prompt)
# clean repo:
# user@host:~/path/to/repo/ [current-branch]$
# dirty repo:
# user@host:~/path/to/repo/ [current-branch*]$
function parse_git_dirty {
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "*"
}
@andreapavoni
andreapavoni / simpleconv_env_config.rb
Created April 19, 2011 15:31
activate SimpleCov just using an ENV
# put at the beginning of your test helper (it doesn't matter which framework you use)
unless ENV['COVERAGE'].nil?
require 'simplecov'
SimpleCov.start 'rails' do
coverage_dir 'coverage'
end
end
# then launch your test this way:
# COVERAGE=1 rake spec
@andreapavoni
andreapavoni / Gemfile
Created September 6, 2011 10:50
setup Rails 3.1 Gemfile using data_mapper 1.2.0.rc1
source 'http://rubygems.org'
gem 'rails', '3.1.0'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', "~> 3.1.0"
gem 'coffee-rails', "~> 3.1.0"
gem 'uglifier'
@andreapavoni
andreapavoni / rcov.rake
Created October 10, 2011 14:18 — forked from alexdreher/rcov.rake
rcov raketask for Rails 3, RSpec 2
# Forked to get it working with Rails 3 and RSpec 2
#
# From http://github.com/jaymcgavren
#
# Save this as rcov.rake in lib/tasks and use rcov:all =>
# to get accurate spec/feature coverage data
#
# Use rcov:rspec or rcov:cucumber
# to get non-aggregated coverage reports for rspec or cucumber separately
@andreapavoni
andreapavoni / vim_clear_white_spaces.vim
Created December 7, 2011 13:24
vim: clear whitespaces when saving buffer
" clear whitespaces when saving buffer
" put it in your .vimrc
function! Clear_whitespaces()
ma a
:%s/\s\+$//e
'a
endfunction
autocmd BufWritePre * :call Clear_whitespaces()
@andreapavoni
andreapavoni / gist:1581987
Created January 9, 2012 08:42
therubygame palindrome solution
def find_longest_palindrome(string)
(string.size/2).downto(1) do |n|
if m = string.match(Regexp.new("#{'(.)' * (n+1)}?\\#{n.downto(1).to_a.join('\\')}"))
return m
end
end
end
@andreapavoni
andreapavoni / config.ru
Created March 8, 2012 06:55
Rails Lightweight Stack. Most of this is detailed on Crafting Rails Applications - http://pragprog.com/book/jvrails/crafting-rails-applications
# Run this file with `RAILS_ENV=production rackup -p 3000 -s thin`
# Be sure to have rails and thin installed.
require "rubygems"
# We are not loading Active Record, nor the Assets Pipeline, etc.
# This could also be in your Gemfile.
gem "actionpack", "~> 3.2"
gem "railties", "~> 3.2"
# The following lines should come as no surprise. Except by
class ActionDispatch::Routing::Mapper
def draw(routes_name)
instance_eval(File.read(Rails.root.join("config/routes/#{routes_name}.rb")))
end
end
BCX::Application.routes.draw do
draw :api
draw :account
draw :session
@andreapavoni
andreapavoni / myleakedin.rb
Created June 7, 2012 12:51 — forked from riffraff/gist:2882358
linkedin dump password check
#!/usr/bin/env ruby
# USAGE: ruby myleakedin.rb yourpassword
# assumes you have the dump in the same dir as combo_not.txt
require 'digest/sha1'
pass = ARGV.first
hex = Digest::SHA1.hexdigest(pass)
print "HEX: #{hex} => "