Browsing the blog archives for November, 2008.

IE Min-Height in CSS

CSS

This is a quick and easy trick/fix for correcting the css min-height problem in IE6.  It is pure CSS and does not require any additional div’s.  Here’s the code:

selector {
  min-height:500px;
  height:auto !important;
  height:500px;
}

That’s it! This trick should be compatible with: IE6, IE7, Mozilla/Firefox/Gecko, Opera 7.x+, Safari1.2

This is not compatible with IE5.5, but with less than 0.01% of my visitors using it I am not overly concerned about implementing this fix on most sites.

You can view Dustin Diaz’s original article here.

No Comments

txtPHPCounter

Scripts

This is a PHP script that I wrote a long time ago (possibly around 2002) to count the unique visitors to your website. It does not require a database and stores everything in a text file.  It is suitable for small websites that don’t expect large amounts of traffic.  It will display web page hits in either text or graphical mode.

Please note that I have not modified this code from its original version so there may be some unknown compatibility issues.  Also, if you do look at the code don’t think that I would still write any code like this.

THIS IS NOT AN EXAMPLE OF MY CODING STYLE/SKILL OF TODAY!

With all the new free Web2.0 tools that are available these days you really should be looking into implementing something like Google Analytics to track your visitors. I just thought I would make txtPHPCounter available since sites are still linking to it.

Download txtPHPCounter.zip

No Comments

Hecklers Bar & Grill

Dining

Looking for a cool new place in Victoria to grab a drink and hang out with friends? Spend one night at Hecklers Bar & Grill located at 123 Gorge Rd, Victoria BC and you will be hooked.  Hecklers has all the games/activities that any serious sports bar should have including a dart board, pool table, Foosball table, bubble hockey, Big Buck Hunter and a recently added pinball machine.

But why stop there? Hecklers Bar & Grill also has a Wii set up on one of their many large LCD tv’s free of charge!  Can you say Wii Bowling League? That’s right; Every Sunday night you can gather your team, step up to the alley and show everyone what you’re made of.   Wii bowling not your style? How about poker?  Every Monday night is a just-for-fun poker challenge.

Laugh much? Hit up Hecklers on Friday for comedy night at Victoria’s only stand up comedy club.  The posters say “Laugh till you pee” and they aren’t joking.  Comedy night features comedians seen on Comedy Central and Just for Laughs. Live music plays every Saturday night with no cover charge!

What about food?! Hecklers has an appetizing with daily specials including 34cent Wednesday wings and $5 appy’s 3pm-6pm.  Mmm Yam Fries!  The basic order of fries for $5 comes with half regular and half yam fries.  Since they make the fries fresh on-site you can order all yams or all regular if you so wish.

Besides the wide array of activities available to keep you occupied, what really makes you want to come back is the atmosphere and the friendly people.  You will always be greeted with a smile and can expect a high-level of service from their great staff.

Thanks for the good times Hecklers!

2 Comments

Comp241 Midterm Review

Miscellaneous

The topics listed below were deemed “important to know” for the Comp241 Midterm scheduled for Nov 13, 2008 by Rob Thorndyke.

Session Management

Client-side

  • scalable – each client is storing its own state, you can have 1 or 1,000,000 clients and it’s all the same to the server
  • distribute load to more servers
  • easier to have persistent data
Server-side

  • secure
  • lower bandwidth requirements – state doesnt go back and forth with each request.
  • sharing data between clients (careful though, session data is generally locked to one client)

Those are the advantages/disadvantages.  How do you actually implement these?

Client

  • Cookies
    • persistent
    • can be turned off / modified
  • Query String (BAD, try not ever to use these if you want your site to rank in google)
    • can’t be turned off
    • user sees it, and curious people will change them
    • search engines can’t deal with them very well
    • browsers can limit the max length
    • setting values is not supported in .NET
    • GET only! does not work with POST
  • View State (implemented using hidden fields)
    • nice support in .NET
    • supports POST
    • with ViewState, watch the bandwidth – everything gets sent back and forth
  • Hidden Fields

For all of the above, data must be key/value pairs and must also be serializable.

Server

  • Sessions
    • unique to each client “connection”
    • time out after a while
    • may depend on Cookies (the session id is generally stored in a cookie, this can be turned off but then the session id goes in the query string)
  • Application
    • global – share data between clients
    • web servers can reset these at seemingly random moments

