Always aim to do something slightly impossible
Wheneven you set your goals in life, in work, in your current project or just today, always aim to do something slightly impossible. Not completely impossible, just slightly.
I guess the man in the image must have thought something similar when he woke up one morning. What a marvalous picture!
HttpContext.Current.Request.UserHostAddress returns ::1
Posted by: Elmer in C#, DotNET, Uncategorized, VB on May 27th, 2009
One would expect HttpContext.Current.Request.UserHostAddress to return the IP address of the client computer. On my developement machine this would be 127.0.0.1. The application I’m working on acts on this IP address, so it is fital to get the correct address.
Since I’ve moved to Windows Server 2008 x64 on my laptop, I got ::1 as a result from HttpContext.Current.Request.UserHostAddress. After some searching I found out that the hosts file actually contained two entries for localhost: 127.0.0.1 and ::1. Removing the ::1 entry solved the problem. I’ve heard people using Windows Vista also have this problem.
Space Shuttle software
Posted by: Elmer in Programming on May 15th, 2009
I just finished reading this article about the developement team that makes the Space Shuttle software. There are a few simple and valuable lessons to be learned from their work:
Design before you code
Design and blueprint as much as you can before starting the actual programming. Also, make sure the client reads the documentation and approves it.
Learn from your mistakes
When you find a bug, fix it (duh!). But don’t stop there! Also fix the system or procedure that allowed the bug to happen. Create an environment that does not allow bugs and errors to find their way into production.
MultipleActiveResultSets (MARS), SQL server 2000 and LINQ
Using the MultipleActiveResultSets setting in a connection string allows one to have multiple datareaders open on the same connection, at the same time. This setting was introduced with SQL server 2005. Setting it with SQL server 2000 does not have any effect, or so I thought.
Change ’sa’ password on SQL server 2008
If you happen to forget your SQL Server password for ’sa’ account, then here’s a simple query to help you reset it:
ALTER LOGIN [sa] WITH DEFAULT_DATABASE=[master]
GO
USE [master]
GO
ALTER LOGIN [sa] WITH PASSWORD=N'MyNewPassword' MUST_CHANGE
GO
In Case you remember your Old Password and want to change the ’sa’ password, use this query:
ALTER LOGIN [sa] WITH PASSWORD = N'MyNewPassword' OLD_PASSWORD = 'MyOldPassword';
GO
Using preg_replace_callback on class methods
To prevent an error like preg_replace_callback() [function.preg-replace-callback]: Requires argument 2, ‘function_name’, to be a valid callback, use the following snippet:
$text = preg_replace_callback(
'((http(s?)\://){1}\S+)',
array(get_class($this), 'function_name'),
$text
);
The trick is to call the method like so:
array(get_class($this), '__shortUrl')
Could not load file or assembly ‘Name’ or one of its dependencies. An attempt was made to load a program with an incorrect format.
On a 64-bit Windows installation this is caused by the fact that assemblies are compiled for x86 processors only. To change the compile settings do the following:
- Open the project properties
- Open the Compile tab
- Open the Advanced Compile Options… window
- Change the Target CPU from x86 to AnyCPU
- Recompile
Happy programming!
Regex to match all uri’s (http, ftp, mailto)
Very usefull regex for finding and replacing all uri’s in a document…
((mailto\\:|(news|(ht|f)tp(s?))\\://){1}\\S+)
CakePHP not showing new tables when using cake bake
When newly created tables don’t show up when using the console application
cake bake
then it’s time to clean out the model cache.
The model cache is located in /app/tmp/cache/models/
PHP frameworks compared
For my latest project, using PHP/MySQL, I wanted to use a framework to take some of the repetitive from me. I’ve looked at a number of frameworks, and here are some of my findings. Read the rest of this entry »
DokuWiki, a worthy tiddlywiki alternative?
I’ve been playing with tiddlywiki a bit lately, and I haven’t been very impressed with it. I’ve been looking at some alternatives, because I do like the wiki way of creating and editing pages very much. And I found DokuWiki to be a very nice wiki.
- It’s light-weight
- It doesn’t require a database (pages are stored as txt files)
- It’s easy to install (just copy it to a server)
- It’s very flexible (good plug-in and template support)
I’m currently using it as my main wiki.
The only small drawbacks is that it does require a server running PHP. But as if you can live with that, I definitely recommend you have a look at DokuWiki.
So, is DokuWiki a worthy tiddlewiki alternative? Yes, I think it is!
CSS hacks
-property
Prepending a property with a non-alphanumeric character like – (or underscore) will cause most browser to ignore that line. Internet Explorer 6 and earlier however do apply the rule.
*property
The previous issue was fixed in Internet Explorer 7, but properties with an asterix(*) immediatly before its name are applied in IE 7.
Examples:
border: 1px solid red; /* applied in all browsers */
-border: 1px solid green; /* applied in IE 4,5,6 -- not in 7 */
*border: 1px solid blue; /* applied in IE 7 */
Simple JavaScript execution timer
Posted by: Elmer in JavaScript on January 15th, 2009
/**
* Simple JavaScript execution timer
* http://programming.torensma.net
*
* Example:
* scriptTimer.startTimer();
* alert('Hello world!');
* scriptTimer.stopTimer();
* alert(scriptTimer.scriptRunTime);
*/
var scriptTimer = {
scriptRunTime : 0,
startTime : 0,
stopTime : 0,
startTimer : function(){
time = new Date();
this.startTime = time.getTime();
},
stopTimer : function(){
time = new Date();
this.stopTime = time.getTime();
this.scriptRunTime = (this.stopTime - this.startTime)/1000;
}
}
Extracting a substring from a TEXT field in MySQL
The following SQL snippet extracts the text between <H3> and </H3> in the raw column:
SELECT mid(left(raw, locate('', raw)-1), locate('
', raw)+4) FROM table
Connect PowerShell to MySQL
Posted by: Elmer in powershell on January 14th, 2009
Using the MySQL.NET connector, it’s possible to connect to a MySQL database using PowerShell.
[void][system.reflection.Assembly]::LoadFrom(\"d:\\tools\\mysql-connector\\bin\\MySQL.Data.dll\")
$myconnection = New-Object MySql.Data.MySqlClient.MySqlConnection
$myconnection.ConnectionString = \"server=localhost;user id=test;password=test;database=test;pooling=false\"
$myconnection.Open()
$mycommand = New-Object MySql.Data.MySqlClient.MySqlCommand
$mycommand.Connection = $myconnection
$mycommand.CommandText = "SHOW TABLES"
$myreader = $mycommand.ExecuteReader()
while($myreader.Read()){ $myreader.GetString(0) }
This example will display all tables in the connected database.
