Oct 16 2010
- 04/10/2011 - Updated application.js and application.rb thanks to @rebo's comments
In this article, I will walk through some simple steps to get a [demo app][2] up and running with [Backbone.js][3] and [Sinatra][4] on [Heroku][5].
| #!/usr/bin/env sh | |
| curl -lo beanstalkd.tar.gz "http://cloud.github.com/downloads/kr/beanstalkd/beanstalkd-1.4.6.tar.gz" | |
| tar xvzf beanstalkd.tar.gz | |
| cd beanstalkd-1.4.6/ | |
| ./configure | |
| make | |
| python -m SimpleHTTPServer $PORT | |
| CREATE OR REPLACE FUNCTION last_day(timestamptz) | |
| RETURNS timestamptz AS | |
| $$ | |
| SELECT (date_trunc('MONTH', $1) + INTERVAL '1 MONTH - 1 day'); | |
| $$ LANGUAGE 'sql' IMMUTABLE STRICT; | |
| CREATE OR REPLACE FUNCTION first_day(timestamptz) | |
| RETURNS timestamptz AS | |
| $$ | |
| SELECT date_trunc('MONTH', $1); |
| # Tab completion for tmux sessions. | |
| # Quickly open new tmux sessions in your projects dir. | |
| # Setup: | |
| # Source this code in your bash shell. | |
| # Update the code_dir var with the root directory of your source code. | |
| # Usage: | |
| # Use the tab to open an existing session. |
| # Streams of Data Part I | |
| ## Logging Basics | |
| # We don't need anything complex here. | |
| # We will use the logger in the stdlib. | |
| # Rails.logger works fine here as well. | |
| # Using Rails.logger is prefered as you won't muck up | |
| # the screen when running tests. | |
| require 'logger' |
| abacus.go | |
| Log Messages | |
| All of our production systems in The Vault have their | |
| STDOUT connected to Heroku's logplex. We also connect | |
| syslog draings to Logplex that outlet all messages to | |
| PaperTrailapp. Each system outputs two classes of | |
| messages. The first class of message is the system | |
| class. Messages of the system class are originated by |
| def lock_job | |
| attempts = 0 | |
| job = nil | |
| until job | |
| job = @queue.dequeue | |
| if job.nil? | |
| attempts += 1 | |
| if attempts < MAX_LOCK_ATTEMPTS | |
| sleep(2**attempts) | |
| next |
| module QC | |
| class Worker | |
| MAX_LOCK_ATTEMPTS = ENV["QC_MAX_LOCK_ATTEMPTS"] || 5 | |
| def initialize | |
| @running = true | |
| @queue = QC::Queue.new(ENV["QUEUE"]) | |
| handle_signals | |
| end |
| module Memstat | |
| extend self | |
| def puts | |
| "memory=#{real_mem_size} ruby_objects=#{num_objects}" | |
| end | |
| def real_mem_size | |
| mb = `ps -o rsz #{$$}`.split("\n")[1].to_f / 1024.0 | |
| mb = mb.round(-2) # nearest 100 (i.e. 60.round(-2) == 100) |
| QUERY PLAN | |
| -------------------------------------------------------------------------------------------------------------------------------- | |
| Limit (cost=21.03..21.04 rows=1 width=10) (actual time=0.063..0.063 rows=1 loops=1) | |
| -> LockRows (cost=21.03..21.11 rows=6 width=10) (actual time=0.062..0.062 rows=1 loops=1) | |
| -> Sort (cost=21.03..21.05 rows=6 width=10) (actual time=0.046..0.046 rows=1 loops=1) | |
| Sort Key: id | |
| Sort Method: quicksort Memory: 25kB | |
| -> Seq Scan on queue_classic_jobs (cost=0.00..21.00 rows=6 width=10) (actual time=0.035..0.036 rows=1 loops=1) | |
| Filter: (locked_at IS NULL) | |
| Total runtime: 0.105 ms |