Friday, April 5, 2013

F$#% SQL Compact

Not a very professional post title, I know.
I would write a poem about it,
but I hate it too much for that.

Really though, SQL Compact provided the majority of the issues on a project I worked on recently. The good news is that I would say I am more qualified to use it now than I was before and know exactly how long much longer to estimate a project out to be when it is going to be involved in some way. The answer is: 42.*

For anyone who is going to use it: It's more limited than you think. Just expect to do all your normal SQL scripting in the business logic for your project. Hell, the best way I found to do something quickly was to use Entity Framework and use the Entity Data Model Wizard to create an .edmx file. Then, include this in your project and write all your batch scripting directly as LINQ statements.

I need to see if someone has create an interpreter that will run a Transact-SQL script on a SQL CE database. If not, it should be created by me or someone else. If you're that someone else, I love you.

* ...hours of annoyance. This is quite possibly the amount of time you will spend outside of the work environment cursing the day it was conceived. 

Friday, March 29, 2013

RE: Area of Focus: C# and HTML5 / Belated Job News

Well, this is the first post I've made in ages. Around the time I started this this blog I had just started my first professional coding job which left less than than I had hoped for updating it. Now that I've been settled in for a while I'm going to do my best to update this again more frequently. I need a place to pursue personal programming tasks and projects anyway.

That being said, I can confidently say now that my 'Areas of Focus' for C# and HTML 5 have been fulfilled. I use C# on a daily basis at work and do modern web design nearly as often. I'm actually creating a clone of an old Windows 3.x game that I used to love as we speak. I'll make sure to provide a link to it as soon as I make a bit more progress. My current goal is for that to be by the end of this weekend however we will see how well that works out this being Easter weekend and all.

I have made some progress this weekend though having already ripped, by hand, all of the graphics from the original game. I converted them to transparent PNGs which should work well I just have to remember to put them in a single sprite sheet if possible so that the number of requests is reduced. This should allow for a much quicker load time. Realistically though there aren't very many sprites and additionally they came from an era where the entire screen resolution consisted of 640x480 pixels or even less so each PNG is like 500 bytes. So, the question is: is it better to have a single request for of the composite sprite sheet or a bunch of requests for the smaller individual sprites? I guess one benefit of the latter is that your browser can do multiple requests at a time allowing for parallel downloading.

Anyway, I'll update this as progress occurs...

Tuesday, May 29, 2012

Area of Focus: C# and HTML5

It seems as if the best move for me would be to focus on a more modern language, such as C#, instead of the fundamental language of C at a low level.

I'm feeling confident about my level of pure C knowledge at this point anyway. There probably aren't too many jobs these days that are going to require me to dynamically allocate memory for strings on a ('sizeof' * length) level.

I've used C# before, when using XNA, so luckily I have some experience with it. Hopefully it turns out to be everything that a modern language should be. It will be nice to have garbage collection for once as a backup. Thank God for that...

Also, HTML5 seems to be even better than I thought it would so I am going to try to spend an equal amount of time on it as well.

