gem install rails
rails new my_app -T
| require 'zmq' | |
| context = ZMQ::Context.new | |
| pub = context.socket ZMQ::PUB | |
| pub.setsockopt ZMQ::IDENTITY, 'ping-pinger' | |
| pub.bind 'tcp://*:5555' | |
| i=0 | |
| loop do | |
| pub.send "ping pinger #{i+=1}" ; sleep 1 | |
| end |
| # An example of elasticsearch & Tire setup for ActiveRecord associations. | |
| # | |
| # A `Book has_many :chapters` scenario, with mapping and JSON serialization | |
| # for indexing associated models. | |
| # | |
| # Demonstrates three important caveats as of now: | |
| # | |
| # 1. You you have to use `touch: true` in the `belongs_to` declaration, | |
| # to automatically notify the parent model about the update. | |
| # |
| #Model | |
| @user.should have(1).error_on(:username) # Checks whether there is an error in username | |
| @user.errors[:username].should include("can't be blank") # check for the error message | |
| #Rendering | |
| response.should render_template(:index) | |
| #Redirecting | |
| response.should redirect_to(movies_path) |
| # Run with: rake environment elasticsearch:reindex | |
| namespace :elasticsearch do | |
| desc "re-index elasticsearch" | |
| task :reindex => :environment do | |
| klass = Place | |
| ENV['CLASS'] = klass.name | |
| ENV['INDEX'] = new_index = klass.tire.index.name << '_' << Time.now.strftime('%Y%m%d%H%M%S') |
HTTP is a stateless protocol. Sessions allow us to chain multiple requests together into a conversation between client and server.
Sessions should be an option of last resort. If there's no where else that the data can possibly go to achieve the desired functionality, only then should it be stored in the session. Sessions can be vulnerable to security threats from third parties, malicious users, and can cause scaling problems.
That doesn't mean we can't use sessions, but we should only use them where necessary.
| ActiveAdmin.register Milestone do | |
| scope :all, :default => true | |
| scope :global | |
| scope :user_specific | |
| index do | |
| column :title | |
| column :description | |
| column :required_litres | |
| column :is_active |
| #Model | |
| @user.should have(1).error_on(:username) # Checks whether there is an error in username | |
| @user.errors[:username].should include("can't be blank") # check for the error message | |
| #Rendering | |
| response.should render_template(:index) | |
| #Redirecting | |
| response.should redirect_to(movies_path) |
This gist is part of a blog post. Check it out at:
http://jasonrudolph.com/blog/2011/08/09/programming-achievements-how-to-level-up-as-a-developer
| require 'rubygems' | |
| require 'sinatra' | |
| require 'fileutils' | |
| # upload with: | |
| # curl -v -F "data=@/path/to/filename" http://localhost:4567/user/filename | |
| post '/:name/:filename' do | |
| userdir = File.join("files", params[:name]) |