Skip to content

Instantly share code, notes, and snippets.

View nesquena's full-sized avatar

Nathan Esquenazi nesquena

View GitHub Profile
##
# 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
##
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
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
@nesquena
nesquena / Routing.rb
Created November 12, 2009 20:23 — forked from DAddYE/Routing.rb
namespace :admin do
get :show do
...
end
end
namespace :frontend do
get :index do
...
end
$ 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
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!"
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!"
@nesquena
nesquena / example_file.yml
Created September 10, 2010 01:04 — forked from trshafer/example_file.yml
TermInit Script
# 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
@nesquena
nesquena / counter_backfill_migration.rb
Created November 17, 2010 21:13 — forked from mpakes/counter_backfill_migration.rb
Populate a cached counter field via a single SQL query.
# 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;"
@nesquena
nesquena / benchmark.rb
Created July 18, 2011 18:42 — forked from ernie/benchmark.rb
A benchmark of some enumerable methods
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