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
def profile(unit = :M) | |
# trying to see where our memory is going | |
population = Hash.new{|h,k| h[k] = [0,0]} | |
array_sizes = Hash.new{|h,k| h[k] = 0} | |
ObjectSpace.each_object do |object| | |
# rough estimates, see http://eigenclass.org/hiki.rb?ruby+space+overhead | |
size = case object | |
when Array | |
array_sizes[object.size / 10] += 1 | |
case object.size |
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
require 'benchmark' | |
# Example: | |
# | |
# bm = MemBench.new | |
# bm.before_each {require File.dirname(__FILE__) + '/config/environment'} | |
# bm.benchmark("find") do | |
# Product.find(:all, :limit => 1000, :include => [:variants => | |
# :variant_descriptors])} | |
# 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
class MemoryProfiler | |
# Memory profiler from Ryan Davis | |
# http://www.zenspider.com/~ryand/memory_profiler.rb | |
# | |
# Just fire it up as MemoryProfiler.profile or use it with a block | |
# of code: | |
# | |
# MemoryProfiler.profile do | |
# # ... |
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 ruby | |
require 'net/smtp' | |
require 'socket' | |
class MemoryMonitor | |
def bloated_processes | |
# the '$11 $12 $13 $14 $15 $16' thing is an ignorant solution for something like '$11 *' | |
# 'grep -v packet_worker_runner' ignores backgroundrb | |
`ps auwx | grep -v packet_worker_runner | awk '{ if ($6 > 500000) print $2 "##" $6 "##" $11,$12,$13,$14,$15,$16}'` |
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
# If I have two named scopes with a :having clause, ex: | |
# | |
# class Product < ActiveRecord::Base | |
# named_scope :qty_ordered_gt, lambda { |number| | |
# { :group => "products.id", | |
# :joins => :line_items, | |
# :having => ["SUM(line_items.qty) > ?", number]} | |
# } | |
# named_scope :revenue_gt, lambda { |number| | |
# { :group => "products.id", |
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
require 'formula' | |
class RApp < Formula | |
# i386 or x86_64 | |
ARCHS = "x86_64" | |
# Leopard, Leopard64, SnowLeopard | |
SYSTEM = "SnowLeopard" | |
url 'http://cran.r-project.org/bin/macosx/Mac-GUI-1.36.tar.gz' | |
homepage 'http://cran.r-project.org/bin/macosx/' |
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
# Relevant for http://local.seomoz.org:3000/campaigns/1/rankings | |
Keyword.all.each do |keyword| | |
[ Week.current.previous, | |
Week.current.previous.previous, | |
Week.current.previous.previous.previous ].each do |week| | |
GA::KeywordMetric.create({ | |
"google_analytics_connection_id"=>2, | |
"google_analytics_engine_id"=> 96, |
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
Process: ruby [80361] | |
Path: /usr/local/rvm/rubies/ruby-1.9.2-p290/bin/ruby | |
Identifier: ruby | |
Version: ??? (???) | |
Code Type: X86-64 (Native) | |
Parent Process: ruby [80349] | |
Date/Time: 2011-11-14 16:42:57.491 -0800 | |
OS Version: Mac OS X Server 10.7 (11A2061) | |
Report Version: 9 |
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
module Tire | |
def self.inverted_aliases | |
aliases.inject({}) do |acc, (index, aliases)| | |
aliases.each do |als| | |
acc[als] ||= SortedSet.new | |
acc[als] << index | |
end | |
acc | |
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
# leaves around a pointer to the root mapping after use | |
def indexes(name, options = {}, &block) | |
@_mapping_pointer ||= @mapping | |
@_mapping_pointer[name] = options | |
if block_given? | |
previous = @_mapping_pointer | |
@_mapping_pointer[name][:type] ||= 'object' | |
@_mapping_pointer = @_mapping_pointer[name][:properties] = {} | |
yield |
OlderNewer