Programming Tip: Equality Checks

I don’t know about you, but I’ve gotten weird errors on occasion when I’m trying to write code like “if (i == 0)” and I inadvertently miss the double equals.  Then, you have a double whammy because the if statement will probably always execute, and then i is set to 0.  Bad Thing.

There’s a really easy way to avoid this, though!  Reverse the check: “if (0 == i)”.  The equality check is bidirectional, but you can’t assign a value to a numerical constant.  So, if you happen to miss the double equals, the compiler will throw an error instead of pretending you knew what you meant.

It’s hard to break years of habits, but it’s a darn good idea to retrain yourself.

Note that in Python, this is irrelevant because the Python interpreter won’t let you have an assignment in an if statement (it throws a SyntaxError).

The Stages of Writing a Program

“Oh, I have to write a robot that solves a maze?  Sweet, sounds like a great time to get inventive!  I’ll just create an artificially intelligent robot, no big deal.”

“Hmm, okay, maybe I can use Dijkstra’s algorithm.”

“Crap.  Well, I’ll just implement the right-hand rule.  That shouldn’t be so bad.”

“I guess I’ll just have it move randomly.  Gotta get this done!”


Interesting Technology of the Week – Chocolatey

So, there’s a package manager for windows that’s actually really well done.  By default it’s only got a command line interface but you can install a GUI through it if you want.

It’s called Chocolatey, and the selection of packages is pretty impressive.  For example, `choco install android-sdk` installs all those fun tools automatically and adds them to your $PATH.  Or `choco install 7zip` installs it and before you know it it’s ready to use.  There’s packages for most anything – JRE, Flash, VLC, Adobe Reader, countless development tools…it’s really handy.  And, of course, you can update what you have installed with it by `choco update`.

@powershell -NoProfile -ExecutionPolicy `
unrestricted -Command “iex ((new-object `
net.webclient).DownloadString `
(‘′))” `
&& SET PATH=%PATH%;%systemdrive%\chocolatey\bin

installs it.

It’s a lot like Homebrew for Mac or apt-get (or whatever your favorite package manager is: yum, yast, pacman, emerge…) for Linux.

Definitely worth a shot! I use it a ton.

IDEs and Programming Environments

After programming for 3 years exclusively in Eclipse and its brethren (Pydev, CDT, etc.), I’ve made a switch that I’m really happy about.

Don’t get me wrong, Eclipse is not a bad IDE, it’s just sometimes too bloated and cluttered and not quite powerful enough.  I really like that it has a plugin for everything under the sun and you can do all your development, in any language, in one program.  But it was time.

I tried many different IDEs, ranging from Apple’s Xcode, Microsoft’s Visual Studio, and many more.  I even tried going the text editor route, using both vim and Sublime, both of which are good at what they do, just not for developing code.

I found perhaps a bit of an underdog in IntelliJ IDEA and its brother PyCharm.  They come in two varieties – one open source, without some advanced features (e.g. Django development with PyCharm), or a more hefty version, with a hefty price tag.  For me, the so-called “Community Edition” works great.

You get all the cross-platform goodness and raw power of Eclipse, combined with the sleekness and elegance of Xcode, along with the code analysis toolbelt of Visual Studio.  It’s the best of all the worlds, I think.  And I’m happy with my move.

Interesting Technology of the Week – BitTorrent Sync

I’ve discovered a cool thing called BitTorrent Sync.  It’s basically Dropbox on steroids, using BT technology.  I’m always glad to see BT used for good, not evil.

You pick any number of folders to sync, and it provides you a secret for each which you can enter in on another computer – perhaps another computer of yours, a mobile device, or even a friend or family member’s computer.  It then syncs anything in those folders between the devices (and you can choose manually on the phone, where space is limited), just like Dropbox.  But it’s like having multiple Dropboxes, with no size limitations…that you can share with your friends completely if you want.  The only catch is, and it’s both a positive and a negative, is because BT is peer-to-peer, it can only sync if another device is on and connected.  That’s good because your data doesn’t go in the cloud, but bad if you have a handful of mobile devices but nothing that’s usually on.

