I’ve had the opportunity to work with Rails for a good three weeks straight, now. Not just evenings and “spare time”, like I might have before, but actually all day. Most of that has been front-end work, views and the like, but enough of that is tied to other parts of Rails that you definitely start to get a better picture of how it all fits together.
Hence the title, as I realize anew what everyone already knows, that you learn more by doing something than by reading about it.
Continue reading ‘Startlingly Obvious Truism Becomes Revealed As More True Than Previously Thought’
I’ve been lamenting the loss of Shiftspace silently and sullenly ever since I upgraded to the beta versions of Firefox 3 last year. I really didn’t want to downgrade and wait, though, since I was experiencing a few unhappy issues with Firefox 2 on Mac OS which happily disappeared with version 3. So, I did without Shiftspace, cool though it may be.
No longer: there is a version of Shiftspace available which works with Firefox 3.0… you can find it here; you will want to click on the “release userscript” in the bottom right-ish corner.
Should I add you’ll need Greasemonkey, first? Well, I guess I have, now.
While searching for this, I happened upon an app called Lily, which is a visual programming environment written in Javascript:
Lily is a browser-based, visual programming environment that lets people create programs graphically, without writing code, by drawing connections between data, images, sounds, text and graphics. Lily’s cross-platform, free, open source and is written in JavaScript. Did we mention it’s fun?
What does it all mean? I don’t know! Isn’t “it’s fun” enough for you?
K2 is a great WordPress theme, and one of it’s strongest features is it’s ease of customization. However, if you want to add anything other than just stylesheet changes — such as Google Analytics, or some adsense code in a place other than the sidebar — you still have to edit the main template, giving you something to remember every time you update to the next version of K2.
Or do you?
It turns out that you don’t, now that K2 has added hooks to their main templates.
Continue reading ‘Using K2 Hooks’
In a site I’m working on, I was using jQuery’s load() function to insert content into a div from a navigational menu. Seemed pretty straight forward. The original code looked like this:
1
2
3
4
| $(".some_class").click(function () {
var link = $(this).attr("title");
$("#div-content").load("some/path/" + link + "/index.php");
}); |
Continue reading ‘Strange jQuery.load() behavior’
I used a little jQuery last night to clear some form fields. The basic idea was, there were a couple text inputs in the form for first and last name; rather than label the fields, I made the value of each form to be initially “First” and “Last” respectively.
Then I was requested to make it so that when the field was clicked on, the word “First” or “Last” (respectively) would disappear, so that you could then proceed to enter a value without needing to highlight and delete the existing value of the text field.
It turns out that with jQuery, this is simple enough; let’s assume your field has the class “clearme”:
Continue reading ‘Clearing Form Fields with JQuery’
Was playing a little with Io. I like one of the options for the conditional if; you can basically just pass “if” three arguments; a statement, something to do if it’s true, and something to do if it’s false.
So you can do simply:
Io> a := 3
==> 3
Io> if(a%2==0, writeln("a is even"), writeln("a is odd"))
a is odd
==> nil
I know, in ruby you could just do a%2==0?"a is even":"a is odd", and similar in other languages. I do like the idea of if looking like a function to which I’m passing arguments, though. Just seems intuitive, somehow.
Yesterday evening Ruby on Rails came up while talking to my mom, and I decided to try to explain what a framework was. I wound up comparing a framework to a sonnet.
If you’re writing a poem, and you decide to write a sonnet, you have a lot of little things decided for you right away. You now know the length of the poem, and the general structure. You know how long each line will be, and you even have some criteria for the content (iambic pentameter and a certain rhyming scheme). Other than that, you can do whatever you want.
It’s by no means a direct analogy, but because my mom knows what a sonnet is, the concept of a framework made sense to her right away.
I may have overreached just a little to use sonnets as the example. Maybe frameworks are more like limericks. Same idea, though.
I know this is first year computer science stuff, but it can be fun to play with.
Suppose you want a simple, general purpose function to find palindromes. Here’s what I came up with; we’ll name it “ispal.py”:
#!/usr/bin/python
import sys
import re
q = sys.argv[1]
q = re.sub(”(\s+|’|\.|\,|\!|\?|\:|\;)”, “”, q).lower()
print q==q[::-1]
Line by line, it’s pretty simple.
Continue reading ‘Detecting Palindromes With Python, Revisited’
More and more I’m seeing people disparage Python over the whitespace issue. What’s most disconcerting is when the same group embraces YAML, Haml, and Sass, because for some reason it’s okay if they have significant whitespace.
I don’t buy it. Yes, when you’re new to it, it’s frustrating to have bugs that are only the result of whitespace, or lack thereof. But if you’re new to a language, syntax errors are just something you learn by making them; I daresay that everyone learned to end lines with a semi-colon in [insert appropriate language here] just by forgetting it a few times.
On top of that, I’ve yet to see anyone who doesn’t prefer clear, well indented code, to sloppy hard-to-read code.
I like to use a variety of languages, and even though Python’s not something I use very much right now, I fully expect to use it in the future, and would do so happily. It’s a great language.
So what’s the big deal with whitespace?
(I almost called this post “All Whitespace Is Significant”, planning to point out you at least need to put a single space between tokens so that your code can be parsed, but I figured the flames telling me I didn’t understand “significant whitespace” wouldn’t be worth it… ;) )