Skip to content

Instantly share code, notes, and snippets.

View tejo's full-sized avatar

Matteo Parmi tejo

View GitHub Profile
@tejo
tejo / gist:58932
Created February 5, 2009 19:16 — forked from rails/gist:58761
var DateHelper = {
// Takes the format of "Jan 15, 2007 15:45:00 GMT" and converts it to a relative time
// Ruby strftime: %b %d, %Y %H:%M:%S GMT
time_ago_in_words_with_parsing: function(from) {
var date = new Date;
date.setTime(Date.parse(from));
return this.time_ago_in_words(date);
},
time_ago_in_words: function(from) {
@tejo
tejo / gist:58933
Created February 5, 2009 19:16 — forked from rails/gist:58761
var DateHelper = {
// Takes the format of "Jan 15, 2007 15:45:00 GMT" and converts it to a relative time
// Ruby strftime: %b %d, %Y %H:%M:%S GMT
time_ago_in_words_with_parsing: function(from) {
var date = new Date;
date.setTime(Date.parse(from));
return this.time_ago_in_words(date);
},
time_ago_in_words: function(from) {
#!/bin/bash
# Unattended REE/Passenger installation with nginx
if [ "$(whoami)" != "root" ]; then
echo "You need to be root to run this!"
exit 2
fi
VERSION="1.2"
# Quick wrapper for undocumented and unsupported MyMileMarker.com API
require 'rubygems'
gem 'httparty', '>= 0.3.1'
require 'httparty'
module MyMileMarker
class Client
include HTTParty
# Monkey-patch for Passenger to use the EventMachine reactor.
# This allows the use of EM timers, EM.system/popen, and other async libraries (amqp, em-http-request, etc) inside a Rails process.
# This requires EM.watch which was added to EM's git repo recently. Build an EM gem first:
# git clone git://github.com/eventmachine/eventmachine
# cd eventmachine
# gem build eventmachine.gemspec
# sudo gem install eventmachine-0.12.9.gem
# Please do not use this in production =)
begin
# check if memcached is running; if it is, use that instead of the default memory cache
Timeout.timeout(0.5) { TCPSocket.open("localhost", 11211) { } }
config.cache_store = :mem_cache_store, %w(localhost:11211), { :namespace => 'OI', :timeout => 60 }
$stderr.puts "Using memcached on localhost:11211"
rescue StandardError
config.cache_store = nil
$stderr.puts "memcached not running, caching to memory"
end
# Para salvar a altura e largura das imagens enviadas pelo plugin paperclip, utilize o callback abaixo
#
# class Document < ActiveRecord::Base
#
# has_attached_file :document, :styles => { :medium => "300x300>" }
#
# before_save :save_dimensions
#
# def save_dimensions
# if document.image?
class ApplicationController < ActionController::Base
before_filter :page_params, :only => :index
def page_key
(self.class.to_s + "_page").to_sym
end
def page_params
if params[:page] then
session[page_key] = params[:page]
@tejo
tejo / routes.rb
Created April 1, 2011 21:41 — forked from pixeltrix/routes.rb
Examples of advanced Rails Routes
Rails.application.routes.draw do
get '/(:locale)/products/(:category)/(page/:page).:extension',
:to => 'products#index',
:as => :products,
:constraints => {
:locale => /[a-z]{2}/,
:category => /.+?/,
:page => /\d+/
},
@tejo
tejo / carousel.js
Created April 18, 2011 07:40 — forked from paolochiodi/carousel.js
advanced js by paolo chiodi