Yes, it’s the BitTorrent protocol, which has some negative connotations.  Security-wise, everything is 256-bit AES and the most an attacker could figure out is the IP addresses of the devices you use.  As far as the app itself, it’s not currently open source, so it may not be for the paranoid, but for the average joe it should be fine.

You can also use it from the mobile app to backup a folder – say you don’t want to use Google+ or Dropbox, or you’ve run out of space on them.  You can have it sync your pictures to your desktop, or anything else you might think of (app backups, rom image “just in case”, etc.)

Ripple Carry Adder in Software

So, for a class I had to write a 32 bit ripple carry adder in C, using only binary operators.  This is what I came up with, although I’ve got to try and get rid of the increment operator, as I’m not sure I can use it.

[gist id="9443087" file="adder.c"]

For some reason, sometimes the gist viewer doesn’t work or load, so in case that happens, here’s the link.

Winter Break Over

Well, unsurprisingly, I didn’t finish all of my goals. But I actually made some progress!

  • I became reasonably competent in Ruby, although not Ruby on Rails.
  • I reached 1.0 in Pyberry (and beyond!).
  • I read Killing Lincoln but due to a mishap with ordering my new Kindle Paperwhite, didn’t read a book in Spanish.
  • I started to look at Android ROM development but decided it’d be easier to wait until I had my big desktop back.

I still feel reasonably accomplished! But now it’s back to school, and I’m already tired of that.

It was an…interesting first week. I had my first two days of classes, and then I got the news that my grandfather had passed away. So I decided to go spend time with my family and join together in celebrating his life (and not go to class for the rest of the week).

But now I’m back in class, and it’s boring and exhausting. I’d be a lot happier if the temperature would at least get above freezing…

Pyberry 1.0!

I’m very proud to announce that I’ve released version 1.0 of Pyberry. It’s been in development for over a year, and it’s my first project to ever hit 1.0/be reasonably stable. So, I’m very excited.

Pyberry started out after I realized there was no good way I could keep track of my books. I tried the heavy duty web apps, like Koha (which I’d worked with during my stint as a library page), and I tried a lot of different local programs, but none were quite right. So I decided to tackle it myself.

I wanted it to be portable; not only cross platform but also able to be used from multiple computers. Pyberry achieves the former by virtue of being written in Python, and the latter by using a single-file sqlite database, which can easily be put in something like Dropbox.

I wanted lightweight, yet easy to use, and it was a bit of a challenge creating a command-line interface that isn’t clunky or off-putting. But I think it’s simple enough my grandma could use it. (Remind me to have her try…)

I’m not saying it’s bug free at all, but I squashed all the bugs I could find and will now be using it to keep track of my library of over a hundred books.

I’m still working on packaging binaries/installers for it. Once I have them built, I’ll put them on the GitHub release page.

This is one of my Winter Break Goals I can definitively cross off. Don’t worry, there’s others to cross of, I just haven’t posted about them then. I figured Pyberry deserves its time in the limelight.

Winter Break Goals

Now that I’m back from sunny Belize and the holidays are over, it’s time to do something so I’m not bored. I go back to school on February 3. Until then, I have a few things in mind to do this winter break…

  • Become competent in Ruby on Rails
  • Reach 1.0 milestone in Pyberry
  • Begin work on Rubeus
  • Read two additional books, one each in Spanish and English (already finished Harry Potter y la Piedra Filosofal & A Clash of Kings)
  • Work on super secret project, codename Hrothgar
  • Stretch goal: Delve into Android ROM development

I’ll be sure to keep you posted on my progress, if for no reason but to motivate myself. Happy new year to everybody!

Public Service Announcement

I’m sure everybody’s seen it in the news, but just in case you haven’t, here’s an announcement.

Target’s debit/credit card readers had malicious software installed on them around Black Friday which enabled attackers to skim card details from anybody who has shopped there since Black Friday.

So if you have used your credit or debit card at any Target between today and Black Friday, you need to call your bank or card issuer and get it canceled and order a new one.

Again, this has been a public service announcement. If you’ve shopped at Target recently, order a new credit/debit card.