My Octopress Blog

A blogging framework for hackers.

Make With Multiple Cores

I was building something, and I remembered a friend was saying a while ago that you could tell gcc how many cores to use when building something. I don’t know if that’s true or not, but it turns out you can certainly tell make: make -j(number of cores to use)

For example, make -j2

I took a screen capture of System Monitor after building each way (make and make -j2), to see the difference. The first box is using just one core, and the second is using both.

Multicore Make

I had initially thought I’d have to tell gcc, and so I had planned to edit the makefile to automatically find the number of cores on the system, and then run gcc with that as an argument, so I went in search of how to find the number of cores on a Linux system. It turns out the easiest way to get that number that I came across was to use /proc/cpuinfo: cat /proc/cpuinfo | grep 'cpu cores' | head -1 | sed -r 's/^.+([[:digit:]]+)/1/'

Sum of Combinatoric Terms

Matt Matteson had a homework problem dealing with (n+a)^b, and finding a bound for it. Expanding this and evaluating it at n=a piqued my curiosity about the sum of each of the binomial expansion terms. That is to say, the sum of bC0 + bC1 + … + bCb. Well, I explored it a little bit, and did a quick-and-dirty writeup of my findings:

Sum of Combinatoric Terms

KAUST Acceptance

I found out yesterday that I got into KAUST. ‘Nough said? Well, maybe I need to add a “w00t!”

Your Introduction to RSS

I recently told my grandmother and cousin-in-law, Wess, about RSS feeds, and both of them said they had been wanting something like RSS for a long time. I told them a little bit about how it’s implemented and what is means, but I wanted to put a quick-and-dirty guide to your introduction to RSS.

RSS stands for “really simple syndication,” and it’s a list of current items on a website. When new items are added to said website, the RSS feed, as it’s called, gets updated with the new information. Since you need a client to really make use of your various feeds, it can keep track of which items you have seen and which you have not, and advises you as such. In this way, you can keep track of the current content on a multitude of websites without visiting each explicitly - the news comes to you.

First you’ll need a client. For Mac, I’d recommend NetNewsWire, which you use in conjunction with your NewsGator account. NewsGator actually has an online client that is synchronized to your desktop client, and it’s pretty useful for when I’m not on my personal machine. For Windows, About.com has compiled a list of their top 10 clients.

From there, you’ll make the rounds to your favorite websites and look around until you see the RSS feed logo, RSS Feed Icon or the words “RSS Feed.” When you click on it, you’ll be taken to a URL that is the feed itself. You want to add this URL to your client by adding a new subscription, and copying and pasting. For example, the feed on my website is http://dan.lecocq.us/wordpress/feed/.

Once you’ve added all of your most-visited sites, you can begin using your client as you would say, an email client - reading all the new items as they’re delivered to you.

That, essentially, is the long and the short of it. If I’ve left out points or there’s something you think I should add, I’d encourage some discussion in the comments.

Too Late

After tossing and turning in bed for what turned out to be three hours of not being able to sleep, I decided to get on my computer and get some reading done. Seriously, my RSS client’s inbox has been around 700 for a couple of days now. Sure, I just clicked “mark as read” for a lot of it, but I did get through a serious chunk:

No New Items

I remember that around 1 o’clock, I listened to Elliott Smith’s “2:45 AM” and hoped it wouldn’t come to that.

Tips for getting to sleep? Leave ‘em in the comments. No meds though. I kicked my Ambien habit.

KAUST

This summer I submitted my application for the Discovery Scholarship at King Abdullah University of Science and Technology in Saudi Arabia. It would pay for my last year of school here, cost of living, travel, tuition there, and a stipend to buy a new laptop. Well, when you have the fifth largest endowment in the world, I guess you can afford to do that sort of thing.

At any rate, I nit-picked an essay (they wanted an essay of 50 lines or less detailing academic achievement, international experience, statement of purpose, etc., so it’s bound to be a paced a certain way), and got letters of recommendation from three of my professors. Specifically, Graeme Fairweather, the department head, Mike Colagrosso, a recently tenured professor who just left us for the private sector (you’ll be missed, Mike), and Yong Bakos, a first year professor. All in all, I felt pretty good about my application.

Well, earlier this week I got an email saying that I had been selected as a finalist. Of the 2300 who applied, they whittled it down to 672 students (of whom they’re saying they’ll accept 500); 99 of these are from the US or Canada. Making it to the finals means that they’re going to fly me out to Washington D.C. for an interview this weekend, about which I’m very excited. I’ve never been back east, and it will give me a chance to see my cousin Elizabeth and her husband Wess, who live in Arlington, VA. The KAUST people even let me delay my departure so I could spend Labor Day weekend with them. Hooray!

