[ Posted by kevin
Tue, 17 Apr 2007 22:57:52 GMT ]
For some reason most rails associations allow :select as a parameter to limit which rows are loaded, but belongs_to doesn't.
Here's my (only rudimentarily tested) monkey-patch to add it:
module ActiveRecord::Associations::ClassMethods
def create_belongs_to_reflection(association_id, options)
$stderr.puts "MAKING REFLECTION"
options.assert_valid_keys(
:select, #added
:class_name, :foreign_key, :foreign_type, :remote, :conditions, :order, :include, :dependent,
:counter_cache, :extend, :polymorphic
)
reflection = create_reflection(:belongs_to, association_id, options, self)
if options[:polymorphic]
reflection.options[:foreign_type] ||= reflection.class_name.underscore + "_type"
end
reflection
end
end
module ActiveRecord
module Associations
class BelongsToAssociation @reflection.options[:select] || '*', #added
:conditions => conditions,
:include => @reflection.options[:include]
)
end
end
end
end
Technorati Tags: monkey patching, ruby on rails
Posted in Coding | 9 comments
[ Posted by kevin
Fri, 13 Apr 2007 20:51:29 GMT ]
I've been avoiding blogging about things that were overly technical for awhile, but screw it, I need more things to write about anyways, so I'll start sharing nuggets of knowledge here as well.
Rails eager loading lets you load sub-elements on the database level, which can be a huge speed increase, though sometimes at a database cost. In my experience, the biggest problem is that items I'm joining together often have a big 'description' column, that can cause memory issues if loaded too indescriminatingly.
@logs = ItemLog.find(:all, :conditions => "target_id=#{@user.id}", :order => 'item_logs.created_at DESC', :limit => 40, :include => 'item')
What I wanted to do was add :select => 'only_rows_i_want'. But rails doesn't let you use :select with :include.
So what I did was do it without the :select, and take a look at the log file to see what the generated query would be. Then I removed the items I wanted and used it as a find_by_sql query:
rows = ItemLog.find_by_sql("SELECT item_logs.`id` AS t0_r0, item_logs.`user_id` AS t0_r1, item_logs.`item_id` AS t0_r2, item_logs.`created_at` AS t0_r3, item_logs.`referer` AS t0_r4, item_logs.`target_id` AS t0_r5, items.`id` AS t1_r0, items.`user_id` AS t1_r1, items.`title` AS t1_r4 FROM item_logs LEFT OUTER JOIN items ON items.id = item_logs.item_id WHERE (target_id=#{@user.id}) ORDER BY item_logs.created_at DESC LIMIT 50")
Then how do you get it to make the sub-elements into the actual objects?
join_dep = ActiveRecord::Associations::ClassMethods::JoinDependency.new(ItemLog, ['item'], nil)
@logs = join_dep.instantiate(rows)
I've put the name of the class I'm doing the find on as the first parameter, the include field I used as the 2nd. It works great with rails 1.2!
Technorati Tags: ruby, rails, ruby on rails
Posted in Coding | 4 comments
[ Posted by kevin
Mon, 08 Jan 2007 21:20:50 GMT ]
I was thinking about this relative to my old post about designing web pages for different screen sizes.
I shall blog about this another day (if I'm going to share it with you instead of capitalizing on it by keeping it secret, but wait, then no-one would adopt it and it would fail. Perhaps that's then the real success of open source?)
In related news, apple recently got a patent for designing UI's based on screen-independent width values. Like all patents, seems kinda obvious, but here we are not doing it.
Technorati Tags: css, design, javascript, patents
Posted in Coding | 2 comments
[ Posted by kevin
Wed, 19 Apr 2006 18:03:35 GMT ]
I hate dealing with multiple screen resolutions. Can’t our socialistic welfare government just give everyone a 30” monitor and designers everywhere can rejoice?
I really miss tables. They were evil to use in design, but they worked so well! if you gave each cell a width, but not the overall table, the cells would collapse smaller if the screen was too small.
I’d use this in my current project, except that each cell needs a #pixels width, which then means that the spaces between cells vary, as it’s the cells themselves that are the same width. Which, for a navigation bar, look strange.
I’m continually amazed and inspired by the changes web2.0 has brought us, in terms of scriptaculus, delicious, ruby on rails, open design, and so many other things. We’re able to get so close to the programming power of a local program, but with the decentralize and social aspect of the web at our fingertips.
But just because we’ve been able to layer javascript and html so well, I still think we need a better underlying layout and programming platform. How long can javascript/CSS/HTML last? We outgrow everything, it’s just a question of how long…
Technorati Tags: css, delicious, design, javascript, rails, ruby on rails, web design
Posted in Society, Coding, Ambitions | 4 comments
[ Posted by kevin
Tue, 18 Apr 2006 00:42:38 GMT ]
OK, so Tara bring home a miniDV recorder that has firewire so she needs me to get it off her.
I plug it in. Nothing happens – damn!
I spend 20 minutes googling – nothing! Finally come across a forum saying maybe you need to use something like iMovie. I remember imovie being one of those huge space-wasting programs included with my computer, so I tab over and run it.
Yay! I turn on the camera. It says ‘import’, i click it… and it records the blank 10 seconds on the end of the tape. Aren’t these things supposed to be idiot proof? And I’m not even an idiot. I fudge with the DV camera’s controls to rewind the tape. Import again, finally a clip!
So now, how do I save this sucker? Sure, it will be File > Save, right? Nope, that’s as a wierd iMovie project, I want to export it as a quicktime/whatever movie. File->Export? Nope, no such thing. File > Share? Maybe. Email? Not really, i want control..
Finally, I find it under File > Share > Quicktime.
A simple user process diagram would have shown that this is so far from what people expect they’re going to be cursing the day they got started with this program. How do you spend so much time making an otherwise good product, but have such crazy UI issues? Someone hasn’t been doing enough usability testing…
As fun as it is to rant on Apple, usually their design is pretty good. The truth is, everyone does this. MS windows is even easier to yell about. Why is the damn start menu called the start menu? Why is there a start menu tree that isn’t related to the file structure? 99% of windows users have no idea what to do when something gets removed from their start menu.
Program grouping of items on the start menu – you’re working, suddenly something flashes and all of your windows are gone! So you open a new version of the program, and it’s not there either! Say you actually realize to click the sub-menu to get to your window – you’re in classic “this-takes-me-twice-as-long” mode. Sub-menus suck! And don’t even get me started about how many damned ‘advanced’ panels and sub-panels there are. Phew.
Often I think I can put myself in the user’s shoes and know what they’ll want. Clearly someone has thought this before and been terribly, terribly wrong. Does that mean I’ll start doing the actual user testing I claim is so important? I hope so, it’s so just so much work, and such a conceptually distant activity from actual programming. I mean, you have to, like, talk to people and stuff!
Technorati Tags: apple, design, windows
Posted in Society, Coding | 6 comments | 3748 trackbacks
[ Posted by kevin
Mon, 17 Apr 2006 13:49:53 GMT ]
Google adwords and google analytics use different methods of tracking a ‘sale’ for tracking marketing campaigns! Why!
Adwords has always had a nice way of tracking ROI - you put a small javascript file or image (I always just used the image) with the particular key and sale amount in the response page, and it coordinates it with whether the user got there from an adwords ad click. Nice and simple!
<img height=1 width=1 border=0 src=”http://www.googleadservices.com/pagead/conversion/1122/?value=amount&label=Purchase&script=0”>
Analytics has you put a hidden form in the result page text, along with a body on-load event. Huge pain!
<body onLoad=”javascript:__utmSetTrans()”>
<form style=”display:none;” name=”utmform”>
<textarea id=”utmtrans”>UTM:T|[order-id]|[affiliation]|
[total]|[tax]| [shipping]|[city]|[state]|[country] UTM:I|[order-id]|[sku/code]|[productname]|[category]|[price]|
[quantity] </textarea>
</form>
Is any of this information used besides the sale amount? Not anywhere I can see.
Keep it simple, please. One pet peeve of mine is when companies get so large their departments don’t talk to each other, google stay agile while you still can!
Technorati Tags: analytics, google, marketing, puppy
Posted in Coding | 1 comment
[ Posted by kevin
Sun, 16 Apr 2006 19:58:04 GMT ]
I’ve been working with ruby on rails for over a year now, and I couldn’t be happier with how well it’s done.
There have been frustrating times—just far fewer than there would have been using any other system (including my own I’d written, which I obviously knew back-to-front).
Interestingly enough, development hasn’t been any faster than it was previously! Crazy! The truth is: I expect any site I create to have so much more now, to be so much more well designed, to write test cases, for crying out loud. These things take time. Quality takes time.
I’m convinced it’s one of those “Murphy’s law” sort of things – any increase in productivity of the tool will be made up for by an increase of ambition in project design.
Anyways, here’s to Rails, the software pattern that makes me want to get up each morning, and change the world one community website at a time.
“Agile Web Development with Rails : A Pragmatic Guide (The Facets of Ruby Series)” (Dave Thomas, David Hansson, Leon Breedt, Mike Clark, Thomas Fuchs, Andrea Schwarz)
Technorati Tags: lighttpd, ruby on rails, social interaction, rails, web design
Read more...
Posted in Coding, Ambitions | 7 comments | 1069 trackbacks
[ Posted by kevin
Wed, 07 Dec 2005 16:35:11 GMT ]
Okay, so this is really weird. People at allpoetry are getting some strange messages –
Starhiker: 4 hours ago : casino buscan, historied Jack sag down beside the spruce, gestured at him wildly, wide-spread by her unlawfulness. casino condemned the gorses to death, but when they went to carry out the cherefullness the executioners learned that he flourish’d long-striding ; swords, casino, bitterish, even lightning, could chesterton no bulliciosa on his skin.
Ms Audrey: Nov 25, 4:36 : casino Said he, I know you will not tell a nasr-ed-din shelfful for the surplice : but for equivocation! could not compromise what Excusez could find in that non-society scribbling-paper, to endure her. tufts’s passe for a great share of our slade in life ; A play or a cosette is often widely-distributed of much of its casino if you sxi the casino beforehand.
words-are-the-way: Nov 22, 6:30 : casino She idolises uttered her rose-tinted against euclase with a shriek ever since the monster was begotten ; and till it evanish coolish the circonvoisins of the casino, she will traverse the rocking-stool on its track, dealing her glass-fragments upon its scraggin, and dashing against it her condemning zascandil.
All of these ims were to a user named ‘casino’. I’ve checked over the code, and it’s possible but very unlikely that there’s a bug that allows people to send messages as other people. More likely it’s some spyware they got on their horribly insecure windows machines, that automatically fills in and posts text areas. The internet is so wierd! It’s like wearing a robotic suit, and claiming that you didn’t graffiti the sidewalk, the suit made you do it…
These look a lot like bad markov chains, something I studied as a part of AI a longwhile back. The misspellings are strange, I don’t know why or how they would be introduced, and why not any web links? The code strips them out, so they were probably there initially…
PROOF!
I googled for “casino “for the surplice” (a phrase from the 2nd message)”, and came across someone’s guestbook (well the google archive of it anyways, since deleted):
casino Said he, I know you will not tell a nasr-ed-din shelfful for the surplice : but for equivocation! could not compromise what Excusez could find in that non-society scribbling-paper, to endure her. tufts’s passe for a great share of our slade in life ; A play or a cosette is often widely-distributed of much of its casino if you sxi the casino beforehand.
And here’s another one, still up for your viewing pleasure, and with links to some stupid casino website: http://preachers-kid.com/tp4a/pledges.php
This takes spam to a new level
Technorati Tags: casino, puppy
Posted in Society, Coding | 4 comments
[ Posted by kevin
Mon, 01 Aug 2005 17:10:32 GMT ]
I’ve been doing too much web-design lately. I’m in the part of the project when you start tweaking everything by 1 pixel, and get soooo pissed if it doesn’t line up just right.
Hopefully someone has a solution to this. Google couldn’t help me, as it’s too abstract.
In CSS, you set the spacing for your elements. So when I have a new first heading, I want 15 px of space above it, so it’s properly ‘set off’. But if that happens to be along the top of the page or a sub-element, then it’s 15 px down! Sometimes spacing is good, but in this case, it messes up the rest of the layout.
I was hoping to use one of the first_paragraph or first_element css elements, but they’re not supported by IE, and I couldn’t get them to work anyways.
Designing things ‘just right’ is hard, it’s always the last pixel that’s a killer. Or when people rescale the screen into really odd combinations and things run into each other. I have to say, designing with tables was far easier. I couldn’t do as much, but at least the paradigm was simple. CSS is wicked complicated.
Technorati Tags: css, web design
Posted in Coding | 1 comment
[ Posted by kevin
Wed, 29 Jun 2005 16:53:01 GMT ]
Last year I decided it was time to ‘get professional’.
For me, that meant buying a bunch of books on usability and studying ‘experts’ and the big web sites like amazon, etc.
Short rant: I hate amazon’s design. It’s always been hideous. The new one is a bit better, at least they realized having 300 tabs was confusing. But now there’s none! And they advertise movies + free shipping on their front page instead of books, talk about losing your perspective.
So I read ‘don’t make me think’, and several other good books. I’ve learned a lot. I think I’m pretty good at it.
Except now, when I design something, it seems like there’s one ‘right way’. I’ve gotten used to this using a programming language ‘ruby’, where we refer to it as the ‘Ruby way’. But design is supposed to be a creative and artistic process. Now making things simple enough seems to lead to one specific design that I like, but I don’t think is flashy or pretty enough. But I can’t change anything, because that would break my usability guidelines.
I’m looking forward to hopefully hiring someone in Pittsburgh to help with the design process. Except now that I’ve read all these books, I’m going to know way more than them. Hopefully it will work out, I really need someone to bounce ideas off, and to come up with creative color schemes and layouts themselves.
I’ve never been an amazing programmer, but now I’m not a good designer either! Uggh, this is progress?
Technorati Tags: design, usability, puppy
Posted in Art, Coding, Ambitions | 4 comments