This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## | |
# Calendar helper with proper events | |
# http://www.cuppadev.co.uk/webdev/making-a-real-calendar-in-rails/ | |
# | |
# (C) 2009 James S Urquhart (jamesu at gmail dot com) | |
# Derived from calendar_helper | |
# (C) Jeremy Voorhis, Geoffrey Grosenbach, Jarkko Laine, Tom Armitage, Bryan Larsen | |
# Licensed under MIT. http://www.opensource.org/licenses/mit-license.php | |
## | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
desc "Generate and deploy assets" | |
task :deploy_assets, :roles => :app do | |
# get the previous timestamp | |
old_timestamp = File.read("config/deploy_timestamp").to_i rescue 0 | |
# generate timestamp into config/deploy_timestamp | |
timestamp = Time.now.to_i | |
File.open("config/deploy_timestamp", 'w') do |f| | |
f.write(timestamp) | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Application < Sinatra::Base | |
register SinatraMore::MarkupPlugin | |
register SinatraMore::RenderPlugin | |
configure :development do | |
DataMapper::setup(:default, "sqlite3://#{Dir.pwd}/db/app.db") | |
end | |
class User | |
include DataMapper::Resource |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace :admin do | |
get :show do | |
... | |
end | |
end | |
namespace :frontend do | |
get :index do | |
... | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ padrino-gen project sample_blog -t shoulda -e haml -c sass -s jquery -d activerecord -b | |
create | |
create app/app.rb | |
create config/apps.rb | |
create config/boot.rb | |
create config.ru | |
create public/favicon.ico | |
create .gitignore | |
exist app | |
create app/controllers |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
project :test => :shoulda, :renderer => :haml, :stylesheet => :sass, :script => :jquery, :orm => :activerecord, :dev => true | |
#default routes | |
APP_INIT = <<-APP | |
get "/" do | |
"Hello World!" | |
end | |
get :about, :map => '/about_us' do | |
render :haml, "%p This is a sample blog created to demonstrate the power of Padrino!" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
project :test => :shoulda, :renderer => :haml, :stylesheet => :sass, :script => :jquery, :orm => :activerecord, :dev => true | |
#default routes | |
APP_INIT = <<-APP | |
get "/" do | |
"Hello World!" | |
end | |
get :about, :map => '/about_us' do | |
render :haml, "%p This is a sample blog created to demonstrate the power of Padrino!" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# you can make as many tabs as you wish... | |
# tab names are actually arbitrary at this point too. | |
--- | |
- tab1: cd ~/foo/bar | |
- tab2: | |
- mysql -u root | |
- use test; | |
- show tables; | |
- tab3: echo "hello world" | |
- tab4: cd ~/baz/ && svn up |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Credit to Mike Perham for this gem of an idea | |
# http://www.mikeperham.com/2007/12/17/creating-a-counter_cache-column/ | |
class RailsMigration < ActiveRecord::Migration | |
def self.up | |
add_column :media, :followers_count, :integer, :default => 0, :null => false | |
# Populate the media follower counter cache in one fell swoop. | |
sql = "update media, (select operable_id, count(*) as the_count from follow_operations "\ | |
"group by operable_id) as follows set media.followers_count = follows.the_count "\ | |
"where media.id = follows.operable_id;" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'benchmark' | |
haystack = (1..1_000_000).to_a | |
needles = 1.upto(100).map {|n| n * 10_000} | |
module EachDetector | |
def self.find(haystack, needle) | |
haystack.each do |v| | |
return true if v == needle | |
end |
OlderNewer