Data Management

Connected Objects

  • DBCommand – SQL Statement
  • DBConnection – interface to the DB
  • DBDataReader
    • read-only
    • forward-only
    • safer
    • faster (lightweight)
  • DBDataAdapter – read/write and bidirectional

Disconnected Objects

  • DataSet
  • DataTable
    • DataTable.Select() – returns DataRow[] (array of DataRow’s)
  • DataRow
    • Field access (read overwrite)
    • Acts as dictionary
int status = (int) ds.Tables["table"].Select("row = 7")[0]["status"];
  • DataColumn
  • Relation

Data-Bound Controls

  • Control.Databind() – Refreshes the view with current DataSource

Input Validation

General Info

  • gives you a chance to check user input and make sure it is valid
  • generally you need to do the validation on BOTH the server and the client
  • server
    • needed in case client validation is bypassed
    • has access to DB -> more complex validation
  • client
    • convenient – quick validation without PostBack

Validation Controls

  • RequiredFieldValidator
    • non-empty / not “default”
  • CompareValidator
    • compare two values (==, <=, >=, …etc)
  • RangeValidator
    • MinimumValue
    • MaximumValue
    • it checks for value between (inclusive)
  • RegularExpressionValidator
  • CustomValidator
    • ClientFunctionName (javascript function)
    • ServerValidate event handler

C# Properties

private int age;
public int Age {
    get { return age; }
    set { age = value; }
}
No Comments

Comp241 Step 5 Hints

Miscellaneous

The following notes were taken during a lecture in COMP 241 .NET Web Applications at Camosun College by Rob Thorndyke.  These notes are here mainly to help me study, but if you can find some guidance through them then all the better!

Remember Managing State?

Client-side state

  • Hidden Fields
  • String Queries
  • View State
  • Cookies

Server-side state

  • Sessions
  • Application (This is what we will be using for this step)
    • Global dictionary for the entire application
    • This is where we will attach our DataSet
DataSet ds = new DataSet();
// do stuff with the DataSet
Application["ds"] = ds; // To set it.
ds = (DataSet) Application["ds"]; // To retrieve it.

Lab Hints

Game Database Tables

games
game_id, name, status

board
game_id, row, col0, col1, col2, col3, col4, col5, col6

Creating and Joining Connect4 Games

  1. After you create a game:
    • new game entries added to the tables
      1. new Guid “game_id”
      2. set status to JOINABLE
      3. add “blank.png” rows to the board table
    • set my colour to “red”
    • “red” always goes first on new game
    • wait for someone to join the game
  2. Once you join an existing game:
    • set my colour to blue
    • hide new game controls
    • set game status to RED_NEXT

“This is where it gets exciting because you can actually
beat your friends into submission!”

~ Rob Thorndyke
private int STATUS_RED_NEXT = 1;
private int STATUS_BLUE_NEXT = 2;
//...
private int getStatus() {
    string filter = String.Format("game_id = Convert('{0}, System.Guid)", Session["game_id"]);
    DataTable gamesTable = ds.Tables["games"];
    return (int) gamesTable.Select(filter)[0]["status"];
}
 
private string getCellValue(int row, int col) {
    string filter = String.Format("game_id = Convert('{0}', System.Guid)", Session["game_id"]);
    DataTable board = ds.Tables["board"];
    return (string) board.Select(filter + " and row = " + row)[0]["col" + col];
}

To Create a new game:

  • use Guid.CreateNew() to make a new unique id
  • add row to “games” table -> status = STATUS_JOINABLE;
  • add 6 rows to “board” table -> row 0…5; colx = “blank.png”;
  • hide the New Game controls
  • set all ImageButtons to “blank.png”
  • set “game_id” & “my_colour” Session vars

To Join a game:

  • verify status is STATUS_JOINABLE
  • set status to STATUS_RED_NEXT
  • hide New Game controls
  • set “game_id” & “my_colour” Session vars
  • set all ImageButtons to “blank.png”

To “Refresh”:

  • if client is in a game
    • check status for my turn and if so
      • set info label
      • update ImageButtons to see where other guy moved
    • check for game end and if so
      • show New Game controls
      • set info label
  • if NOT in game
    • repopulate Joinable Games List
No Comments