Posts tagged 'Programming'

Prev Previous Entries
September 26, 2010, 6:18 pm

Generic Makefile

Earlier today I decided to start working on yet another side project, this time written in C++. Before I get into the meat of this post I thought I’d mention that I reinstalled my dev environment for C++, I use the MinGW port of the GCC for my compilier and would like to mention that the work they have done on their package manager mingw-get is really awesome it allowed me to get MinGW and MSYS up and running in no time with very little effort.

Once my dev environment was all setup again I went to set up my project only to find that somewhere along the way I had lost my generic all purpose Makefile, so after taking a little bit of time out to re-teach myself how to write a Makefile – from the best source that I know of – I recreated a makefile very similar to my original generic makefile. In an effort to not lose it again I thought I would share it with the world:

APPNAME = test
SRCDIR = src
OBJDIR = obj
BINDIR = bin

SRC = $(shell find $(SRCDIR) | grep .cc)
OBJ = $(patsubst $(SRCDIR)/%.cc, $(OBJDIR)/%.o, $(SRC))

.PHONEY: all clean init

all: clean $(APPNAME)

clean:
	rm -rfd $(OBJDIR) $(BINDIR)

init:
	mkdir $(OBJDIR) $(BINDIR)
	$(foreach DIR, $(patsubst $(SRCDIR)/%, $(OBJDIR)/%, $(shell find $(SRCDIR)/* -type d)), mkdir $(DIR))

$(APPNAME): init $(OBJ)
	$(CXX) -o $(BINDIR)/$(APPNAME).exe $(OBJ)

$(OBJDIR)/%.o: $(SRCDIR)/%.cc
	$(CXX) -c $< -o $@

To use this makefile you will need to run it from a POSIX like environment so it should work fine on Mac OSX and Linux but on Windows you will need something like MSYS or Cygwin, personally I use MSYS but that’s just a preference thing.

This makefile is intended to be a drop in start point for any C++ project, though it isn’t had to modify it for other languages. The following is the project structure that the makefile is designed to work with:

  • Project Root/
    • makefile
    • src/
      • source_file1.cc
      • source_file2.cc
      • subfolder1/
        • source_file3.cc
      • subfolder2/
        • source_file4.cc
        • source_file5.cc

It will pickup all of the source files in the subdirectories eliminating the need for a recursive makefile. I have never tested this makefile on a large project so I don’t know how well it would hold up, but I’m guessing if your project is getting big you would most likely be better off using something like Autotools or CMake.

Tags: , , , , , ,
Category: Programming  |  Comment

September 25, 2010, 5:54 pm

Fun with strings and hashes in ColdFusion

At work we do a bit of web development using ColdFusion and earlier this week I got stumped by a problem which I thought I would share.  We are currently working on a RESTful API which requires an API signature similar to how flickr does. When it came to writing my unit tests I created a signature grabbing a private key out of the database to test against. I ran the test and BAM! it failed, now this was half expected it was the first time I’d run the test. So it turned out that the code was syntactically fine, then I thought  maybe I had made a mistake in the process of creating a signature.

With that ins mind the next step I took was comparing the raw pre-hashed version of both signatures, to my surprise I found that the test passed.  This was beginning to not make sense, it wasn’t until I altered the test to fail that I saw what the issue was: when I retrieved the key from the database all of the characters were uppercase however when coldfusion retrieved the key all of the characters were lower case. After updating the test to use a lower case version of the key it passed successfully.

So it turns out that ColdFusion is not case sensitive when it does string comparisons, but the hash function does care what case the characters are, as you can lead to a frustrating situation.  Now I’m not expecting you to take my word for it so I have quickly coded up some example code showing the issue.

<cfset original = "secret-key" />
<cfset upperCase = "SECRET-KEY" />
<cfset match = "secret-key" />
<cfset random = "5q2up0awet530" />

<cfset originalHash = Hash(original) />
<cfset upperCaseHash = Hash(upperCase) />
<cfset matchHash = Hash(match) />
<cfset randomHash = Hash(random) />

<cfoutput>
	<h1>String Matching</h1>
	<table border="1" style="width: 30%">
		<tr><th></th><th>Upper case</th><th>Match</th><th>Random</th></tr>
		<tr>
			<th style="text-align: left">Original</th>
			<td style="text-align: center">#original eq upperCase#</td>
			<td style="text-align: center">#original eq match#</td>
			<td style="text-align: center">#original eq random#</td>
		</tr>
	</table>

	<h1>Hash Matching</h1>
	<table border="1" style="width: 30%">
		<tr><th></th><th>Upper case</th><th>Match</th><th>Random</th></tr>
		<tr>
			<th style="text-align: left">Original</th>
			<td style="text-align: center">#originalHash eq upperCaseHash#</td>
			<td style="text-align: center">#originalHash eq matchHash#</td>
			<td style="text-align: center">#originalHash eq randomHash#</td>
		</tr>
	</table>
</cfoutput>

When you run the code this is the output you should get.

As I found the hard way when ColdFusion says two strings are the same it may not necessarily be true.

Tags: , ,
Category: Programming  |  Comment

September 10, 2010, 11:39 pm

Weekend of Code

I found that for me this weekend is going to be a bit of a quiet affair so rather than sitting around all day doing not very much I decided that I’d try to be productive.  It’s been a while since I sat down and done any meaningful amount of coding for myself so I thought that is where I’d start, my next question was what do I want to write? I then remembered that I’m not overly fond of most of the music players that I’ve tried on Windows, the closest so far to something I find acceptable is iTunes.  With that I had it: my goal for this weekend would be to write (or at least make a dent in writing) a music player that I would like.

Alright, that’s all fine and dandy to say but what does that actually mean? Brainstorming it I came up with seven key features that I want in my media player:

  • Only plays music, doesn’t try to do anything else.
  • Watch folders.
  • Filter on album, artist, title.
  • Filter a filter.
  • Ability to queue songs while on shuffle.
  • Playlists.
  • A similar interface to iTunes.

While watching Justice League: The New Frontier tonight I made a bit of start by making some rough UI mock-ups in Balsamiq.

To implement this I’m planning on using C# and WPF, I haven’t had a good chance to play around with WPF or some of the new Windows 7 features that are available so I figured this would be as good a time as any.  Finally my other goal with this project is an attempt to get me back into blogging, to that end I will hopefully be making a post at the end of each day summarizing what I’ve done – possibly with some screenshots.  Until then I should be posting some updates to my twitter feed.

Tags: , , , , , , ,
Category: Me, Programming, Projects  |  2 Comments

March 20, 2010, 3:35 pm

theCloud Blog

So it would seem that I might be starting to go a little theme happy. Not one week after releasing the new theme to my own blog I’ve tried my hand at another theme. At work we are gearing up for the release of theCloud our hosted services platform and I had the pleasure of designing the blog theme that we are using for theCloud blog which was launched yesterday there over the next little while you will be able to find posts related to hosted services, cloud computing and other related topics. I’m hopefully going to try and squeeze in some posts about customising the software we have available through coding.

Tags: , , , , , ,
Category: Programming, Projects, Work  |  Comment

March 14, 2010, 12:58 am

New Theme

If you have actually browsed to the site to read this post you will have noticed that Mike’s Musings has had a fresh coat of paint, also if you’ve read my previous entry you will have noticed that it is not the theme that I mocked up. In the end I thought that the first theme was not a good fit for the site, though one day I might turn it into a real theme.

The motivation for changing the theme in the end came down to a mixture of the following factors:

  • Fluid Blue the old theme had been in service on this site for getting close to four years now and it was time for a change.
  • I wanted to try my hand at a bit of design, I knew it was not going to be any hugely fantastic but I’m happy with the result.
  • Finally I wanted to integrate some of the various social networking sites that I belong to into the site, I found that fluid blue didn’t really lend itself to how I wanted it all displayed.

As I noted above I wanted to integrate some of my social site activity into the site to that end I have also integrated my twitter stream into the left sidebar.  As with any new piece of code I will not be surprised if there are bugs, I have tested it in IE 8, Firefox and Chrome and it appears to work fine but these are not the only browsers in the world.  If you do happen to find anything wrong with the site don’t hesitate to report a bug over at the mlowen.com bug tracker.

Tags: , , , , , , ,
Category: Programming, Projects, The site  |  1 Comment

November 8, 2009, 11:54 pm

REST API Test Utility

One of the things I enjoy most about being a programmer is the fact that when you can’t find a tool to do what you want you can write it yourself. Generally I’ve found that these applications tend to be quite simple and stick to the unix philosophy of ‘do one thing and do it well’ which as a software developer I think is a good philosophy to live by. The most recent occurrence of this happening to me was at work not to long ago where we are currently writing a REST API I needed an application to make a HTTP call to a URL. After about 5 minutes of looking around the web I couldn’t find anything, at that point I had the choice of either continuing to search for an appropriate tool or I could write my own. As you might have guessed I wrote my own, it took about 10 minutes to implement the basics of what was needed.

Over the next couple of weeks the tool continued to evolve to better fit the specifics of the project we we’re working on, but in the back of my mind I kept going back to how other people must have this problem as well. Eventually I decided to re-implement the core of my tool. Having finished the re-implementation a couple of weeks ago I’m finally getting around to releasing it to the public under the GPL, below are the links to download the 0.1 release.

  • [download id="1"]
  • [download id="2"]

For those of you who would like to grab the latest source and stay current with any updates (which may be buggy broken code) you can check out the subversion repository which is available at the following URL:

In other news I have signed on to be a contributor to lounge media a blog about digital media in the home, hopefully I should have a post up there soon – once I figure out a good subject to start on.

Tags: , , , , , ,
Category: Programming, Projects, Rest Application Test Utility  |  Comment

April 19, 2009, 11:58 pm

gIDE Build System

As I mentioned earlier tonight here is my coding related post, since the 14th I haven’t really worked on gIDE until today.  I finally got the build system all finished and integrated into the rest of the application.  You can now happily define and run the commands needed to build your project. The following images show gIDE building a test project and the other shows the dialog for defining the build commands.  I am currently not very happy with the properties dialog but am yet to think of anything better so what I have will have to do for now.

I’m happy to have finally gotten this finished as it was the big feature I wanted done before I would eat my own dog food and use gIDE to develop gIDE.  I also took this oppurtunity to port gIDE from vte to vtemm which made the task of the code to set the commands a lot easier than a previous attempt I had made with vte, this does mean however that there is now a dependency in gIDE that is to the best of my knowledge not included in any distrobution.  I do not see this as being much of a problem however because the primary audience for gIDE is developer most of whom would know how to build a library from source.

As always the latest changes to gIDE can be found in trunk of the svn repo at http://mlowen.com/svn/gIDE/trunk.

Tags: , , , , ,
Category: gIDE, Projects  |  2 Comments

March 14, 2009, 12:23 am

Weekend Coding

So lately I’ve been doing little to no work on gIDE, which while it is not unusual it is a little disappointing as I had hoped to have made at least one release by now.  With that in mind and the fact that I don’t have anything planned for this weekend I sat down and listed all of the features that I needed and wanted to have before I made an initial release.  The plan is to sit down this weekend and knock as many of these things out before the weekend is over and make a release, will I hold true to this? I do not know, my track record of promises similar to this (which you should be able to find in the archives of this blog) is not stellar.  Heres hoping I follow through on it this time. Now onto the important part of this post the lists:

Needs

  • Find/Replace
  • File Rename
  • File Move
  • Build System

Wants

  • Move from vte to vtemm
  • Document Split view

Of the things that is on these lists the one that I am not really sure about is the moving from vte to vtem, while vtemm would fit in better with the rest of the application it is currently not packaged with any of the major distros.  This leads to the problem which is more important the design of the application or the ability of people to run the software? I’m sure I will have some comments about this in the next couple of days.

All going well I should hopefully make a blog post after I finish each feature, or for a couple of less screenshot worthy features I might just save them until a screenshot worthy one is finished before making a posting.

Tags: , , ,
Category: gIDE, Programming, Projects  |  2 Comments

February 3, 2009, 5:03 pm

What happened to Cuttlefish?

Close to a month ago now I wrote about what I got up to on my holiday and I said I had started a new project Cuttlefish – a syntax highlighting text box for .Net. I also said that I would post about in more depth later, so far that hasn’t happened. This is mostly because I haven’t actually finished cuttlefish and I haven’t a lot of time to code lately. The other big reason is I recently picked up a copy of Framework Design Guidelines: Conventions, Idioms, and Patterns for Reusable .NET Libraries and found that my little project needs a quite a bit of refactoring to be compliant with these guidelines. I hope to get started on the compliance work tonight, once that refactoring is done it shouldn’t take to long to finish it off. With all that in mind it hopefully won’t be to long before I am able to show cuttlefish off.

Tags: , , , ,
Category: Programming, Projects  |  Comment

January 13, 2009, 2:23 pm

This is not the post I intended to write today

I’ve been back at work a couple of days and once again settling back into the daily grind.  I had originally decided to make a series of posts once I got back from holiday called ‘Holiday Hacking’ which would detail the coding that I got up to during my time off, as it happens there was just one small hitch in that plan – I didn’t do much coding in my time off.  It would seem that I choose to relax these holidays rather than try and chip away at my to do list for gIDE.  While I didn’t work on gIDE this holiday I did however start a new project: Cuttlefish.  I plan to go into this in more depth in a later post so for now just let me say that it is a syntax highlighting Textbox component for .Net written in C#.

I have been doing a little bit of work around the site as well, mostly involving integration with my facebook account (which I’m intending to give more attention to this year).  For those that haven’t noticed (or read this via rss) a link to my profile now appears in the in the sidebar and all of my posts should hopefully be appearing on said profile. This has the added side effect of some of my friends who hadn’t noticed it before get to see how truly geeky I am.  For those who are interested the two plugins I am using for the integration are Wordbook and Facelook.

Tags: , , , , , ,
Category: gIDE, Me, Programming, Projects, The site  |  Comment

Prev Previous Entries