Skip to content

Instantly share code, notes, and snippets.

View jpcody's full-sized avatar

Joshua Cody jpcody

View GitHub Profile

Keybase proof

I hereby claim:

  • I am jpcody on github.
  • I am jpcody (https://keybase.io/jpcody) on keybase.
  • I have a public key whose fingerprint is EDDD 586C 07D5 F92D 383A 3B75 2789 8F36 F964 A826

To claim this, I am signing this object:

@jpcody
jpcody / 1_original.rb
Last active August 29, 2015 14:04
A refactoring of a hairy Arel query in 5 steps.
# Bean.find_by_sql(query)
query = Bean.
arel_table.project(Bean.arel_table[Arel.star]).
join(Roaster.arel_table).on(Roaster.arel_table[:id].eq(Bean.arel_table[:roaster_id])).
join(City.arel_table).on(City.arel_table[:id].eq(Roaster.arel_table[:city_id])).
join(Rating.arel_table.alias("bean_ratings")).on(
Arel::Table.new(:bean_ratings)[:type].eq("Bean"),
Arel::Table.new(:bean_ratings)[:target_id].eq(Bean.arel_table[:id])
).

Here's the gist of the step-wise refactoring done during the talk. Included below are some specific links that were insightful to me as I dug in to this.

Modern Resources

$which_document = (array(
"_id" => $email_address,
'$elemMatch' => array('word_id' => $word)
));
$which_fields = array('$set' => array("status" => "complete"));
$collection->update($which_document, $which_fields);
@jpcody
jpcody / gist:649745
Created October 27, 2010 19:18
Pubsub Middle Ground
var search = {
getResults : function(){
$.getJSON(
'http://query.yahooapis.com/v1/public/yql?format=json&callback=',
{ q : getQuery(term) },
function(resp) {
if (!resp.query.results.result.length) { return; }
search.updateDOM(resp.query.results.result);
}
# Copyright 2008 Chris Wanstrath
# Taken from defunkt's gist repository: http://github.com/defunkt/gist/tree/master
require 'open-uri'
require 'net/http'
require 'net/https'
module Gist
extend self
scenario "A user should be able to save an opportunity" do
all('input[type="text"]').each{ |input| fill_in( input[:id], :with => "Test Data" ) }
all('select').each do |select|
option = first("##{select[:id]} option")
select( option[:value], :from => select[:id] )
end
click_on( "Save" )
end
scenario "A user should be able to save an opportunity" do
all('input[type="text"]').each{ |input| fill_in( input[:id], :with => "Test Data" ) }
all('select').each do |select|
option = first("##{select[:id]} option")
select( option[:value], :from => select[:id] )
end
click_on( "Save" )
end
## Semantic
<div class="childhood-story">
<label for="story-of-youth">A Story From Your Childhood</label>
<textarea name="story-of-youth" id="story-of-youth" cols="30" rows="10"></textarea>
</div>
<style>
div.childhood-story label {
vertical-align: top;
def top_align_label(form_field)
return "top-align" if form_field.is_a?( TextareaFormField )
return "top-align" if form_field.is_a?( FileFormField ) && form_field.reference
end