Posts Tagged ‘coding’



few and far between, and project euler #15

Wednesday, September 24th, 2008

I feel crappy that I haven’t been updating, but I’ve got 12 hour work days. There’s that twinge of guilt about unattended blogs, but I’ll be in the back of a class supervising a lecture (like I am now, actually) and just think: “now’s not the time!”

But yes, I’m still around, and I haven’t forgotten my meag… erm, “highly exclusive” readership. So, how’s my week been?

Ok. Been working on fixing my damned pointers. I have one that keeps faulting when I delete it and I don’t know why. So, as angry as computers make me, I was glad this morning.

Why? I did a project euler problem (#15) without a lick of programming. The question was in a 20×20 grid, how many combinations of paths are there from one corner to the other. Welllllll permutations tell us it’s the factorial of 2 times of the size of your grid, all over the factorial of the number of possible choices multiplied by factorial of the the number of columns. In easier terms, that’s

(2n)! / ¹n! * ²n!

And since our grid is 20×20… well. You figure it out.

Hope to be back soon enough!

project euler #9

Friday, September 5th, 2008

Many of you know I’ve been sucked into the world of Project Euler. I love problem-solving with computers, and I love math, despite not being great at problem-solving with computers and being even worse at mathematics.
As of yet, most of my solutions have been brute-force attempts which get the answer quite ahem thoroughly, if not the most efficiently.
Well, project euler #9 involves calculating pythagorean triplets, and I’d left it for a while deciding it would involve a pain-in-the-ass buttload of calculating and would take about 20 minutes to run. However, I’ve been listening to The Teaching Company’s The Joy of Thinking, and they presented ways of calculating the pythagorean triplets that I’d never really thought of.
Anyways, this morning I was waiting around for a while between errands, and a napkin and 4 lines of python inspired me. All I had to do was reduce the fact that:
2mn+(m*m - n*n)+(m*m+n*n) = 1000
to
m(m+n)=500 and run through m and n with n < m. BAM!

[nate@pepper python]$ time ./peuler9.py
sum = 1000
product = *****

real 0m0.012s
user 0m0.010s
sys 0m0.000s

Yes, I removed the actual answer so as not to be a spoiler. However, I will include my full source code, as I’m amazed at how simple it was, and maybe you’ll enjoy it too.
(source code after the jump…)
(more…)

gah! school!

Monday, April 21st, 2008

Well, well. I’ve been really busy with school, as predicted. I’ve actually spent almost the whole day working on a presentation to my communications about the wonders of Linux. I actually made a really cool video for it, but I can’t post it, because it has Led Zeppelin’s Rock and Roll as the soundtrack. :)

Also this weekend… I’ve been working on a newer version of the Distrofy plug-in I was working on last week. Actually, now it’s very much evolved, as the work has been in batch-processing images from the web and setting them as the wallpaper. I have however added a few new distro logos as well. Hopefully I’ll be able to roll it out by next weekend. We’ll see how school goes this week!

i made a plugin

Monday, April 14th, 2008

Well, aside from getting ready for finals (ugh!), I had the inspiration of a group on Gnome Look to make a plug-in for the Gimp. The group “No Ubuntu Wallpapers” is based around the idea that there are way too many people just slapping the logo of their favorite linux distribution on a sexy picture and posting it as art. So, half tongue-in-cheeked, I made a plug-in that does exactly that!

Written in python for the Gimp’s Python-Fu scripting language, it takes an image (potentially of a sexy and scantily clad woman) and changes it to the colors and logo of popular linux distributions.

Here’s some examples.

Example 1

Example 2

Example 3

If you want to snag it, it’s available for download here.

if the python’s a-rockin, don’t come a-knockin’

Wednesday, March 12th, 2008

Update on the SEC parser. I’ve started rewriting it with xml.sax instead of xml.dom.minidom. I realized that since I’m already processing 100 pages at a time (despite the fact that it’s fast as balls already) it may as well be fast. And despite the fact that I’m writing more code to actually do what I need it to do, considering SAX is so much simpler, the code is easier to read and alot more fun to write. It’s straightforward, which is how I feel python should be damnit. Plus, it may make a big difference when I start multi-threading it to pull a whole month’s worth of the SEC’s database. That’s a lot of 4/a forms to read through. :)

back to the grind (and occasionally, hiss)

Monday, March 3rd, 2008

Well, spring break (or whatever you call the last week of February) is finally over. Of course, I still cleverly have Mondays off (isn’t that everyone’s dream?), so I got to enjoy my day worry free! Until about 9:30 AM. At that point, I called Nerine back thinking her leaving 3 missed calls on my cell phone must be important. Turns out, her car died. Or was dying. Actually, by all appearances it runs fine, but I guess it was having problems. Still, I digress.

So, I quickly got all my stuff together and was going to head to her work to pick it up, and then to the dealership (leaving my car with her) to take it in. Well, turns out I didn’t have to do that as early as thought (which led to a fantastic row between us over the phone). So I went back and decided I finally should get cracking on some code I started writing back in January for a friend.

I spent that fantastic 2 hours writing maybe 3 lines of python. See, the Securities and Exchange Commission provides access to all of their information on filings in a searchable database. That’s fine and dandy if you want to see one filing at a time. But if you want to analyze trends, you need ALL the data. And to subscribe to their live feed of data… a mere $31,000 per year. They do provide an ftp site that allegedly makes all of this information available, but I haven’t figured out how to dig through all of the data yet. First… I need to get the sample data I want organized how I want it, then I’ll worry about getting all of it.

