Monday, 27 January 2014

Fast Rails API with ActionController::Metal

#app/controllers/api/api_controller.rb
class Api::ApplicationController < ActionController::Metal
include ActionController::Rendering
respond_to :json
end
#app/controllers/api/v1/tasks_controller.rb
module Api
module V1
class TasksController < Api::ApplicationController
def do_something
render :json => Task.find(params[:id]).to_json
end
end
end
end
#routes
namespace :api , defaults: {format: 'json'} do
namespace :v1 do
resources :tasks, :only => [] do
member do
get 'do_something'
end
end
end
end
view raw gistfile1.rb hosted with ❤ by GitHub

Tuesday, 21 January 2014

fixed brew permissions

ls -al /usr/local/bin/brew #confirm brew ownership
#must be run under root
sudo chown root:wheel /usr/local/bin/brew
view raw gistfile1.sh hosted with ❤ by GitHub

Monday, 20 January 2014

rake db

  • db:migrate runs (single) migrations that have not run yet.
  • db:create creates the database
  • db:drop deletes the database
  • db:schema:load creates tables and columns within the (existing) database following schema.rb
  • db:setup does db:create, db:schema:load, db:seed
  • db:reset does db:drop, db:setup
Typically, you would use db:migrate after having made changes to the schema via new migration files (this makes sense only if there is already data in the database). db:schema:load is used when you setup a new instance of your app.
I hope that helps.

UPDATE for rails 3.2.12:
I just checked the source and the dependencies are like this now:
  • db:create creates the database for the current env
  • db:create:all creates the databases for all envs
  • db:drop drops the database for the current env
  • db:drop:all drops the databases for all envs
  • db:migrate runs migrations for the current env that have not run yet
  • db:migrate:up runs one specific migration
  • db:migrate:down rolls back one specific migration
  • db:migrate:status shows current migration status
  • db:migrate:rollback rolls back the last migration
  • db:forward advances the current schema version to the next one
  • db:seed (only) runs the db/seed.rb file
  • db:schema:load loads the schema into the current env's database
  • db:schema:dump dumps the current env's schema (and seems to create the db as well)
  • db:setup runs db:schema:load, db:seed
  • db:reset runs db:drop db:setup
  • db:migrate:redo runs (db:migrate:down db:migrate:up) or (db:migrate:rollback db:migrate:migrate) depending on the specified migration
  • db:migrate:reset runs db:drop db:create db:migrate
http://stackoverflow.com/questions/10301794/difference-between-rake-dbmigrate-dbreset-and-dbschemaload

Friday, 17 January 2014

ssh-copy-id-for-OSX

curl https://raw.github.com/beautifulcode/ssh-copy-id-for-OSX/master/ssh-copy-id.sh -o /usr/local/bin/ssh-copy-id
chmod +x /usr/local/bin/ssh-copy-id

Thursday, 16 January 2014

frendly if greek

#friendlyID Greek by Yiannis Deliyiannis
el:
i18n:
transliterate:
rule:
α: a
ά: a
Α: a
Ά: a
β: v
Β: v
γ: g
Γ: g
δ: d
Δ: d
ε: e
έ: e
Ε: e
Έ: e
ζ: z
Ζ: z
η: h
ή: h
Η: h
Ή: h
θ: th
Θ: th
ι: i
ί: i
Ι: i
Ί: i
κ: k
Κ: k
λ: l
Λ: l
μ: m
Μ: m
ν: n
Ν: n
ξ: x
Ξ: x
ο: o
Ο: o
ό: o
Ό: o
π: p
Π: p
ρ: r
Ρ: r
σ: s
Σ: s
ς: s
τ: t
Τ: t
υ: y
ύ: y
Υ: y
Ύ: y
φ: f
Φ: f
χ: ch
Χ: ch
ψ: ps
Ψ: ps
ω: w
ώ: w
Ώ: w
Ω: w
αι: ai
αί: ai
άι: ai
ΑΙ: ai
ΑΊ: ai
ΆΙ: ai
οι: oi
οί: oi
όι: oi
ΟΙ: oi
ΟΊ: oi
ΌΙ: oi
ει: ei
έι: ei
ΕΙ: ei
ΕΊ: ei
ΈΙ: ei
ου: u
όυ: u
ού: u
ΟΥ: u
ΌΥ: u
ΟΎ: u
αυ: av
αύ: av
άυ: av
ΆΥ: av
ΑΎ: av
ΑΥ: av
ευ: ev
εύ: ev
έυ: ev
ΕΥ: ev
ΕΎ: ev
ΈΥ: ev
ϊ : i
ϋ : i

Greek to_param

def to_param
"#{id}-#{name.tr("αβγδεζηθικλμνξοπρστυφχψωςΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩάέήίόύώ", "abgdezhuiklmnxoprstyfhsosABGDEZHUIKLMNJOPRSTYFHSOaeiiouo").parameterize}"
end
view raw Greek to_param hosted with ❤ by GitHub
Thanks to v.paraskevas