Skip to content

Instantly share code, notes, and snippets.

View woahdae's full-sized avatar

Woody Peterson woahdae

  • Seattle, WA, United States
View GitHub Profile
@woahdae
woahdae / r_app.rb
Created February 26, 2011 23:31
R.app brew script
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/'
# 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",
#!/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}'`
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
# # ...
@woahdae
woahdae / mem_bench.rb
Created January 18, 2009 00:01
benchmarking with memory reporting
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
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
@woahdae
woahdae / modified_query.json
Created March 18, 2015 05:58
Previous query minus 'nested' produces correct results
{
"from": 0,
"size": 10,
"sort": [
{
"_score": {
"order": "desc"
},
"boost": {
"order": "desc",
@woahdae
woahdae / base_query.json
Created March 18, 2015 05:54
Elasticsearch query returning no source fields
{
"from": 0,
"size": 10,
"sort": [
{
"_score": {
"order": "desc"
},
"boost": {
"order": "desc",
@woahdae
woahdae / settings.rb
Created March 3, 2014 06:57
settings.rb
module MyApp
def self.settings
Settings.instance
end
class MyApp::Settings < BasicObject
# so we can reference classes w/o appending '::'
def self.const_missing(name)
::Object.const_get(name)
end