Automatic Get/Set Visual C# 2010
One of my favorite features of c#. Automatic getters/setters!
Before, one would have to declare a variable.
private int _x;
And then write get/set methods:
public int X{
get{return _x;}
set{x=value;}
}
However, in VISUAL C# 2010 - you can now do the following:
public int X{get;set;} Which is the same as the code above!
Note: If you want to wrap any validation or anything around the get/set you will still need to write out the full get/set. However, for quick variables that require no extra work - the automatic get/set is a lifesaver! (or timesaver - if you're life is not in danger...whichever you prefer)
C#/PHP Database Object Generator/Database Access Layer Generator
This is something i have been working on.
It is virtually a tool I use to generate c#/php classes based on a database schema.
The c#/SQL integration works well, however, I am still working to support the php/mysql generation.
It creates very simple base C# classes based on a database connection. The program includes Saving Generation profiles and reloading them at a later time. It has a recently loaded profiles list - and allows you to regenerate the DAO as many times as you like.
By using this C# Database Object Generator/Database Access Layer Creation Tool I can focus on my application development as opposed to my DAL (data access layer) development.
This piece of software is currently in beta - and I am the only beta tester!
If you would like the installer - you can send me an email and I can send you a copy.
Here are some screenshots and some example usage!
And example usage of the classes generated by the c# database object generator tool. Note - the class HeroBase was from the generation files.
public HeroBase GetHeroById(int id)
{
SqlConnection conn = serv.GetConnection();
try
{
conn.Open();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "SELECT * FROM hero WHERE hero_id="+id;
cmd.Connection = conn;
SqlDataReader rdr = cmd.ExecuteReader();
while (rdr.Read())
{
HeroBase h = HeroFromReaderRow(rdr);
if (h != null)
return h;
}
}
catch (Exception ex)
{
throw new Exception("Could not load Heros " + ex.Message);
}
finally
{
conn.Close();
}
return null;
}
public HeroBase HeroFromReaderRow(SqlDataReader rdr)
{
if (rdr == null)
return null;
HeroBase h = new HeroBase();
h.HeroId = Convert.ToInt32(rdr["hero_id"]);
h.HeroName = rdr["hero_name"].ToString();
h.HeroDescription = rdr["hero_description"].ToString();
h.HeroType = rdr["hero_type"].ToString();
h.ImageFile = rdr["image_file"].ToString();
h.ModelFile = rdr["model_file"].ToString();
h.BaseAutoAttackLow = Convert.ToInt32(rdr["base_auto_attack_low"]);
h.BaseAutoAttackHigh = Convert.ToInt32(rdr["base_auto_attack_high"]);
h.BaseMovementSpeed = Convert.ToInt32(rdr["base_movement_speed"]);
h.Premium = Convert.ToBoolean(rdr["premium"]);
h.Concentration = Convert.ToInt32(rdr["concentration"]);
h.ModelRotation = Convert.ToDouble(rdr["model_rotation"]);
h.ModelScale = Convert.ToDouble(rdr["model_scale"]);
h.Active = Convert.ToBoolean(rdr["active"]);
return h;
}
The reason the classes are affixed with the 'Base' word, is because this allows for the extension of these classes. HeroBase is the database version of the class - which includes base_hp, base_energy, base_movement_speed etc etc, however, an actual hero in a game will have much more than this (hp timers, energy/mana timers, current hp, current energy) - the naming of the classes allows for you to easily extend them.
For example:
public class Hero:HeroBase(){
public Hero():base(){
CurrentHP=MaxHP;
}
public int CurrentHP{get;set;}
}
I have classes created named service.
E.g HeroService - this service has necessary methods for loading heroes from the database. This service returns objects of the Hero/HeroBase type.
All in all - it saves me a ton of time and I am glad Ive written this tool. Please comment if you have any interest in it - as I would like to gauge interest before I invest more of my time into refining it. As it sits now - it is perfect for my side project development, however, if there is enough interest - I am more than willing to improve it
Beginner Game programming jobs in Toronto
Well, it seems to me that finding a game programming job in Toronto is going to be pretty hard.
I have used XNA and am currently working on a small c#/xna based engine for a game.
Currently I have the following, none of which are graphical (except for the heroes with a small chase camera):
Heroes (Health, HP regen, Energy Regen, Attacking Mechanisms, Defense Mechanisms)
Hero Abilities
Hero Stats
Creep Waves (CreepEngine class responsible for spawning waves and keeping track of wave timers etc)
and am currently working on a few mechanics - like stealing gold etc.
I guess Im just doing this to kill time and practice coding a game engine, but hopefully it gets to a point where it could be useful to someone.
It seems breaking into the game programming industry will be harder than I thought - teachers in college often discouraged me from it - saying it was a hard industry with tight deadlines etc etc...but what can be more fun than MAKING GAMES?!
There will be a point in time where I know that programming business apps will no longer do it for me - and thats when I want to switch over to game programming. Call it a midlife crisis (at 22 years old) - but I am passionate about it! It seems that most video game companies already want a ton of experience in the game industry - how can someone get that experience if no one in the industry will hire?
Its nuts.
3years with an advanced college diploma - and its not enough.
Everyone wants a bachelors degree in comp sci - because having the money to pay your way through university and being in debt is somehow a sign that your dedicated. I will continue working on my little demo - it wont be easy and it will take a while but, I will get there.
Is anyone in the same situation as me?
Does anyone feel helpless with this whole video game industry?
Its such a big industry - I don't even know where to start (Sure, I can go to a game programming school for $15,000/yr) - but life isnt a crystal staircase and I have bills to pay).
Any tips, inside knowledge etc, is highly appreciated - [b]comment if you'd like please!!!
[/b]
HostGator 2010 Black Friday Sale Special 50-80% off hosting!
Discounted hosting has never been better!
As a hostgator affiliate I get emails and notices about their specials. And this one blew my mind.
One day only 50-80% off!!
Now - let me be perfectly frank - I am an affiliate and do make commissions off referrals - but come on 80% off hosting for 3 years? Thats awesome any way you slice it. (horizontal, vertical, or diagonal). But, even if I didn't make any commission referring - i would still HIGHLY recommend them. Their live support chat always gets 10 ratings from me across the board!
Here is an excerpt from my affiliate email (we're obviously refers to hostgator)
:
We're offering 50% OFF EVERYTHING From 12:00AM CST – 5AM CST (11am EST - 4am EST)
We're offering 80% OFF EVERYTHING From 5AM – 9AM CST (4am EST - 9am EST) WHILE SUPPLIES LAST (first come, first receive; so definitely don't miss out!)
From 9AM – 11:59PM CST (8am-10:59pm) OR after 80% OFF accounts have sold out, we will continue to offer 50% OFF EVERYTHING
This applies to ALL Accounts and ALL Term Lengths. So you're visitors and friends will have the opportunity to receive up to 80% off of up to 3 years worth of Hosting! That would come out to $35.64 for 3 FULL YEARS!
And - The links you have all been waiting for:
(Feel free to use hostgator.com if you do not want me to get commission on your referral)
ENJOY!!!! ![]()
Theyve treated me really well - and they will treat you just as well.
HostGator Discount Code 2010 – Cheap Web Hosting
By far one of the best hosting companies I have had the experience of being a customer of is HostGator. Their prices are extremely affordable and their customer support is SUPERB. I have never had a web hosting company with the technical expertise and patience of the live support chat. They always answer questions and help configure servers. I have had live support chat agents sit there patiently and wait for me to re-test my site after their changes.
Our programming company uses HostGator to host all of our sites - they have shared web hosting, reseller accounts, and others.
They offer UNLIMITED disk space hosting (250,000 files maximum ...100,000 if you intend to use the auto-backup feature) and
UNLIMITED bandwidth and are just the best hosting company i have ever had the pleasure of working with.
Use one of these HostGator 2010 coupon codes to receive $9.94 off your first month!
HostGator Discount Coupons/Promo Codes:
HostGator 2010 coupon/promo code 1: 994offhgpackage
HostGator 2010 coupon/promo code 2: 2010hostgatorcoupon
HostGator 2010 coupon/promo code 3: hostgatorcoupon2010
With the "BABY" plan for 1 month this means you pay $0.01 for 1 month hosting!
How To Remove Viruses and Spyware Manually
Remove Viruses and Spyware Manually
Viruses,spyware, malware - whatever you want to call it, these things wreak havoc on your computer. Browser hijacks, file deletion, disabling ctrl+alt+delete are just a few things that some of these baddies can do. However, there are some tools to help you remove viruses and spyware manually.
Preventing Viruses and Spyware
Prevention is the best medicine. I'm sure you've heard something like that before but its true. Knowing about how to prevent spyware goes a long way. There are many programs that offer virus+spyware/malware protection and they will monitor your computer for changes to your registry and files. I recommend the following programs for spyware/malware protection and scans.
Spyware Search & Destroy (Spybot S&D)
Ad-aware SE (Free for personal use)
Steps To Remove Viruses and Spyware Manually
- Download and Update 1 of the above software (or all 3! [recommended])
- Perform scans - Use the above programs to perform viruses, spyware, and adware scans. This is usually the initial step in removal as it will remove most of the spyware/adware/malware on your computer. I recommend using safe mode to do these scans. In safe mode, your computer does not load extra applications and drivers, only the bare minimum need to run your operating system, so these programs will have an easier time removing/deleting files from these viruses. There are different ways to get into Windows Safe Mode. On my computer, I turn off the power and turn the computer on. I keep hitting the F5 key until i get a prompt asking how I want to boot. I select safe mode and let it load. On your computer it may be a different F key...like F7.
- Check your startup using msconfig - Now that we have run scans and have done an initial clean on our computer. We can check our startup. Hit Start, then Run and type msconfig. Hit OK. Click the Startup tab, and look through the list. For the most part, anything here can really be unchecked. Try to look at the file path and the name of the checked items, this will usually give you a hint of what is what. Example: Logitech Quickcam Driver -> This is probably your camera driver, dont disable it. Once you go through the list and uncheck unwated items, click apply. Restart when you are prompted to. After restarting, click Do Not Show This Message Again and click OK.
- HijackThis! - Download Hijack This Hijack This is a program that will scan your computer and show information about changes that have been made to it. Download and install hijack this and run a scan and produce a log. You can copy and paste your log into this site: http://hjt.networktechs.com/ and it will guide you onto what to remove (To remove items, place checks next to them and click Fix Selected Issues) . Also, there are many forums which will let you paste a HJT log and other kind users will help you analyze it. Alternatively, you can post your HJT log in the comments below and I will try to assist you with it.
- CC Cleaner - Download CC Cleaner CC Cleaner will help remove temporary browser files, cookies, recycle bin, some program cache info. It is a good idea to run this program every once in a while just to help free up some space and keep your programs running in top shape.
- Reformat (Last Resort/First Resort) - A lot of viruses and spyware can be removed with the above steps, however, sometimes you get very pesky viruses and programs. If you think the malware/adware/virus will be extremely difficult to remove, or if it is extremely malicious (i.e rootkit viruses that attach to windows files) sometimes the BEST option is to reformat and reinstall windows. This is the ONLY way to ensure your computer is COMPLETELY free of spyware. The programs listed above often do the trick. Sometimes you will do Steps 1-5 and then decide to reformat anyways because they couldn't completely remove the infection. Sometimes when I get extremely pesky infections, I reformat as my first resort. A backup, reformat and reinstall of all my programs takes me less than 4hours. Sometimes, virus removal and infection cleaning takes more than this.
Hope this guide helps you remove viruses and spyware infections. I often get paid to clean and remove spyware, adware, and viruses, however, I don't mind sharing how I do it. Most people just cant be bothered with it, but, if you can take the time to do the steps above, you will have a cleaner, faster, better, smoother running computer.
Comment if this helped you!
Paste your HJT logs if you need assistance.
Dreamweaver error: xml parsing fatal error: Invalid document structure
If you get an error like this, chances are one of your layout files went corrupt.
I received an xml parsing fatal error: mentioning that my workspace file Designer.xml could not be read.
If you get this error too, no worries, fixing it is simple.
Go to C:/. Click Tools>Folder Options. Click the View Tab. Click 'Show hidden files and folders'.
Navigate to C:/Documents and Settings/username/Application Data/Adobe/Dreamweaver/en_us/Configuration/Workspace. Make a new folder and move all files in that directory into this new folder. Close Dreamweaver and restart it. You should have no more problems with Dreamweaver (this may also work with Flash) and it should load.
Comment if this helped
Easy, Simple Paging Using PHP
Easy & Simple Paging using PHP. Here is the result: (DB has 8records, Rows per page is set to 5, and we're on page 2)

Paging usually takes a while but here we will do it quickly and cleanly.
Your page will be named page.php. And when we want to switch pages we will make it page.php?pg=2.
Im sure you've seen this before. Anyways lets dive in.
I use shorthand to clean stuff up, but basically shorthand is
$returnvalue=(condition ? "true" : "false");
Example:
$is_loggedin=(isset($_SESSION["loggedin"]) ? 1 : 0);
After this statement, if the session variable is set, $is_loggedin will equal 1, else it will equal 0.
At the top of your PHP page type the following:
<?php /*paging*/ Line 1: $pg=(isset($_GET["pg"]) && is_numeric($_GET["pg"]) && $_GET["pg"]>0 ? $_GET["pg"] : 1); Line 2: $rowsperpage=10; Line 3: $offset=($pg>1 ? ($pg-1)*$rowsperpage : 0 ); Line 4: $limitstr=" LIMIT $offset, $rowsperpage"; ?>
Explanation:
First of all Limit is : LIMIT $startrowid, $number of entries to return
So LIMIT 55, 5 means start at row 55 and return 5 rows (55, 56, 57, 58, 59)
Line 1: If in the query string the pg is set e.g page.php?pg=4, and it is numeric, and greater than 0 we will assign the value of $_GET["pg"] to our $pg variable. If it is not set, or it is not numeric, or zero or less, we set the $pg variable to 1.
Line 2: We set our rows per page
Line 3: If the page is greater than 1, we set the offset to ($pg-1)*rowsperpage. If the page is 1 or less, we set offset to 0.
Line 4: We create the limit string for the sql statement. This will output something like LIMIT x, y.
(rowsperpage set to 10)
In this case page.php?pg=1
$pg = 1;
$offset = 0;
$rowsperpage=10;
$limitstr="LIMIT 0, 10"; //this string will pull 10 rows starting from row 0 (the first row) (rows 0-9)
In this case page.php?pg=3
$pg=3;
$offset= (3-1) * 10; //offset calculates to 20
$limitstr="LIMIT 20, 10"; //this string will pull 10 rows starting from and including row 20 (rows 20-29)
Ok. Now that we got that out of the way.
We will use a simple query, then we will attach our new limit string (looking at case 2 above)
$sql="SELECT * FROM MEMBERS $limitstr"; //sql = "SELECT * FROM MEMBERS LIMIT 20,10";
$res=mysql_query($sql);
while($row=mysql_fetch_array($res)){
//processing if you need to
}
We also need to know the total count for this table
$sql="SELECT COUNT(memberid) FROM MEMBERS";
$res=mysql_query($sql);
$row=mysql_fetch_array($res);
$total = $row[0];
Now we know the total count.
So we need to calculate the number of pages. That is done by this formula:
($total/$rowsperpage);
Now in the case of 26 members and 5 rows per page. Using this formula 26/5 = 5.2pages, so we need to round up!
$maxpage=ceil($total/$rowsperpage); //max page is now 6.
Ok, we got everything set up
Just need to print out our paging!
Wherever you want your paging setup add this:
<?php
print '<div class="paging"><ul>';
for($i=1; $i<=$maxpage; $i++){
if($pg==$i)
print '<li><span>'.$i.'</span></li>';
else
print '<li><a href="?pg='.$i.'">'.$i.'</a></li>';
}
print "</ul></div>";
?>
Then we can do some nice styling (Mess around with margins to setup spacing)
CSS
div.paging {text-align: center; margin-top: 5px;}
div.paging span{font-weight: bold;}
div.paging ul{overflow: hidden;}
div.paging ul li{width: 10px; float: left; margin: 0px 10px 5px 0px;}
This will page across until it hits the edge of the div, then it will move to the next line.
ENJOY and comment !
Recursing through a directory/filesystem using C#
This will teach you how to recurse through a directory/filesystem using C#..
The problem comes from not knowing how many folders/files exist.
One folder can have many folders inside it, those folders can each have many folders inside it.
I will show you how to recurse through the filesystem and explain it so that you UNDERSTAND it. This isnt for copy-paste.
We will start with a C# console application and pick a path, we'll use C: for this.
First of all, we're going to need the IO namespace. The IO namespace has access to File and Directory methods.
At the top add these lines:
using System; //Just so we can use the shortcut Console instead of System.Console using System.IO; //Gives us access to file, directory objects
Now, in our "main" method, we are going to write the following:
string path="C:/"; //set the root path we want to recurse through.
//check if the directory exists
if(Directory.Exists(path)){
DirectoryInfo di=new DirectoryInfo(path);
//based on a path, this object will give you directory information about that directory
printDirectories(di);
//this method will actually go through our directories and print out information
}else{
Console.WriteLine("Directory does not exist. Press Enter to exit");
Console.ReadLine(); //when you hit return the program will terminate.
}
Now we will write the print directories method. It takes a DirectoryInfo object as a parameter and will use that to recurse through the file system.
//declared as static because were a console app, this can be private in your application if it a utility method.
2 Important methods we're going to be looking at are in the DirectoryInfo object. They are
public FileInfo[] directoryInfoObject.GetFiles() //returns an array of FileInfo objects
public DirectoryInfo[] directoryInfoObject.GetDirectories() //returns an array of DirectoryInfo objects
static void printDirectories(DirectoryInfo di){
foreach(FileInfo fi in di.GetFiles()){
//we are going to run code for each file
Console.WriteLine(fi.FullName); //this prints out the full file name including the path
}
//now that we process this directory for files, we do the same for every subdirectory in this directory
foreach(DirectoryInfo subDir in di.GetDirectories()){
//we are going to call the printDirectories method, with the subdirectory as the root.
//its files will be processed, then its subdirectories will be checked
//this happens foreach Directory in the current directory
printDirectories(subDir); //recurse
}
}
Thats simple recursion. The most common use of this is for populating a treeview and another use that comes to mind is file searching. Keep an eye out for the next tutorial: Populating a Treeview from a file system!
Adding/Insert Line Breaks into a Textarea
Seems like a simple enough problem to solve...just use \n or a br tag
right? ...wrong.
This markup <textarea>Test<br/>Newline</textarea> produces:
And the markup <textarea>Test\nNewline</textarea> produces:
The trick to inserting a new line is to use the character for a carriage return. I stumbled upon this when I ran into this problem. I opened a new notepad file and made a simple textarea. When typing in it, I noticed that when I press enter it goes to a new line (obviously), so I figured why not try to put a carriage return into the textarea. The carriage return representation is .
So the markup <textarea>Test Newline</textarea> produces:
And there you have it, simple problem to which the answer may take 30+ minutes to find.
Hopefully I save you that 30 mins ![]()
Comment, Enjoy ![]()



