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 |
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
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
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
# 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
# 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
-- 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
http://skitch.com/railsninja/n4xi5/job-futures | |
Above Url is the interface for the numbers I am trying to pull, Fuck me I have no idea how to try and explain this simply, we have been mindfucking this here for ages | |
1. Is from a table called placement_scores which needs to have numbers from the latest month, period_ending field (date) | |
2. Is also from a table placement_scores but needs to aggregate numbers from the 3 months prior to the latest month | |
3. Is from a table called outcome_scores which needs to aggregate numbers from between 7 months and 5 months prior using a period_ending value as well | |
It looks like 3 separate queries UNIONed together to me, like this: | |
select "Placement targets achieved in #{month_year}", count(*) from placement_scores where .... |
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
%p | |
Blah blah blah blah | |
%a(href='#foo') foo | |
and | |
%a(href='#bar') bar | |
\. | |
-# The problem with the above Haml fragment is that I am left with a space after <a href='#bar'>bar</a> and before the period. | |
-# Haml's whitespace removal does not resolve the issue, because it can either remove ALL whitespace | |
-# around an element or ALL whitespace within an element. Neither option seems to fit the bill. |
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 coffee | |
class Base | |
someMethod: -> | |
sys.puts "hello from Base" | |
class Derived | |
someOtherMethod: -> | |
someMethod() # error: method doesn't exist |
OlderNewer