My thoughts are with you Christchurch (#NZEQ #CHCH)
Tuesday, February 22nd, 2011 Leave a comment
while(true) { blog.post(profound.musings, random.discoveries) ; }
Tuesday, February 15th, 2011 Leave a comment
Sometimes Microsoft’s logic impresses me even more than normal. To quote from the Microsoft Support pages:
A 64-bit version of the Microsoft Windows operating system includes the following versions of the Microsoft Open Database Connectivity (ODBC) Data Source Administrator tool (Odbcad32.exe):
The 32-bit version of the Odbcad32.exe file is located in the %systemdrive%\Windows\SysWoW64 folder.
The 64-bit version of the Odbcad32.exe file is located in the %systemdrive%\Windows\System32 folder.
Let me highlight that for you there:
A 64-bit version of the Microsoft Windows operating system includes the following versions of the Microsoft Open Database Connectivity (ODBC) Data Source Administrator tool (Odbcad32.exe):
The 32-bit version of the Odbcad32.exe file is located in the %systemdrive%\Windows\SysWoW64 folder.
The 64-bit version of the Odbcad32.exe file is located in the %systemdrive%\Windows\System32 folder.
Tuesday, February 15th, 2011 1 Comment
I discovered an interesting anomaly today, working with ASP.NET and Web Parts, I had an issue whereby creating a CatalogZone caused the HTML generated from template to lose a whole lot of closing tags. This threw the whole page out the window as the CSS was stuffed. I did a LOT of Googling to no avail.
Finally I went into the tried and true method of trial and error; removing one element at a time until I found the problem bit. This was also anomalous as I have three pages with essentially the same code and only one breaks! I won’t bore you by going through every iteration and step I took, I’ll just bounce to the solution.
In their wisdom Microsoft has apparently made the template work for an odd number of elements, but an even number has a tantrum and is not composed correctly. It was only when I realised that that during my trial and error, the two working pages had 15 and 5 elements respectively, and the “broken” page had 6 elements; thinking this could not possibly be the issue, I checked and was astounded. The general response from my colleagues was “you’ve got to be f@$#en kidding me”. I swear, I’m not.
In summary, from an HTML point of view, this works:
<asp:CatalogZone ID="CatalogZone" runat="server"> <ZoneTemplate> <asp:DeclarativeCatalogPart ID="DeclarativeCatalogPart" runat="server"> <WebPartsTemplate> <tfr:stuff1 ID="stuff1" runat="server" /> <tfr:stuff2 ID="stuff2" runat="server" /> <tfr:stuff3 ID="stuff3" runat="server" /> </WebPartsTemplate> </asp:DeclarativeCatalogPart> <asp:PageCatalogPart ID="PageCatalogPart" runat="server" /> </ZoneTemplate> </asp:CatalogZone>
and this doesn’t:
<asp:CatalogZone ID="CatalogZone" runat="server"> <ZoneTemplate> <asp:DeclarativeCatalogPart ID="DeclarativeCatalogPart" runat="server"> <WebPartsTemplate> <tfr:stuff1 ID="stuff1" runat="server" /> <tfr:stuff2 ID="stuff2" runat="server" /> </WebPartsTemplate> </asp:DeclarativeCatalogPart> <asp:PageCatalogPart ID="PageCatalogPart" runat="server" /> </ZoneTemplate> </asp:CatalogZone>
Monday, February 14th, 2011 Leave a comment
Today’s Valentine’s winner goes to Lily Vanilli in London for their ‘Bleeding Heart’ cake. And, it’s fundraising for < href=”http://trekstock.com/” target=”_blank”>Trekstock, with 20% of proceeds going to support their work with young people with cancer.
[via SideSwipe]
Monday, February 14th, 2011 Leave a comment
A website I’ve been working on has a WordPress blog included in it. The site is not using WordPress as the CMS, just as one section. While the blog is sub-foldered (e.g. http://[SITENAME]/blog/) there was still a need to refer to the tags elsewhere on the website, and link to them. While it would definitely be possible to reference components of the blog itself, and then call the function/s to get tags and counts etc, I decided to hook into the DB with some SQL and rock it from there.
After a quick explore of the WordPress DB, I pulled the tables and fields I needed to reference in order to get the results I desired. The query itself is pretty straight-forward:
SELECT wp_term_taxonomy.count AS count, wp_terms.name AS name FROM wp_term_taxonomy, wp_terms WHERE wp_term_taxonomy.term_taxonomy_id = wp_terms.term_id AND wp_term_taxonomy.taxonomy = 'post_tag';
Walking through this query step-by-step we have:
SELECT wp_term_taxonomy.count AS count, wp_terms.name AS nameFROM wp_term_taxonomy, wp_terms WHERE wp_term_taxonomy.term_taxonomy_id = wp_terms.term_id AND wp_term_taxonomy.taxonomy = 'post_tag';Implementation is very simple, the sample below is a delivery in PHP:
// connect to your DB
$sql = "SELECT wp_term_taxonomy.count AS count, wp_terms.name AS name ".
"FROM wp_term_taxonomy, wp_terms ".
"WHERE wp_term_taxonomy.term_taxonomy_id = wp_terms.term_id ".
"AND wp_term_taxonomy.taxonomy = 'post_tag';";
$taglinks = "";
$result = @mysql_query($sql);
if($result) {
while($row = mysql_fetch_array($result)) {
$tag = $row['name'];
$count = $row['count'];
$taglinks .= "<a href='http://[SITENAME]/blog/?tag={$tag}'
class='tag-link-{$count}' title='{$tag}' >
{$tag}</a><br /> ";
}
// close the DB connection for security, e.g.
// mysql_close([CONNECTION]);
}
In my example, I have retrieved the tags and their counts and formatted them into absolute links which are styled based on the number of uses. This enables them to be displayed more prominently based on popularity for example.
Sunday, February 13th, 2011 1 Comment
This is brilliant, this photo shop in Singapore is truly wearing Christ on their sleeve daily and affirming their faith. The name says it all.
Thursday, February 10th, 2011 Leave a comment
The for loop in C# is useful for iterating over arrays and for sequential processing. That is the statements within the code block of a for loop will execute a series of statements as long as a specific condition remains true. E.g.:
for(initialization; condition; increment) {
statement/s
}
initialization : Initialize the value of variable
condition : Evaluate the condition based on the variable
increment : Step taken for each execution of loop body
The for loop initializes the value before the first step. Then checks the condition against the current value of the variable and executes the statement/s inside the loop before incrementing.
int count = 4;
for(int i = 0; i < count; i++) {
MessageBox.Show("The first number is: " + i);
}
This outputs:
The first number is: 0 The first number is: 1 The first number is: 2 The first number is: 3
The loop executes four times because we set the condition as being i is less than count, and i was initially 0.
All expressions in a for loop declaration are optional. The following creates an infinite loop:
for( ; ; ) {
statement/s
}
in much the same way as simply using while(true) creates an infinite loop, e.g.:
while(true) {
statement/s
}
Happy looping!
Thursday, February 10th, 2011 1 Comment
Closing a browser window with JavaScript is easy, you just call window.close(); however catching the browser close event and preventing it is another kettle of fish. I’ve been working on this a bit on-and-off, and have managed to pull together what I think is a reasonable solution [NOTE: this does not work in Opera, as it uses the onunload() and onbeforeunload() events, which are not supported by Opera 11].
The solution I have come up with is pretty simple once you see it. I put the following code either in my JavaScript library included into the page, or I just place it at the top of the required page (in tags, of course):
function checkClose() {
if (ok) {
return "Have you saved your information?";
}
}
var ok = true; // this is reset everytime a new page is loaded
function okToLeave() { // called if leaving the page is needed
ok = false;
}
window.onbeforeunload = checkClose;
window.onunload = checkClose;
and in my links where I’m happy to leave the page without checking (i.e. on submitting a form):
I have also allowed for a cancel event, where I don’t want the checkClose() event called, but I still want to catch the close/departure:
What we have going on here is a standard JS being called whenever there is a page unloaded. This can be due to clicking a link, entering a new URL in the browser, or closing the window or tab. The JS call will be to checkClose(). If checking before exit is required, then the pop-up is activated. If the page-exiting event is not a problem, then the JS inserted within this event (onclick="okToLeave();") sets the checking variable (ok), which then causes the checkClose() function to do nothing, so the onunload events are not thwarted. In some circumstances (i.e. the Cancel button being clicked) we don’t want the onunload event called, but we do want to confirm departure; in these cases the extra JS inserted in the event (onclick="okToLeave(); return confirm('Confirm leaving this page.');") warns and confirms with the client user.
This approach is only necessary if you are trying to check for events not triggered within your own page (e.g. the window closing event), otherwise it is just overkill. If you only want to confirm when certain links are used, then insert the check within their use, i.e.:
<a href="otherpage.html" onclick="confirm('Do you really
want to leave this page?')" >this is a link</a>
I did like this comment I found on a forum regarding this concept though:
The question is not how but why??
If a user wants to close his browser, that’s his god-given right!If you don’t want him to close it, make it so there’s something interesting in the window. (Naked women seem to do the trick for a lot of people)
recent comments