time_t and printf


Written on 12/6/2009 – 1:14 pm

The bane of my existence is work where I use c++ primarily with MFC.

Now today I have come up to one or the most strange occurrence while debugging the database code in our product. I was formatting a string with sprintf and all of my time values were being formatted as “(null)“.

I know we should really be using parameterized queries but this is legacy code created by PC software guys, and I really don’t know if ODBC supports it in a database agnostic way.

Now we have been using Visual Studio 2005 for years but this code has not been working for years, the problem showed up around the database purging code.

When looking in the debugger at the formed SQL I noticed “(null)” showing up instead the numbers I was expecting.

It turns out we were using time_t as the type being fed into sprintf which under this version of Visual C++ is actually a 64-bit integer, or unsinged long long.

So the solution to this rather strange error in formatting is also quite strange, as in how do you format a unsinged long long into sprintf. Well it’s rather simple just add another formatter charter so if you have a signed long long use %lld or if you have a unsinged long long use %llu.

I hope you don’t get tripped up like I did. And if you were wondering why there was “(null)” in the string it’s because the next token was a string, %s, and intel architeture is little endian making the upper 4 bytes all zero, ie null.

  • Share/Save/Bookmark

Tags: ,

Floder Properties in Windows Vista


Written on 20/1/2009 – 1:18 pm

When using the explorer in Windows Vista I was having trouble finding the folder properties, for showing hidden files among other things. Like everything else in Vista it has moved and changed name. No longer can you find it under “Tools” -> “Folder Options…”

But now under “Organize” -> “Folder and Search Options”

Location of Folder Options in Windows Vista

Location of Folder Options in Windows Vista

It really shook me and the help only had a link to open the options and didn’t tell you how to actually get to the options directly.

  • Share/Save/Bookmark

Tags: ,

My very own home


Written on 16/1/2009 – 2:04 pm

Well it finally happened. No we moved into our own home like 6 months ago :p get with the program.

Today I purchased my first domain :)

So as of today welcome to jprogrammer.net a nice short sucsinct way to acess the random ramblings that don’t happen as often as they should.

  • Share/Save/Bookmark

Tags: ,

Death in a Digital Age


Written on 12/12/2008 – 12:26 pm

I have recently experienced a death in the family, which has started me wondering about how our digital persona’s will live on.

I personally spend alot of time on the internet, a couple of hours a day at least. Spending my time reading email and rss, writing a blog entry (ocasionally :P ), particiapating in online discussion (Stack Overflow at the moment), buying stuff, reasearching stuff. There is just soo many things that I rely on the internet for.

But at what point do these things dissapear, with the cheapness of media maybe what we create will exisit on forever. This webpage may not as hosts come and go like my first provider, but you can still see entries from there, not very pretty ones, with the internet archive.

It just goes to show that there really isn’t anyone who produces on the internet will ever trully die and therefore no one should be lost to history no matter how small your percived contribution was.

Just makes you think doesn’t it.

  • Share/Save/Bookmark

Tags: ,

The house is finished!


Written on 14/8/2008 – 2:04 pm

Have you ever noticed that as time goes buy your passion for different things start to wain? I do it seems some things that you thought was important is not so important any more. Like blogging for instance :P

It has been quite a while now mainly because work has been heating up for me. I went on a week long trip to China visiting different customers.

And most importantly our house was finished and we moved in about 4 weeks ago Yey!

Completed
And we are loving it, the cat hasn’t adjusted too bad either. But the money is now flowing out finishing off the house. Oh well such is the life of a mortgagee.
  • Share/Save/Bookmark

Tags: , ,

We have a Slab!


Written on 24/1/2008 – 9:54 am

Well the Christmas hiatus for the building industry is finished and we now have a slab. It’s such an exciting thing to finally see some progress in the house that we have invested so much time and effort into actually taking shape.

Slab

With all this excitement we are now heading out there every evening so there will be loads of photos to follow. I may not post about each stage so to keep up subscribe to the Our House photo rss.

  • Share/Save/Bookmark

Tags:

House Update


Written on 2/11/2007 – 12:55 pm

Most people would know we bought land in April to build our first house on.

Our House

And since then we have been trying very hard to get approval to build the house we want on it. There was a clause in our title, Memorandum of Common Provisions to be exact. That no structure within the first metre of the boundary will be greater than 3.6 metres tall. And the house plan we decided to build once sited on the block made the height of the garage at 1 metre from the boundary 3.79 meters.

