Here are last month’s articles:
- January 01, 2014: Happy New Year!!!
- January 02, 2014: Logitech Harmony 1100 Review
- January 03, 2014: Real-Time Vehicle Diagnostics with Google Glass and OBD-II
- January 04, 2014: Permanent Red Dot Sight for FPS Games
- January 07, 2014: Power Hour
- January 08, 2014: Block IP Address Ranges and Subnets with iptables
- January 09, 2014: Distributed Computing with Python and RPC
Recently I was working on a project for the Raspberry Pi that grew a little too big for a single Pi to handle. Instead of moving the app to a system that contains more resources, I thought I would divide up the work load and have individual tasks ran on multiple Raspberry Pi’s instead of one. Since I already have a RPi cluster, I thought this would be a great opportunity to put it to work. Even though there are plenty of different ways to do distributed computing, I chose to go the RPC route. Since I had a really good grasp of what needed to be done and what could be offloaded to other Pi’s for processing, I chose not to use any of the available 3rd party frameworks that are out there on the web. Instead, I chose to roll my own module using the XML RPC libraries that come packaged with Python. Since my project doesn’t require any extra dependencies, it makes it easier to get up & running on the different Pi’s in my cluster. Because I went thru the (easy) work of writing the RPC app, I thought I would share a simpler version of it with all of you in case you find yourself needing to do something similar.
As an owner of several web servers, it seems like everyday is an ongoing battle to protect those servers from hackers. From a quick look of my log files, it appears that the majority of attempted breakins are coming from China. For example, today’s log files were showing attempted breakins from the IP address 126.96.36.199. Yesterday’s logs showed attempts for IP address 188.8.131.52. Digging a little deeper in my logs I have seen attacks from similar IP addresses on the same network. So, instead of blocking individual IP addresses one at a time, I have decided to begin (continue) blocking entire IP ranges. Now, most websites will tell you to use the “.htaccess” file in your web server to prevent attacks. But, this only blocks connections at the web server level. Instead, I prefer blocking connections at the firewall level using iptables (and other undisclosed techniques). So, today I want to share with you some of the commands I use for blocking entire IP address ranges using iptables.
Earlier today a friend and I were sharing some of our best practices for coding and overall work ethics. During that conversation, he asked what is my secret for writing massive amounts of code in a short amount of time. For those of you that know me, you already know that I do in fact churn out a lot of code in a very short amount of time. The answer to that question is simple, “planning”. Yep, before I write a single line of code, I will walk thru the entire application in my head and make as many notes as I can on paper. For larger projects, I will even draw out the overall architecture of the project before jumping into the code. Even though the architecture can and most likely will change throughout the project lifecycle, having an idea ahead of time of all that will be involved makes the development a lot easier and faster.
After I have written out (or at least planned in my head) everything that will be required, I begin what I call a “power hour”. Since I already have a good idea of everything I need to do, I will spend the next solid hour doing nothing but writing code. I make sure to remove any and all distractions so that I can get at least one full hour of coding complete. Since I’m a fairly fast typist, I can usually complete smaller projects within this one hour. When working on projects that cannot be completed within a single hour, I still make sure to stop when the hour is up even if it’s only to revisit my architecture drawings and notes or to grab a sandwich or stretch my legs. Otherwise I will begin to get fatigued and can quickly lose interest in the project. I know that I code for exactly one hour because I will set a timer on my cellphone before the power hour begins.
I also like to do my actual coding late at night after everyone else has gone to bed. During the day, I get phone calls and emails continuously which interrupt my power hour of coding. Even the slightest sounds of things like cars passing by, dogs barking, or planes flying over head can break my concentration. So, by waiting until at least 11:00pm or even midnight (and sometimes even later), I always get in at least one full hour of coding done. If my power hour is up and I have to take a break but there is still more work to be done, I will typically wait until the next wall-clock-hour (or half hour) and restart my timer for another power hour and will repeat the process until the project is finished.
For planning my projects, I have a notebook on my desk that I will use to make any necessary notes which provides me with something to revisit if I get stuck. By spelling it out on paper, I found that I can usually think thru things a lot better than just planning it out in my head. Depending on how many projects I have going on at a time, I will have several notebooks, one for each project, on my desk. Separate notebooks are great to have for larger projects and for when you are working on multiple projects at a time. However, I would always recommend working on one project at a time if possible. Since I have several responsibilities at my day job and have several personal projects going on, it’s difficult for me to stay focused on one single project at any given time. Instead, I find it’s better for me to juggle multiple projects at the same time which helps me from getting burned out on any one project. I also have a whiteboard on my office wall that I will use for any architectures or mind maps that need to be drawn out for planning. Having visuals like this within eyesight really helps keep the creative juices flowing and thought process engaged, especially after taking a break from a project and revisiting it later.
So, as you can see, just like with anything else you do in life, you can always do it faster and better if you just take a little time up front to do some planning. Once you know what it is you have to do, getting it done is the easy part.