Laser Etch My Macbook Air
Dear Lazyweb,
I would really like to Laser Etch my Macbook Air with Martha Stewart's face. Where can I get that done? How much would it cost?
Posted by Aaron Patterson • Permalink • Comments (6) • Leave your Comment »
Dear Lazyweb,
I would really like to Laser Etch my Macbook Air with Martha Stewart's face. Where can I get that done? How much would it cost?
Posted by Aaron Patterson • Permalink • Comments (6) • Leave your Comment »
The Mechanize library is used for automating interaction with websites.
Mechanize automatically stores and sends cookies, follows redirects,
can follow links, and submit forms. Form fields can be populated and
submitted. Mechanize also keeps track of the sites that you have visited as
a history.
Changes:
# Mechanize CHANGELOG
## 0.7.5
Fixed a bug when fetching files and not pages. Thanks Mat Schaffer!
Posted by Aaron Patterson • Permalink • Comments (0) • Leave your Comment »
Despite the recent Ruby webserver speed contests, most of the slowness at my job results from slow (or too many) database queries.
To help keep database queries down, I added a stats to every page that shows the number of queries vs. cache hits, the number of rows returned, and the amount of data transferred from the database. In this screenshot I'm using the "live" environment, 3 cache hits, 169 misses, 577 rows returned, and 458.9k data transferred. Clicking the box hides it, and clicking "Super Hide!" hides the box and sets a cookie so that the box doesn't show up again for a while.
To get this working, first I monkey patch the MysqlAdapter to collect database stats:
def self.get_stats
{ :queries => @@stats_queries,
:rows => @@stats_rows,
:bytes => @@stats_bytes }
end
def self.reset_stats
@@stats_queries = @@stats_bytes = @@stats_rows = 0
end
def select_with_stats(sql, name)
bytes = 0
rows = select_without_stats(sql, name)
rows.each do |row|
row.each do |key, value|
bytes += key.length
bytes += value.length if value
end
end
@@stats_queries += 1
@@stats_rows += rows.length
@@stats_bytes += bytes
rows
end
alias_method_chain :select, :stats
end
Next I patched the QueryCache to keep track of hits and misses:
def self.get_stats
{ :hits => @@hits,
:misses => @@misses }
end
def self.reset_stats
@@hits = @@misses = 0
end
def cache_sql_with_stats(sql, &block)
if @query_cache.has_key?(sql)
@@hits += 1
else
@@misses += 1
end
cache_sql_without_stats(sql, &block)
end
alias_method_chain :cache_sql, :stats
end
Then modify ActionController to reset stats for each request:
alias_method_chain :perform_action, :reset
def active_record_runtime(runtime)
stats = ActiveRecord::ConnectionAdapters::MysqlAdapter::get_stats
"#{super} #{sprintf("%.1fk", stats[:bytes].to_f / 1024)} queries: #{stats[:queries]}"
end
end
Just drop all that inside the after_initialize in your development.rb and you'll get the nice stats. After that, just create a partial that displays the stats and include the partial at the bottom of your layout. Our partial looks like this:
It's a little work, but it helps keep my mind on reducing the queries. With enough work, one of these days the speed of the webserver will matter to me. Thanks to Adam Doppelt for the basis of this monkey patch. Any bugs are mine, not his!
Posted by Aaron Patterson • Permalink • Comments (2) • Leave your Comment »
The Mechanize library is used for automating interaction with websites.
Mechanize automatically stores and sends cookies, follows redirects,
can follow links, and submit forms. Form fields can be populated and
submitted. Mechanize also keeps track of the sites that you have visited as
a history.
Changes:
# Mechanize CHANGELOG
## 0.7.1
Handling 0 length gzipped responses. [#17471]
Posted by Aaron Patterson • Permalink • Comments (1) • Leave your Comment »