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
-- A Postgres 8.4 query against a table called 'trade_summaries' | |
-- This query makes use of WINDOW FUNCTIONS to provide access to the previous trading | |
-- day on the row for the current trading day. | |
-- The end result of the query is a set of market trading days with the interesting column being | |
-- the number of standard deviations that the difference in total trading value for the current | |
-- day versus the previous day is from the average difference between trading days. | |
-- What makes this query more verbose than it has to be is eacerbated by three limitations of Postgres: | |
-- (NOTE: there may be a good technical or theoretical 'correctness' reason for these limitations, | |
-- but I am obviously not smart enough to figure it out!) |
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
# I'm testing some code that translates HTTP query params from the front end | |
# into a query against a Solr via the Sunspot API. What I want to be able to | |
# do is unit test the query translation step *without* having to have Solr running. | |
# So I thought about mocking it out, but none of the mocking frameworks seem to | |
# be able to provide a way of mocking out something passed as a block. | |
# I have some HTTP query that my code 'executes' against Solr. It should be *exactly* equivalent | |
# to running the following query against Sunspot. |
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
# Here are the params to my QuestionsController update action. | |
# accepts_nested_attributes_for is defined on the Question model | |
# for its child relationship Choice. (Question has many Choices). | |
# Adding new choices to a question in bulk as shown below works except for the order | |
# that the Choices are created in. Choices use acts_as_list and have a list_index column. | |
# The order that update_attributes (on the Question instance) creates | |
# the Choice objects is the sort order of the hash keys below. The 'new_NNNNN' id | |
# within the hash is created in JavaScript using new Date().getTime(), so it always |
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 'rubygems' | |
require 'pp' | |
require 'wirble' | |
Wirble.init | |
Wirble.colorize | |
require 'hirb' | |
extend Hirb::Console |
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 foo(bar) | |
# CHALLENGE: write the body of this method such that | |
# when it is invoked, the second call to 'puts' below | |
# prints something different that the first call to 'puts'. | |
# Getting hold of the Ruby bindings object or reflecting | |
# over local variables is cheating and would not demonstrate | |
# pass-by-reference. | |
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
# So this is in my controller: | |
@items = Dir.glob("views/*/*").map do |item| | |
item.gsub(/views\/.+\/(.+).haml/, '\1') | |
end.select do |item| | |
!item.match(/^hide-/) && x != "index") | |
end | |
# Its contents look like this: | |
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 | |
# If your tables follow default Rails naming conventions (i.e. | |
# pluralized table names and #{model_name}_id foreign key names) then | |
# this script can run a quick report on your data and tell you if any | |
# of your tables contain references to non-existent rows in foreign key | |
# tables. | |
# | |
# If you had used referential integrity from the start, this script | |
# wouldn't be that useful. But for some people migrating from MySQL to |
NewerOlder