Man, I wish I had known about this snippet earlier 1
as it would have made plenty of tooling around exploring (and even a job interview) easier. It’s much nicer than just sorting the whole mess after you decide it would take less time to find what you want then implement this very functionality.
# List instance methods without ancestor methods
String.instance_methods(false)
5 random reasons I love Textmate
- Run tests – command-r runs the current test file
- Run focused unit!!!! – command-shift-r runs the test your cursor is in.
- The TODO bundle – ctrl-shift-t compiles all your #FIXME #TODO and #CHANGED comments into a pretty little list
- goto file – command-t – a smart, easy, and quick way to go to a given file.
- wrapping/unwrapping – a variety of shortcuts and menu items to combine/un-combine lists of items, wrap text in delimeters, etc.
Leopard quicklook from the commandline 2
function ql()
{
qlmanage -p "$@" >& /dev/null
}
I don’t like how people are backgrounding it or trying to get fancy, primarily, because any of the scripts claiming to make the spacebar-kills-QL functionality work, didn’t. This way CTRL-C does what it should, instead. It also maintains the qlmanage functionality of slideshowing multiple params.
Be careful when you paste it to convert curly quotes back to straight quotes. >:|
rails javascript helper - capturing an additional level of block nesting within a content_for
When making a helper that takes a block, the yield causes it to output at the point of being called in the template. If the reason for the helper is to populate a content_for/yield variable, such as to put javascript in the head tag, you get duplicate output: once where it belongs when the content_for is yielded, and once where you call your helper. Instead, make use of capture(&block).
This helper
def javascript(&block)
content_for(:header) do
"<script type=\"text/javascript\">//<![CDATA[#{capture(&block)}//]]></script>"
end
end
when called like this
<%javascript do%>
alert('hi')
<%end%>
results inthis
<html>
<head>
<script type=\"text/javascript\">//<![CDATA[
alert('hi')
//]]></script>
if you have a yield :header in your head tag.
redirect_routing plugin : easy redirects in your routing and my patch accepted
Lars Pind’s redirect_routing plugin fills a gaping whole in rails routing’s claim to be an apache mod_rewrite replacement. With a simple
map.redirect 'old_path', the_usual_options_like_controller_and_action
you can handle redirecting old urls to the new rails functionality, or whatever else you want to do a redirect for.
My only problem was, since the plugin creates a controller to do this (behind the scenes, of course), it raised a “missing default helper path” warning on starting up the server. That was easily resolved by adding an matching, empty helper, and then submitting as much as a patch, which Lars applied pretty much immediately, so it seems he’s on the ball.
Angle cutting carrots
It just works better. I always thought it was just a way of cutting them so they look all fancy, but it has real advantages: they don’t roll away off the cutting board and they seem not to stick to the bottom of the pan/wok as tenaciously, since there is a little lip that your utensil and other veggies can catch under.
In memory delete from an rails Association - a counterpart to build 4
I don’t like how a lot of the association methods automatically go through to the DB. I like to be able to work with my objects in memory more, get them actually how I want, and then save to the DB. There are times that having instant DB saving go through can really mess with a object that is live on a site. For creation there is such a method: build. And for editing: an update won’t go through until you save it. There isn’t an obvious counterpart for deletion.
I found one by googling around for something else, and noticing people complaining about delete_if not working as they expected. delete_if does exactly what I want, operate on the collection without effecting the DB. Of course, this doesn’t do much good without a way to save it when you are ready. The easiest way I’ve come up with so far is to keep a copy of the initial ids array, and then compare to that later.
class Parent < ActiveRecord::Base
has_many :children
attr_accessor :initial_children_ids
def commit_delete_if_children
parent.connection.delete <<-SQL, "Delete_ifing children"
DELETE FROM children WHERE id IN ('#{(initial_children_ids - children_ids).join('\',\'')}')
SQL
end
protected
def after_initialize
self.initial_children_ids = self.children_ids
end
end
>> dad.children.delete_if { |child| child.id == 3}
>> dad.commit_delete_if_children
=> 1
>> dad.commit_delete_if_children
=> 0
The original IE team actively took out their spite on developers
I know we are not supposed to attribute to malice what could be covered by stupidity, but…. Unless they put someone who couldn’t tie their shoelaces, without almost choking to death on them, behind a keyboard as a key contributor, I can’t see how they managed some of the feats they did, other than out of a seething hatred for web developers to come.
Here is how to shrinkwrap a block level element around its contents, for instance.
#yourelement {display:inline-block;}
#yourelement {display:inline;}
Ya, that’s right, the second declaration on the exact same element doesn’t actually overwrite as it does everywhere else in CSS, but in a completely unprecedented move*, it combines with it in some unholy way to create a Frankensteinian abomination of css.
WTF, mate?
* No really, where else in ALL of selector style programming does overwriting a value not overwrite it. Hell in any programming that is a little bit of dark magic. Now I’m picturing the IE lead making a Faustian bargain to get his job, and then doing Mephistopheles bidding once he was there.
A couple handy Rails helpers - conditional comments and docttype 1
A buddy of mine, Tieg, from 12 Spokes wrote a Rails helper for conditional comments. That combined with Jeremy Voorhis’s doctype and html tag helpers clean up the top of my layouts nicely, when I use ERb. When I use Markaby, which takes care of doctype and html attributes for you, the conditional comments helper is still useful.
TextMate really is growing on me or how to activate project drawer via keyboard
TextMate may not be an obtrusive, in-your-face, I’ll do that for you”, IDE in the style Visual Studio, but the more I use it the more I like it. I think it fits the Mac better, somehow, both the pretty-side and the *nix roots – it’s like vim or emacs with a pretty gui. I could go on about all it’s little not readily apparent niceties that you discover as you start to use it, and I might over time, but first….
After getting QuickSilver set-up I’v been trying to rely on my mouse less. After a bit of that I was still constantly using the mouse for one particular task in TextMate, which lead me to a question: how to activate project drawer via keyboard?
CTRL-TAB will switch you back and forth between the drawer and the editor. Combine that with option-command(aka open apple)-[right|left] arrow for tab switching and you hardly need your mouse.

Articles via rss or email