So both I and the build phoned the council to see what could be done, simple they said all you will need is a Planning permit and it should only take a couple of weeks for such a small item.

Thats when the fun really began it took the council 3 months not a couple of weeks to approve the permit and when we finally got it back we were told that the planning permit was not all that needed to be done to allow us to build our house :(

A planning permit like this gives you permission to get a licensed surveyor to draw up a plan that will then be approved by council which will then need to be submitted along with the title kept by the bank to the Titles Office.

So here’s the list of things that cost money along the way:

  • Planning Permit
  • Letters to neighbours
  • Plan
  • Approval of Plan with Council
  • Release of Title from bank
  • Submission to Titles office

So if anyone ever tells you that a Planing Permit is no big deal laugh in their face it is a big deal and it will take time effort and quite a bit of money.

But if you are going through something similar take a queue from me that I should have known earlier, you need to be a squeaky wheel. If the person says that something will be done on a certain date or in a “couple of days” then make sure you phone them then and find out if it has been done.

Other than that we are now very excited about the prospect of getting on with the building of our house :)

  • Share/Save/Bookmark

Tags: , ,

Vertical text align of radio buttons in java


Written on 19/9/2007 – 11:24 am

I have been doing some GUI java code in both swing and SWT recently and find text alignment a niggling annoyance of mine. Often you want to align components with the text line vertically of combo or check boxes.

Here is the code for determining the width in pixels for the two most popular GUI libraries in java. Both are cross platform/look-and-feel solutions.

Swing

JRadioButton radio = new JRadioButton();
int raddioButtonOffset =
    UIManager.getIcon("RadioButton.icon")
        .getIconWidth()
    + radio.getIconTextGap()
    + radio.getInsets().left;

SWT

// get the width of a space
GC gc = new GC(parent);
int spaceWidth = gc.getAdvanceWidth(' ');
gc.dispose();

// create radio widget to get widths
Button radioButton = new Button(parent, SWT.RADIO);
Point baseSize =
    radioButton.computeSize(SWT.DEFAULT, SWT.DEFAULT);
radioButton.setText(" ");
Point withSpaceSize =
    radioButton.computeSize(SWT.DEFAULT, SWT.DEFAULT);
radioButton.dispose();

int radioButtonOffset =
    withSpaceSize.x
    - ((withSpaceSize.x - baseSize.x) / 2)
    - spaceWidth;
  • Share/Save/Bookmark

Tags: ,

Down again?


Written on 20/7/2007 – 8:59 pm

This week the blog went down again with “500 Internal Server Error” again. This time however I believe that the problem has been resolved for good this time however.

Back when I started this blog in 2003 with Wordpress 1.0 there was no WYSIWYG editor so I wrote the first 18 months of posts in Textile before Wordpress 2.0 was released with the TinyMCE editor for writing posts. And after that I couldn’t be bothered re-formatting them so I left the Textile plugin turned on and as it turns out it created the problems so hopefully it’s all finished with now. Thanks again to the support staff of Profusehost.

  • Share/Save/Bookmark

Tags: , ,

Netbeans


Written on 12/7/2007 – 3:58 pm

I have become a bit obsessed with the java community lately more in a consuming fashion than a participatory fashion, reading Java Desktop and listening to the Java Posse and it just keeps coming up how much everyone loves Netbeans and that everyone should be using it for Java development.

Features such as Mattise look to be very good and a great reason to use the IDE. However as an Eclipse user there are just too many features that I miss to change IDE for now.

  1. Per project settings including templates and code style
  2. Macro for YEAR for code templates
  3. Incremental compiler.
    On a small project of only one file takes a good 3 seconds just to launch even if it is built. Like really do you need to build a jar always when executing projects? As good as running everything through ant sounds it is just too slow when compared to what you get for free with eclipse.
  4. Editor support.
    Supposibly the java editor is greatly improved for version 6, however in the test build I used M9 it is still slow, non intuitive and just painful give me eclipses Ctrl-1 quick fix any day.

Completion in the IDE space is good but for my everyday java development it is still impossible for me to switch.

  • Share/Save/Bookmark

Tags: , , ,

Page 1 of 1212345»10...Last »