Ben's blog

Quick Shell Tip: Find empty lines after closing PHP tags

If you’re using PHP to output XML, and you have empty lines outside of your <?php and ?> tags, you may insert empty lines before your opening XML tag - a big no-no. Apparently, that invalidates XML.

To detect this, use this Bash code in a directory of PHP files:

for file in `find -type f -name "*.php"`; do lines=$((`wc -l ${file} | cut -d' ' -f1`+1)); pos=`grep -Hn '?>' ${file} | cut -d: -f2`;  `(($lines != $pos ))` && echo $file ; done

Disclaimer: I wrote this code while in an unnatural state (who ever is?). It may break your code, impregnate your cat, cause your baby sister to fall madly in love with your microwave, or really, anything else. It even might (definitely) fail to check for newlines before you opening <?php tag! And it’ll complain if you don’t have a closing ?> tag (you’d be surprised how … inconsistent people may be). Anyway, don’t complain to me.

No More TrackBacks

I’ve turned off trackbacks for the site. I was getting large amounts of spam, and very little signal. Although my blog is pretty unknown, and doesn’t have a lot of visitors, the amount of spam was monumental - I don’t want to have to deal with it in the future. Also, the value was not very helpful. I have a couple of RSS feeds tracking mentions of my name and blog, so I’ll definitely know when someone writes about me. Like SMTP, TrackBacks are inherently broken - both were not designed with Evil in mind. So, until something better comes along (because, the idea is great) your only method of replying is by either composing an entry on your own blog, and leaving a comment here with a link (preferred) or, simply, leaving a comment with your reply. Whatever floats your boat.

The New York Times and The Death Of Old Media

Seeing as how I’m going to be working for the Times this summer, I’ve put in a bit of thinking about the role of news, newspapers, and journalism in today’s hyperconnected world. The death of paper newsletters has been predicted for a while now, but strangely enough, they are still around. Wired Magazine, in their 15-year anniversary retrospect, highlighted one of their unfulfilled visions: “The Death of Media”. Wired called for the death of “Old Media” over and over again, but Old Media is still around, and rumors of their death are exaggerated…for now.

Semester close, and Summer Internship

Whew! My final exam (Algorithms) is done, and the semester is over! It was lots of fun, (except for Physics) and lots of work (mostly, Physics), and I’m glad it’s over. Next semester promises to be lots of fun: highlights include Artificial Intelligence, Communication and Networks, and Software Engineering. That last one might be interesting. While I’ll have to draw endless UML diagrams, the Professor will also let use something other than Java (finally!) to write our web app, so I plan on using the opportunity to learn Ruby on Rails. About time. Anyway, looking forward to next semester, but until then, I have the whole summer.

So, a while back, I applied to a couple of places, in search of a summer internship. I spoke with VMWare, Google, The New York Times, and a few lesser-known places. I applied to the TimesSummer Internship Program, and after a great interview, I accepted - dropping midway out of the VMWare interview, and turning Google away outright (I might have went to Google if they hadn’t lost my first application, and the second later offer was as attractive as the first). So, this June and July I’ll be working with some talented people on the Platforms team for NYTimes.com, working on … something. They haven’t told me what, exactly, yet. But, I’m convinced it’ll be fun. As a perk, they are even paying for a place for me on Manhattan, in some NYU dorms. Future things I’m allowed to reveal about the internship and The Times will be found on the NYTimes topic page.

Learning Perl

I’m back to posting here after a long hiatus, mostly because I have something interesting to report. I’ve been avoiding/neglecting this site because I’ve been incredibly busy with schoolwork, but everything is getting more leisurely in a calm-before-the-finals sort of way.

Anyway, I have in front of me the thick (1k pages) 3rd edition of O’Reilly’s “Programming Perl”, graciously lent, because at some point, that’s what I hope to do. In preparation for this summer (more on that later) I hope to work my way at least partly through this tome, and in the process, hopefully post some reactions to the language as I go.

I guess I’d better be upfront about my prejudices and preconceptions: from what I’ve seen, I don’t think I’ll like Perl. I have a distaste for extraneous punctuation (eg, I try to leave parens and such off as much as I can when coding in Ruby, and I consider Ruby’s @variable an offense to the eye and sensibilities), and from what I’ve seen from Perl, it has plenty of extra $(%]&*# to annoy the hell out of me. I imagine I won’t like the lack of turtles-all-the-way-down OO that Ruby has, and I think the general lack of cohesiveness and cobbled-together inelegant TMTOWTDI messiness won’t sit with me well either. But hey, I’d love to be shown wrong – two favorite languages are better than one!

So, in general, expect some more activity at this place, and especially some more Perl posts.

UNIX tip: chmod's +X option

UNIX tip: from chmod(1): “The letters ‘rwxXstugo’ select the new permissions for the affected users […one option is:] execute only if the file is a directory or already has execute permission for some user (X)”. That is, when, for whatever reason, you’ve got a whole tree of files and directories, and you can’t enter some number of sub-directories because their execute bit isn’t set, you can either execute chmod -R u+x my_dirs, or, you can (now) execute chmod -R u+X my_dirs. The former will make all the files executable (Bad™) while the latter will make only directories enterable (or, otherwise-executable files executable for you). Handy to know.

How to sort your Twitter friends by update frequency

Have you ever wished you could sort all of the people you follow on Twitter by how frequently they update? Here is a Ruby script that will do that for you. It asks Twitter for your friends, and uses Gene Smith’s Tweeterboard.com to determine update frequency. (Follow tweeterboard to let it know to track your stats).

To use the script, simply download it below, edit the constants at the top of the file, at run: ruby friendstats.rb. (Optional step: unfollow your boring-but-prolific “friends”).

Feedback appreciated. Usual disclaimer applies: beware, may kill your cat, I’m not liable, etc.

Snippits 0.5.2 released

I’ve just released Snippits 0.5.2, my Ruby text expansion program for Linux. This version contains mostly bugfixes and documentation updates. The full changelog is below. I also have put together a roadmap of future versions of snippits, and what they might entail. Take a look; any feedback is appreciated.

  • Bugfixes
    • Updated README on how to use GPG-encrypted files. Please try it and report

Snippits featured on Lifehacker!

Kevin Purdy, editor at Lifehacker has an excellent post featuring setting up and configuring Snippits. Why not take a look? (Also, a birdie tells me there will be a new release of Snippits soon. Keep your eyes peeled. Peeled, like tangerines.)

Design Tweakings

I’ve been tweaking the design of the site for the past week or so, shifting elements around and mostly attempting to give the text a chance to breath. Because HTML sucks, my spring cleaning will undoubtedly broken something for someone, somewhere. So, if you are that someone, and you’ve noticed some bit over here broken, give me a ring, if you please, and let me know. Thanks. Oh, and I’m still not done, that sidebar over there is giving me trouble. Bear with me, please, I’m working on it. ­

Syndicate content
bk