After I got the car to the dealer, I luckily had Nerine’s laptop (thankfully, running Ubuntu, so it’s already got python and ruby on it) with me, and they had free wifi. I was able to get a little more done there sitting in their waiting room. Of course, that’s before George called.

Apparently, the computers at work are again going willy-nilly, but this time it’s on the server. Never good news. And of course, George has the folks from the company who make the barcode reader dialed in — via PCAnywhere. Ahh, hell of hells. These are the situations that make IT people shriek: (because…)

  1. PCAnywhere is SO terribly insecure in the first place.
  2. What the hell are you having the guy who makes the barcode reader dial in for? This man doesn’t manage the data flow in a production environment. He sells a product that just sends and receives our data for us! Without specific knowledge of our deployment of his device, he can’t do anything but perhaps break it more!
  3. The system he’s dialed in to has the master customer accounts. While it’s unlikely he’s untrustworthy or stupid enough to steal this information, that doesn’t mean he can’t break it disastrously if something goes wrong.
  4. PCAnywhere is really insecure.
  5. I’m the one who did the configuration (and in the end, provided the 2-minute fix)… had I been called first, none of the system’s integrity would be compromised in the first place!

So, that was the end of my working in python for the day.

I’ve also managed to complete my test for my Business on the Internet class. Good news. I think I survived Then again, I’m hoping my grade is inversely proportional to the amount of bullshit involved in that class. That would make my GPA something like a 4.1.

shouldn’t i be studying?

Sunday, February 17th, 2008

2 things:

  1. css display on IE sucks
  2. drupal is cool

I noticed in class on Friday that when I open the blog in IE, it looks like someone took a shit on my CSS. The blog entries roll all the way down, then the navigation is all at the bottom. Why IE, why? Worst part is, I can’t find anything WRONG with my code. I hacked away at it for a while and still nothing. I’ve tried changing all kinds of positioning rules and margins. No avail. IE just doesn’t like <div>s.
So, to that effect, I will now say: “This site is designed to be viewed in firefox on linux. If you don’t run that and it looks fine: awesome. If you don’t run that and it looks like poo: tough cookies.”

I’ve been playing around with drupal. I’ve had this idea to have a more serious site (of which this blog would be an offshoot) to host my code projects, school projects, and to aggregate all my favorite news into one spot. Looks like drupal will certainly do it. I also notice that there is a guide to theming it right on their website! Amazing. Take note here, wordpress people. :)

Maybe over spring break I’ll have some time to get that set up. Although currently, my hosting service doesn’t allow cron, so it’s not like the aggregation is gonna be THAT great.

Well, now I’m finally off to do some homework. I’ve actually got to take a test about, yes really — the vi editor. I guess it’s important to know vi if you’re gonna do any systems administration or programming on the fly. But sheesh! The worst part is, you’d be amazed at how many people just can’t handle it not being a word processor. Oy Gewalt.

interface hacking remandment

Wednesday, February 13th, 2008

Gah! I had some extra time in class today while our instructor went on about the wonders of Microsoft Office and how great Excel was before failing miserably to see glaring errors in the logic formulas she was demonstrating to us. She just couldn’t seem to get the formulas right, and damned if she was gonna type them in by hand — no she had to point-and-click them into existence. So yea, I had a good 20 minutes between short moments of needing to pay attention.

In that time, I was able to pour through the 1200 or so lines of Wordpress’ widget modules to set the navigation to use <div> instead of <table><tr><td>… but the divs don’t look as good. I like the uneven was the navigation looked when they were in tables. I have an idea why this is, but haven’t a solution to fix it yet:

Quite simply, the tables shrank themselves down to the size of the text they were surrounding. The divs, on the other hand, expand to the width of the column they’re in. I’ve just got to figure out how to make the divs shrink down to the size of whatever they’re encapsulating and I’ll be all set.

I’m just no CSS expert, and I can’t find an easy answer based on what results 1-10 of what Google has to offer me.
I’m sure a solution will come to me at some point, when I have more time to care.

interface hacking redux

Monday, February 11th, 2008

Apparently, it’s not as hard as I thought it would be to change the look of the blog here. Granted, it’s much easier that I like the default layout (posts on the left, navigation on the right, header and footer in boxes), so most of what I had to do was just bang away at the CSS until it looked like I wanted to. It was very much an experiment, as the software package is not written the way I like to write code.

(more…)

interface hacking

Friday, February 8th, 2008

I can see now it’s going to be a biatch to try and hack up this Wordpress interface. Or I should say, to hack it up the way I want it.

No wonder everyone just uses the theme templates.

I’m left with the hard decision: write my own? hack it up anyways? go straight to a Content Management system?

I like the number of options available, but I want the flexibility to push my information into whatever format I want. I’m sure once I take a better look at the Wordpress code, I’ll see how everything flows together. It looks pretty modular, but I didn’t see any big glaring signs that say “This is the code that spits out your sidebar” or “This is the code that produces your archive”. I of course found the index layout, but that’s only a minor part of it. For now though, I’ve too many other things I’m working on to give it much time. I’m sure it will be come blatantly obvious in time. If not, I’ll just write my own!