The old INSERT SELECT
A good example of SQL's favorite timesaver.
INSERT INTO `evo_bloggroups`
SELECT '4',
bloggroup_group_ID,
bloggroup_ismember,
bloggroup_perm_poststatuses,
bloggroup_perm_edit,
bloggroup_perm_delpost,
bloggroup_perm_comments,
bloggroup_perm_cats,
bloggroup_perm_properties,
bloggroup_perm_admin,
bloggroup_perm_media_upload,
bloggroup_perm_media_browse,
bloggroup_perm_media_change
FROM `evo_bloggroups`
WHERE bloggroup_blog_ID = 1
polymorphic user list class
I wrote this for a job interview that never panned out. Tune in next week for the matching User class.
Question: why do interviewers often admit to not being very technical, yet continue on to ask complicated questions and become bewildered as a consequence?
And furthermore, how good is the guy they hire if no one knows how to talk to him? Ah well, it is almost Christmas.
class UserList < ActiveRecord::Base
belongs_to :user_listable, :polymorphic => true
belongs_to :user
def invite_user(target_user, note)
if target_user
x = Invite.new
x.user_id = target_user.id
x.title = "user #{self.user.id} has invited user #{target_user.id} to #{self.user_listable_type} #{self.user_listable_id}"
x.note = note
x.user_list_id = self.id
if x.save
message = "#{x.title} - #{note}"
return message
else
return false
end
else
return "given user id matches nothing."
end
end
end
Ruby find_by_sql and a select statement
This is how I still do things. I don't think it's terribly old-fashioned. Databases are still faster than web servers, aren't they?
Summary.find_by_sql(["
(select 'GMG' name, 0 id, 1 orderby
from partners where 1=1)
union
(select display_val name, p.id, 2 orderby
from partners p where active = 1)
order by orderby, name, id"
])
Be a CSS Sherlock Holmes
Sometimes you want to do the right thing. Sometimes you want to do the right thing, AND it's possible. This is one of those times. I'm about as guilty as anyone for putting inline CSS all over the place, but I have rebuilt my blog and I am not going to make the same mistakes I did last time.
Question: how do you match a piece of 'source code' to the actual master style sheet reference?
Last year, I might have just overridden the inline div with a "style='display: xxx; color=NEWCOLOR;'" kind of thing, and shoved a bunch of css into the div wherever it happened to be. Today, not so much. Having just set up my new skin the way I like it, using a very few tweaks to the existing style sheet, I needed to track down a way of changing the color of the CODEBOXER.COM in the top left of my screen. You may appreciate that it is now a soothing and complimentary shade of charcoal. It used to be a very whorish red. What did I do?
I became a CSS Sherlock Holmes, and you can too!
STEP ONE: VIEW SOURCE
As you must know by now, anyone can view anyone's HTML just by right clicking on their web page. Of course, this isn't the whole show, because this 'source code' is fully 'executed', which is something we don't really need to worry about for this discussion. The reason we are doing it in this case is to see how certain parts of the website are referencing their CSS-ness, post-execution. Behold:

STEP TWO: SECURE THE EVIDENCE

STEP THREE: SEARCH FOR YOUR KEYWORD

and this is what you find:

Basically, the evo_title_area div begat the title_container div which begat the widget_core_coll_title div which within itself held an "a" tag which was enclosed in an "h2" tag.
Do we have enough evidence?
Wait for it...
div.evo_title_area div.widget_core_coll_title h2 a {
color: #4b473b;
}
div.evo_title_area div.widget_core_coll_title h2 a:hover {
color: #aaa;
text-decoration:none;
}
Extra points for the hover.
Yes, my routes are messed up
And I do apologize. My permalinks are gone. My podcast is down. You may have noticed.
I am having what is now a bit of a ritual December web asset rejuvenation party, and yesterday both http://digbox.net and http://codeboxer.com got smacked pretty hard. Anyway, I think this site looks better than ever and if you got here from a strange link, just press your back button, look at the link, press forward again and type something into the search box about it (top of the screen, on the right). This site is about quality, not quantity - so you will probably find what you are looking for.
Finally, if you need to look at a list of everything it is right here.
The podcast will be back up in a few days with new songs for everyone.
:: Next >>