Skip to content

Instantly share code, notes, and snippets.

outsidein@ey05-s00398 ~ $ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 6.0G 6.0G 0 100% /
udev 10M 124K 9.9M 2% /dev
shm 769M 0 769M 0% /dev/shm
/dev/sdb1 19G 2.4G 17G 13% /data
@jsl
jsl / gist:711058
Created November 23, 2010 01:06
cattr_reader
# File activesupport/lib/active_support/core_ext/class/attribute_accessors.rb, line 10
def cattr_reader(*syms)
options = syms.extract_options!
syms.each do |sym|
next if sym.is_a?(Hash)
class_eval("unless defined? @@\#{sym}\n@@\#{sym} = nil\nend\n\ndef self.\#{sym}\n@@\#{sym}\nend\n", __FILE__, __LINE__ + 1)
unless options[:instance_reader] == false
class_eval("def \#{sym}\n@@\#{sym}\nend\n", __FILE__, __LINE__ + 1)
end
@jsl
jsl / immediate_failure_formatter.rb
Created March 2, 2011 23:37
Untested Untested
require 'spec/runner/formatter/base_text_formatter'
require 'spec/runner/formatter/no_op_method_missing'
module Spec
module Runner
module Formatter
class ImmediateFailureFormatter < BaseTextFormatter
include NOOPMethodMissing
def example_failed(example, counter, failure)
def index
search = PartnerPage.find_all_by_indexed_name(params[:term])
names = search.hits.map do |h|
name = h.stored(:name_kword)
url = partner_page_url(h.stored(:friendly_id))
{ :value => name, :id => url }
end
SELECT DISTINCT message_id
FROM SELECT *, id AS message_id FROM user_messages WHERE user_id = ?
AND read = false AND parent_id IS NULL AS initial_messages
UNION
SELECT *, parent_id AS message_id FROM user_messages WHERE user_id = ?
AND read = false AND parent_id IS NOT NULL AS replies;
SELECT DISTINCT message_id
FROM SELECT *, id AS message_id FROM user_messages WHERE user_id = ?
AND read = false AND parent_id IS NULL AS initial_messages
UNION
SELECT *, parent_id AS message_id FROM user_messages WHERE user_id = ?
AND read = false AND parent_id IS NOT NULL AS replies;
Remember to use BigDecimal when multiplying floats in Ruby!
ruby-1.9.2-p290 :001 > 8.19 * 1_000_000.0
=> 8189999.999999999
for i in `git br -r | grep -v master | sed 's/origin\///'` ; do git push origin :$i ; sleep 1 ; done
@jsl
jsl / gist:1775007
Created February 8, 2012 22:38
Hacked SubTestTask that allows exit status to be returned after failing tests
module Rails
# Don't abort when tests fail; move on the next test task.
# Silence the default description to cut down on `rake -T` noise.
class SubTestTask < Rake::TestTask
# Create the tasks defined by this task lib.
def define
lib_path = @libs.join(File::PATH_SEPARATOR)
task @name do
puts "running sub test task #{@name}"
run_code = ''
justin ~/Code/atea $ lein clean
justin ~/Code/atea $ lein deps
Copying 4 files to /Users/justin/Code/atea/lib
Copying 2 files to /Users/justin/Code/atea/lib/dev
justin ~/Code/atea $ lein native-deps
WARNING: lancet namespace is deprecated; use lancet.core.
[WARNING] POM for 'org.clojars.pka:jdic-macos-tray:pom:0.0.2:compile' is invalid.
Its dependencies (if any) will NOT be available to the current build.
Expanding: /Users/justin/.m2/repository/org/clojars/pka/jdic-macos-tray/0.0.2/jdic-macos-tray-0.0.2.jar into /Users/justin/Code/atea