At a recent dinner, my mother mentioned that she was praying I didn’t get accepted. Something about the perceived danger of living in the Middle East for two years. At any rate, things are looking up, and at the very least, I’ll get a trip to D.C. out of it.

It really looks like a beautiful campus and a unique opportunity. I would be in their first graduating class, getting my Master’s when I finish. I have a knack for being in the early graduating classes for schools. I was in the second class out of my middle school, and I was in the second class to graduate from the IB program at Niwot.

For more on KAUST, visit their website.

Injection Attack

For those of us familiar with SQL, we’re almost certainly familiar with SQL injection attacks. We’ve talked about them in class, and maybe the more nefarious of us has even tried it on a form or two. There are vulnerable ones out there - I remember having to tell an experienced programmer about sanitizing his form input. If you’re reading this, you know who you are.

For those of you who don’t know about SQL injection attacks, the long and short of it is you try to give input in a form that will be interpreted as SQL and executed. So, for example (see comic link below), you might try to give input that deletes records, or inserts malformed records. For example, a simple, well-formed request to insert a comment might be:

INSERT INTO `comments` (`name`, `comment`) VALUES ('Bob', 'My comment');

If Bob’s comment has a quote in it, though, if you haven’t sanitized the input, you’ll get something that doesn’t make any sense to the interpreter:

INSERT INTO `comments` (`name`, `comment`) VALUES ('Bob', 'It's my comment');

Say Bob were feeling malicious, part of his comment could be an entirely new command that the interpreter would deem valid. If his comment were “Haha suckers!’); DROP TABLE comments;”, then we’d get two well-formed commands that would get executed:

INSERT INTO `comments` (`name`, `comment`) VALUES ('Bob', 'Haha suckers!'); DROP TABLE `comments`;');

This, as you can imagine, is not desirable. So, part of sanitizing input is to escape out characters that are normally recognized by the interpreter:

INSERT INTO `comments` (`name`, `comment`) VALUES ('Bob', 'Haha suckers!'); DROP TABLE `comments`;');

At any rate, a few months ago, I actually had an attempt more or less ‘caught on tape’ in the comments section of my blog. I got an email that there was a new comment awaiting moderation, and it was this:

Bill164415140′,’311521868billy@msn.com’,”,’30.68.179.4′,’2008-03-12 16:12:16′,’2008-03-12 16:12:16′,”,’0′,’lynx’,'comment’,'0′,’0′),(’0′, ”, ”, ”, ”, ‘2008-03-13 16:12:16′, ‘2008-03-13 16:12:16′, ”, ’spam’, ”, ‘comment’, ‘0′,’0′ )

Not exactly the most harmful stuff. Still, it was nice to see an attempt in the wild.

Another good example is this xkcd comic.

Coffee and Cigarettes

During my time in Japan, I picked up a new habit - smoking. I would let myself have on cigarette per day, and I would save it until the evening. I would sit out on my tanning chair with a cigarette, a Kurt Vonnegut book and “Cafe au lait,” and just enjoy the quiet Japanese evening. The crackling of the cigarette and slowly burning ember are among the things I enjoyed most. As I write this, even, I’m enjoying a clove cigarette. I just accidentally ashed on the floor. Oops. Apparently for the crackling of cigarettes in movies, they use cloves because they’re so much louder. A film-major friend of mine said that the mics can’t pick up that of a normal cigarette. Clove smoke is so much thicker, too. It rises up like a beautiful plume. The taste is toxic. Somehow I’ve always found it satisfying. It’s like breathing poison. Fill my lungs.

Chocolate Milk

Tonight I saw Shireen, and in fact, it’s just now that I’m returning. I’m so completely infatuated with her, and we’ve spent many nights in the last couple of weeks cuddling and kissing softly. She told me tonight that kissing me is like Chocolate Milk - warm, sweet, and makes her feel tingly. She’s so sweet.

I told her that kissing her fills me with pride and awe and makes me feel very flattered that such a wonderful girl and beautiful creature would kiss me.

A few weeks ago I told her that I had a crush on her. I actually told her twice - the first time when more than a little drunk, and the next night I told her as I had intended. A couple days afterwards, she informed me that she liked me, as well. I paused, and apparently looked expressionless for a few seconds, which lead her to briefly think that she had said something wrong, but then I said, “I’m ecstatic! This really makes my night.” I had just walked her to her car, and she about to be on her way home. I wished her a good night, and walked off, but even then I wish I had kissed her. She was already seated in her car, so it probably would have been awkward, but all the same, it just would have been the perfect flourish to wonderful news.

Since, we’ve spent probably 7 of 9 evenings together, holding each other, watching movies, and just generally twitterpated. What a lovely girl.