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
| // Object literal code organization pattern. From Rebecca Murphy's blog: | |
| // http://blog.rebeccamurphey.com/2009/10/15/using-objects-to-organize-your-code | |
| var myModule = { | |
| 'config' : { | |
| 'option1' = val, | |
| 'cached_elem' = $(this) | |
| }, | |
| 'init' : function(config) { | |
| // provide for custom configuration via init() |
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
| set :domain, ENV["domain"] | |
| set :application, domain | |
| set :user, ENV["user"] | |
| set :destination, ENV["destination"] || domain | |
| set :web_conf, ENV["web_conf"] || ENV["environment"] || 'production' | |
| raise "please set domain=app.domain.name.com" unless domain | |
| raise "please set user=server_username" unless user | |
| set :port, ENV["port"] || 1234 | |
| set :repository, "." |
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
| # Bulk API design | |
| # | |
| # resources :posts | |
| class PostsController < ActiveController::Base | |
| # GET /posts/1,4,50,90 | |
| # post_url([ @post, @post ]) | |
| def show_many | |
| @posts = Post.find(params[:ids]) | |
| 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
| #!/usr/bin/env python | |
| import socket, time | |
| sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
| sock.connect(('localhost', 6379)) | |
| sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) | |
| time.sleep(2) | |
| sock.sendall('PING\r\n') | |
| print repr(sock.recv(4096)) | |
| time.sleep(2) |
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
| ------------ From Rake Task | |
| namespace :app do | |
| # Checks and ensures task is not run in production. | |
| task :ensure_development_environment => :environment do | |
| if Rails.env.production? | |
| raise "\nI'm sorry, I can't do that.\n(You're asking me to drop your production database.)" | |
| end | |
| 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
| # autoload concerns | |
| module YourApp | |
| class Application < Rails::Application | |
| config.autoload_paths += %W( | |
| #{config.root}/app/controllers/concerns | |
| #{config.root}/app/models/concerns | |
| ) | |
| end | |
| 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
| # from http://stackoverflow.com/questions/6499654/is-there-an-asynchronous-logging-library-for-ruby/6527134#6527134 | |
| require 'thread' | |
| require 'singleton' | |
| require 'delegate' | |
| require 'monitor' | |
| class Async | |
| include Singleton |
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
| set :test_log, "logs/capistrano.test.log" | |
| namespace :deploy do | |
| before 'deploy:update_code' do | |
| puts "--> Running tests, please wait ..." | |
| unless system "bundle exec rake > #{test_log} 2>&1" #' > /dev/null' | |
| puts "--> Tests failed. Run `cat #{test_log}` to see what went wrong." | |
| exit | |
| else | |
| puts "--> Tests passed" |
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
| # No yielding | |
| class NormPerson | |
| attr_accessor :first, :last | |
| def initialize(first = nil, last = nil) | |
| @first = first | |
| @last = last | |
| end | |
| def hello | |
| puts "#{@first} #{@last} says hello!" |
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
| ## just some ways to check if a url exists | |
| # method 1 - from Simone Carletti | |
| require "net/http" | |
| url = URI.parse("http://www.google.com/") | |
| req = Net::HTTP.new(url.host, url.port) | |
| res = req.request_head(url.path) | |
| # method 2 - from some kid on the internet | |
| require 'open-uri' |