Visual Studio Express, why u take so long to install?? =(

Coming Next: C# practices, standards, and classes. Oh My!

Wednesday, May 23, 2012

Lanlost.com has risen from the dead!

I just wanted to take this moment to thank my friend Ryan N. for deciding to magically ressurect my old domain for me. I thought it would be lost forever as the last time I let it lapse someone else registered it for 10 years and did nothing with it.

Since he is also awesome, he has provided me with hosting on his server which means I will now be able to accomplish a lot of the HTML5 and other code experiments I've wanted to do.

I never asked him. He's just awesome like that and took the initiative and made this happen for me.

[todo: Create and Insert Good Guy SA picture].

Update:

(Not an actual picture of Ryan N.)

Areas of Focus: Mobile Development or HTML5?

Title says it all. Which to focus on?

On one hand, mobile development is something I have been interested in for years. This goes back all the way to the pre-smartphone era for me. Something about seeing my program running on a hand held device was something that attracted me and still does. The situation has MUCH improved since then luckily.

With HTML5 the possibilities are endless. With mobile phones and tablets becoming more and more powerful this might eventually be the end all solution to cross platform problems. Are there any browsers that allow for HTML5 yet? Pixel perfect accuracy and drawing on a website? Check. Javascript instead of Java? Check.

While I ponder this maybe I'll take a stab a both in a simple way. If I'm going the mobile development route then it looks like it's time for me to get back into Linux full time. I always loved the Linux environment more even though it primarily consists of Eclipse and ADB.

I realize no one reads this yet but this would be a great time for someone to weigh in on both options. They are both going somewhere so either one isn't really a bad choice. .. Or is it? Please tell me something I don't know!






Well, at least it looks like I can integrate HTML5 with blogger in sort of a hackish way.

String Manipulation in C - 01

Here is another one...

Problem:
Escape all % characters in a string; % is the escape character.
Example: “I’d like 2% milk” becomes “I’d like 2%% milk”.

I decided to make it work for any problematic character and to be replaced with any escape character that you should choose. Maybe I will create an amendment later that allows you pass an array of characters that each should be escaped.

I took on this problem because they specifically talked about how easy it would be in C++ or Java where string manipulation is MUCH more advanced and defined. In C you can't simply insert the escaped character because it isn't a string but a character array of a fixed size. This means that you are going to have to allocate the space for it.

Here is what I came up with:
#include <stdio.h>
#include <string.h>

// for malloc, in memory. *
#include <stdlib.h>

char *escapeString (char *origString, char badChar, char escapeChar)
{
    int newStringLoc = 0;
    int toEscape = 0; 

    // Determine number of characters we will need to allocate.
    for (int curChar = 0; origString[curChar] != '\0'; curChar++)
        if (origString[curChar] == badChar)
            toEscape++;
   
    char *newString = malloc (strlen(origString) + toEscape);

    // This really shouldn't happen in 2012...
    if (!newString)
        return NULL;
 
    for (int curChar = 0; origString[curChar] != '\0'; curChar++)
    {
        if (origString[curChar] != badChar)
            newString[newStringLoc] = origString[curChar];
        else
        {
            newString[newStringLoc] =  escapeChar;
            newString[++newStringLoc] = origString[curChar];
        }
 
        newStringLoc++; 
   }

   return newString;
}

int main(void)
{
    char *origString = "This is a problematic string! 2%, 3%, 4%%!";
    char *newString = escapeString (origString, '%', '\\');

    // Check to see if it worked..
    printf ("origString: %s\n newString: %s\n", origString, newString);
 
    free (newString);
    return 0;
}

To make it much easier to see what is going on here, I have replaced the original escape character ('%') with ('\'). The output looks like this:


c:\CProgs\Str1-1>lcc strings1.c
c:\CProgs\Str1-1>lcclnk strings1.obj
c:\CProgs\Str1-1>strings1
origString: This is a problematic string! 2%, 3%, 4%%!
 newString: This is a problematic string! 2\%, 3\%, 4\%\%!


for (int curChar = 0; origString[curChar] != '\0'; toEscape += (origString[curChar++] == badChar));

Tuesday, May 22, 2012

Interesting Article and My Solution

So, I found an article on Coding Horror about how most programmers can actually not write a simple program. I figured their example question that people have trouble writing would be a good test to see how efficient I could make it.

The problem is as follows:

Write a program that prints the numbers from 1 to 100. But for multiples of three print "Fizz" instead of the number and for the multiples of five print "Buzz". For numbers which are multiples of both three and five print "FizzBuzz".

I started at (4:33:35 AM) and ended at (4:36:45 AM) for a total of around 3 minutes and 10 seconds.

Here is what I came up with:

#include <stdio.h>

int main()
{
     /* Write a program that prints the numbers from 1 to 100. 
        But for multiples of three print "Fizz" instead of the number
        and for the multiples of five print "Buzz". For numbers which are
        multiples of both three and five print "FizzBuzz". */

     for (int num = 1; num <= 100; num++)
     {
          if (num % 3 == 0)
             printf ("Fizz");
          if (num % 5 == 0)
             printf ("Buzz");
  
          if ((num % 3 != 0) && (num % 5 != 0))
             printf ("%d", num);
  
          printf ("\n");
     }

     return 0;
}

The short article is a fantastic read and only takes a second. Both solutions that appear early in the comments fail for various reasons. It is not necessary to have a statement to print both Fizz and Buzz when you can simply leave out the newline until the end and solve both in one go.

Even though it's simple problem and may seem like a step back in complexity from the previous post I'm happy with my solution. Moving to something a bit more complex tomorrow. For now, I need sleep.