Posts Tagged ‘code’

The Importance Of Having A Fast Computer For Coding

MX_Revolution_02.jpgA fast computer is important for a coder. It may be obvious, although, some people think, “hey, I just code, I don’t do anything that is graphic intensive, I can code fast enough with my 486DX2-66 with 8MB of RAM”.

What they don’t realize is that although the computer is fine for coding once you have your IDE open, it is task switching that can add up to wasted time. Every second spent launching a program counts. For instance, if there is a slight delay in your browser and it takes 10 seconds to launch. You could be looking at 5 minutes or more of wasted time daily. I have an Intel Core 2 computer at work, and although at times

I push it to its limit and have to wait for it to catch up, I know that when my browser opens instantly I am saving time.

Input devices can have a similar impact. Specifically the MX revolution mice series. When I first used a regular scroll wheel mouse I thought, “nice, this is such a time saver”. I didn’t have to press page down or click on the scrollbar arrows anymore. Then recently I tried a revolution mouse. Wow, what a difference. This mouse flies through code or data, slices and dices noisy log files and can completely change gears when you need precision click-to-click control.

A new concept for navigating documents and folders, the MicroGear Precision Scroll Wheel operates in two distinct modes. In free-spin mode, the familiar ratchet-scrolling mechanism retracts, allowing the wheel to spin for up to seven seconds, providing hyper-fast, nearly frictionless long-distance scrolling. In its normal click-to-click mode, the wheel allows users to navigate small distances with great precision, such as individual spreadsheet rows, or small vertical distances in a document or Web page. Switching between the two modes is either done manually or managed automatically by Logitech’s SmartShift technology.

The revolution really does revolutionize mousing making mouse use more enjoyable. Two notes about these mice and Logitech scroll wheels in general. One, be careful not to drop the mouse on the scroll wheel, it will break the tactile feedback on the middle click. I’ve tried to fix the issue but both times it seems like its missing some part. Two, don’t place a wireless router in between the mouse and the receiver. It will cause random pauses while you are moving the mouse. What are you using for coding? Are there any devices that save you time?

Ai

Ruby Did My Taxes

Over the weekend, like many Americans, I did my taxes. I’m required to file a couple of different Schedule C’s for various side-businesses I have, and when it comes time to hunt for deductions, it sure is nice to be a programmer.

I had initially thought that I would be able to download the entire year’s bank transactions into a CSV file, but alas, my bank (and many others, I’m finding) only provide 45 days of history. They do, however, allow you to download PDF files of all of your statements, and so there I was staring at thousands of transactions in PDFs, dreading retyping them into Excel.

Enter my skills as a Rubyist. I sought out the PDF::Reader library, which allows you to hook its parsing engine to a custom callback and do what you want with it. This definitely parsed the PDF fine, but I had no context; no idea where I was in my statement, because there’s no callback for a “new line” character – it’s just a stream of words. I found that if I used Adobe Acrobat to save the files as text-accessible, then I started to have statements I was able to work with.

Now that I had ‘lines’, I was able to use the power of regular expressions to get the data I needed. The lines I was interested in started with a date and an amount, and the rest was just description for my transaction.

Here’s the warts-and-all code I used to compile the year’s worth of spreadsheet data. It’s truly “quick-and-dirty”, but it saved me tons of time. The next step, of course, would be to implement regular expressions against the ‘memo’ field of these transactions, and pre-suppose categories and deductions based on these patterns. But then again, maybe it’s time to just use Quicken and stop waiting until the last minute.

Technology

Reuse Code And Write Reusable Code

reuse-code.jpgBefore I set out to write a significant amount of code, I search high and low to make sure someone else hasn’t already written it.
There are a few ways to do this:
1. Google Code Search
2. Look in your other projects for similar code.
3. Ask around (co-workers, twitter, IRC etc..).
One main reason for code reuse is that it will usually have less bugs than writing it from scratch. It is also evident that reusing code will save time. For example, why write a user authentication system when you can just download one and install it as a plugin. A few hours of research can save hundreds of hours programming. Another advantage to using pre-existing code is that it is usually more abstract and can fit a wider variety of applications. As a bonus, it usually has more features.
When you do have to write code because the problem you are solving requires more customization than anything out of the box, it is best to make sure it is reusable. For example, avoid naming your variables too specific, such as the_yellow_square_at_the_left_of_the_page, instead, create a function similar to shape('yellow', 'square', 'left'). This will allow you to reuse it for many situations. If you wanted a purple triangle on the right you would just write shape('purple', 'triangle', 'right'). It’s much easier to refactor and reuse on future projects.

Technology

Kick your footer into gear with a dynamic copyright

Year after year we end up changing copyright footers. Here are some snippets that will automatically update the year in your copyright text.

Django:
{% now "Y" %}
Ruby on Rails:
<%= Time.now.year %>
PHP:
<?php echo date('Y'); ?>
Smarty:
{$smarty.now|date_format:"%Y"}
JavaScript:
<script type="text/javascript">
   
 document.write(new Date().getFullYear()); 
</script>
Technology