I've been looking at this guy's blog and it struck me as extremely interesting. He shows several algorithms to generate mazes, while fairly useful and fun. I don't know how to implement this kind of logic so I am researching hard on the matter. Expect a post about it soon !
Here is the blog I'm talking about, go check it ! http://weblog.jamisbuck.org/2011/2/7/maze-generation-algorithm-recap
This is a blog to talk about programming. I am a student in IT currently working with the C# language.
Tuesday, February 15, 2011
Monday, February 7, 2011
Regex are AWESOME
So today in class we`ve seen regular expressions ( widely known as Regex ). They are expressions used to recognize if a piece of code follows a certain pattern. A regex is usually a string of character representing the expression. Regex'es are language agnostic, meaning they will work with whatever language you are using provided it uses the right libraries.
A regex looks like this : "^[a-z]\d[a-z][\s-]?\d[a-z]\d$" .
This particular regex is used to check a string to see if it represent a canadian postal code (they look like this H2Y 8D7 with a space, dash or nothing in the middle).
How does it works ? Like this : A regular expression is filled with special alphanumeric characters and symbols. How you place these characters determines how the target string will be evaluated. Rather like programming languages with keywords and expressions.
The first set of symbols is the [a-z] interval. An interval is used to represent any value comprised between those two. In this instance I mean any lowercase letter between a to z.
The second set of symbol is \d . \d is a pre-defined character. It means whatever numeric character. It is the same as [0-9] but shorter. Then is another a to z interval. These three expressions are used to check for the first three characters of the targeted string. The last three is checked the same way.
A simple problem we are faced is the middle space, or the absence of it. Indeed we have to check that the fourth character is a space, dash or nothing. Several operators are used to check occurrences of several characters.
A regex looks like this : "^[a-z]\d[a-z][\s-]?\d[a-z]\d$" .
This particular regex is used to check a string to see if it represent a canadian postal code (they look like this H2Y 8D7 with a space, dash or nothing in the middle).
How does it works ? Like this : A regular expression is filled with special alphanumeric characters and symbols. How you place these characters determines how the target string will be evaluated. Rather like programming languages with keywords and expressions.
The first set of symbols is the [a-z] interval. An interval is used to represent any value comprised between those two. In this instance I mean any lowercase letter between a to z.
The second set of symbol is \d . \d is a pre-defined character. It means whatever numeric character. It is the same as [0-9] but shorter. Then is another a to z interval. These three expressions are used to check for the first three characters of the targeted string. The last three is checked the same way.
A simple problem we are faced is the middle space, or the absence of it. Indeed we have to check that the fourth character is a space, dash or nothing. Several operators are used to check occurrences of several characters.
- * : The asterisk is used to check 0, 1 or several occurrences of the previous character. A* will return true to A, AA, AAA, AAAA and basically every A in the text.
- + : The plus sign is used to check 1 or several occurrences of the previous character (or expression between brackets [ ] a "class" ). H+ will return true to HH, HHH and every other series of two consecutive H. Not simply one though.
- ? : The interrogation mark is used to check 0 or 1 occurrence of the previous class. It will test if a class is there or not. This what we need to test if there is a space, a dash or none.
Lastly, you can see symbols in the first and last position of the regex. These are to make sure the value we check does not contain any other characters before and after the string. The ^ symbol is used at the beginning of an expression to check if the string *starts* with the tested expression and the $ is used at the end to check if it *ends* with the expression. Using both we make sure the tested string starts and ends with our pattern.
An example :
We want to check if a string is a Canadian permanent code. These codes are made of four letters and 8 numbers with spaces(or not) at the 5th and 8th position.
Regular Expression :
^[a-z]{4}[-\s]?\d{4}[-\s]?\d{4}$
Test strings :
SIGH03129117
DUG712345673
SIGH 0312 9117
SIGH 03129117
SIGH0312 9117
1234DUGH9154
Using the expression above, we can see that the second and last expression does NOT fit and we did that only by checking it against a string of symbols. Much less hassle than going by letter by letter with a loop.
Here is the program I made in class today, it contains many good examples. Available with the .net framework 4, as are the majority of what I do anyway. Don't forget to grab the latest version.
EDIT : Testing a regex can be a pain in the ass. This is why I use a tool, its here if anyone would like to try it. It is an AWESOME regex testing tool and I recommended it to anyone interested.
EDIT : Testing a regex can be a pain in the ass. This is why I use a tool, its here if anyone would like to try it. It is an AWESOME regex testing tool and I recommended it to anyone interested.
Saturday, February 5, 2011
We need a new prog post !
Ok well, since this is a blog about prog and I'm starting on a very boring and prog-less path. So ! My next post is going to be about some programming stuff, still in VB.net because I like it very much and its easy to explain.
Not sure when I'll make another post, probably in less than 6 months though.
Not sure when I'll make another post, probably in less than 6 months though.
First things first : I need a name
OK, I already have a name. MY name, and I'm not using it for this. I need a company/team name. Its not lerouxtechnologies anymore because it has to be a name to represent multiple people, I intend to make this a team. I have a few candidates I can choose from, this should be fun.
I only have a few choices yet :
I only have a few choices yet :
- Dragon Roost + Software, Team (Not sure which one yet)
- Drunk Gamers
- CodeHackers
- Team Coders
The trouble of finding a new idea
They say ideas flow miles a second in our head. Thats probably why they get out so fast, and why we can't hold on to one. Its a shame really, having abandoned so many projects and having a hard time finding a new one.
So here I am, in search of an idea. One that I can, hopefully, complete in order to learn the right development process. It has been 272 days since my last post and I have created some many project stubs and samples. So many empty test projects. Of course I learned a lot in programming since then, learned new languages (or at least parts) and concepts. With that I hope to create another project with a tad more complexity, or at least something with fun features.
Also my urge to write some new stuff is growing again. So I'll try post my idea gathering here, maybe a couple posts a week. That'd be fun.
So here I am, in search of an idea. One that I can, hopefully, complete in order to learn the right development process. It has been 272 days since my last post and I have created some many project stubs and samples. So many empty test projects. Of course I learned a lot in programming since then, learned new languages (or at least parts) and concepts. With that I hope to create another project with a tad more complexity, or at least something with fun features.
Also my urge to write some new stuff is growing again. So I'll try post my idea gathering here, maybe a couple posts a week. That'd be fun.
Subscribe to:
Posts (Atom)