Posted: 27th October 2013 by manchicken in Gist of the Day, Hacking, Perl
Tags: gist, github, hacking, mockmodule, perl, testing
I like repeatable tests. The #1 benefit of repeatable tests is that they’re repeatable. This also means they’re less vulnerable to data changes (e.g. this test depends on this product record remaining unchanged) and don’t pollute your environment. There are two ways that I think you can make your tests repeatable, and I think both of them are equally valid, and each should be used in their appropriate time:
- Creating and tearing down fixtures
- Using some sort of mocking framework to force a repeatable result from an up-stream dependency that is not what you’re trying to test
Read the rest of this entry »
Posted: 30th September 2013 by manchicken in General
Tags: absent, new job
Hey all, I just wanted to let you know that I didn’t die… I am only going through a job change and a move, so I am currently bogged down with a number of things.
I expect to be back up and running again by next weekend at the latest. I suspect very few people care, but in the event that you do, now you know.
I’ll share all of the details when I have them
Posted: 25th September 2013 by manchicken in Gist of the Day, Hacking, Perl
Tags: gist, github, hacking, perl, testing
First, I suppose I should apologize for two days of silence. I am currently going through a major life transition, so things could get a little spotty for a while. I haven’t forgotten about you. I actually have had a couple of days where my experiment for the Gist of the Day failed, and I couldn’t get something working in time to put it up.
Today, however, I do have something for you!
Today we are going to cover two topics very briefly (as usual): 1) how do you factor files you wrote into your tests, and 2) how do you write your code with testing in mind (which you should). Read the rest of this entry »
Posted: 22nd September 2013 by manchicken in Gist of the Day, Hacking, Perl
Tags: abstraction, gist, github, hacking, perl
In programming you will commonly see abstraction layers. Say, for instance, you wanted to have a program to take some arbitrary data format and load it into your data. We’ll call it product feeds (just because some people like relevant examples). So, you want to pull in product data from various different web sites and vendors to list some products on your site. Now if you have ever done this task before then you’re already thinking “jeez, what a pain in the ass it is to get everybody to use the same format!” If you’ve done this task before then you’ve probably already dabbled in this type of abstraction. In Perl – my go-to language (since I arbitrarily prefer it) – this usually results in dynamically loading a “driver” class based on the data format which is likely vendor-specific. This makes it easy/easier for you to allow each data source to have its own format while using them all in the same way.
If you were to pick a Design Pattern for this, you would do well to choose a Factory pattern. In Perl, since you have so much dynamic leeway, you don’t need to go with a pure Factory pattern here, but what you end up with I think is most certainly in keeping with a factory pattern.
For this Gist, I will demonstrate three common ways to get from knowing which class you need to getting that class:
Read the rest of this entry »
Posted: 21st September 2013 by manchicken in Gist of the Day, Hacking, Perl
Tags: gist, github, hacking, mojolicious, perl
Mojolicious is a fun module/framework/thing for me. How do I love Mojolicious? Let me count the ways (sorry Shakespeare):
- Mojo has ridiculously few dependencies, especially when compared to other web frameworks
- Mojo brings web servers (morbo and hypnotoad) with it
- Mojo does MVC, or doesn’t do MVC, whatever I want to do
- Mojo has templates, and they’re outstanding
- Mojo does routes very simply, which is badass
- I can write an entire web application in only one file (though it could get big and may not be advisable) using Mojolicious::Lite
- Mojo has helpers which are actually helpful
- Mojo is crazy fast, so fast that if there is a performance problem I’m pretty sure it’s me
- The more I use Mojo, the more I find cool stuff that it can do Read the rest of this entry »
Posted: 20th September 2013 by manchicken in Gist of the Day, Hacking, Perl
Tags: gist, github, hacking, perl, sl4a
I am very sorry that I missed posting this yesterday, I kinda got crazy sleepy and went to bed shortly after getting home from work.
AS PROMISED, however, this next Gist is the SL4A Android component. This program gives you two buttons: “Process Queue” and “Exit the program!” With these two buttons you can either process a message from the queue (see previous post) or exit the program. Processing the queue involves sending an SMS message and then repeating the message with TTS. Read the rest of this entry »
Posted: 18th September 2013 by manchicken in Free Software, General, Gist of the Day, Hacking, Perl
Tags: gist, github, hacking, mojolicious, mongodb, perl, sl4a
I got a little bored with what I had been posting (I suspect you did, too), so I’m doing something neat. I’m going to write a full (though limited) program for you. Here are the user stories (if you don’t know what user stories are, see here before continuing):
- As a web user I can enter a phone number and a SMS message into a queue so that it can be sent by a mobile handset.
- As a mobile handset user, I can push a button to dequeue a message and send it via SMS so that I might risk my device’s stability and my own financial solvency by opening up the internet to sending messages through my phone. Read the rest of this entry »
Posted: 17th September 2013 by manchicken in Gist of the Day, Hacking, Perl
Tags: android, gist, github, hacking, perl, sl4a
So I’m on very little sleep after a long three days of travel which is not yet done. Nonetheless, the show must go on!
Today I have for you a demo program I wrote for CMI.pm a while back (last July I believe) on how to use Perl with SL4A (Scripting Languages 4 Android). This sample code loads a screen which does one of two things: says “something nice” or exits the program. This program demonstrates how to make an event loop for SL4A, how to load an external XML UI resource for Android, and also uses some very basic functionality of SL4A (TTS speak, in particular).
As I am very tired – three hours of very interrupted sleep – I will not be writing any more than this, but I will, of course show you… Read the rest of this entry »
Posted: 16th September 2013 by manchicken in Gist of the Day, Hacking, Perl
Tags: gist, github, hacking, perl
I’m pretty sure there’s a more efficient way of doing this, but here’s what I’ve quickly typed up in 10 minutes sitting in my hotel. It just takes in a number, and then the size (in bits) of the number. It returns the number of bits it counts. I believe there is a very common algorithm called the Hamming algorithm, but as I don’t know that algorithm I’ve kinda worked this up instead.
This post is super short as I have a very busy day ahead of me. I’m going to go ahead and just post the code and call it a day. Sorry for the brief post. Read the rest of this entry »
Posted: 15th September 2013 by manchicken in Free Software, Gist of the Day, Hacking, Perl
Tags: c, gist, github, hacking, perl
Hi, did ya miss me? I’m blogging from O’Hare today, it’s going to be a busy week for me with lots of air travel. That won’t stop me from polluting the Internet with yet another blog post though, don’t you worry!
One of the things that we sometimes encounter is a binary file created by some C program writing a
struct straight to disk. If we want to get any of that data we will need to parse this file, and read that struct. It’s a little tricky, and you kinda have to know a little bit about either the system on which he program was run, or the intentional decisions made by the program about how the file was written. The most important thing you need to know is the endianness of the binary data. Read the rest of this entry »