December 12th, 2011
Further to the original rollout of FTTN, Arbroath is on the list of exchanges to be upgraded in 2012.
w00t!
[Via: BT Plc.]
Tags: Computing, Interests, Technology
November 30th, 2011
I’ve been working on a project where I have to maintain data in a SQL Server database. In order to prevent different users updating the same data at the same time, I’ve also employed optimistic locking by using a “timestamp” field called OLToken on each table which is binary. This field is read out and is used in any Insert and Update statements to ascertain if the record has been updated since the data was read out.
I’m using PHP to get each record. There isn’t much on the web about working with timestamp fields in PHP, so I created the function below to convert and store the OLToken as an integer:
function ConvertOLToken ($theToken)
{
$OLToken = "";
for ($i = 0; $i < strlen ($theToken); $i++)
{
$Byte = dechex (ord ($theToken[$i]));
$OLToken .= str_pad ($Byte, 2, "0", STR_PAD_LEFT);
}
return hexdec($OLToken);
}
This value is passed back to stored procedures as an integer parameter and used in stored procedures:
IF EXISTS (
SELECT 1
FROM [Table]
WHERE [ID] = @pID
AND [OLToken] = CONVERT([binary](8), @pOLToken))
BEGIN
...
END
Tags: Personal, PHP, Projects, SQL
August 26th, 2011
I ran into problems with the auto-upgrade facility of WordPress on my sites hosted here, on NearlyFreeSpeech.net.
Through trial and error, I established the following works:
- Add the following lines to
wp-config.php:
define('FS_METHOD', 'direct');
define('FTP_BASE', '/public/');
define('FTP_CONTENT_DIR', '/public/wp-content/');
define('FTP_PLUGIN_DIR ', '/public/wp-content/plugins/');
define('FTP_USER', '---your username---');
define('FTP_HOST', 'ssh.phx.nearlyfreespeech.net:22');
define('FTP_PASS', '---your password---');
- Using PuTTY, log-in.
- Enter the following command:
chgrp -R web *. This will change the group ownership of all files and directories to web. This is the required ownership for WordPress to perform the upgrade.
- Enter the following command:
chmod -R 777 *. This will change the permissions on all files and directories to full public access.
- Perform any WordPress upgrades; core, plugins or themes. It shouldn’t ask for any connection details.
- Enter the following command:
find . -type d -print0 | xargs -0 chmod 755. This will reset all directory permissions to read-only for everyone except the owner (you).
- Enter the following command:
find . -type f -print0 | xargs -0 chmod 644. This will reset all file permissions to read-only for everyone except the owner (you).
- Enter the following command:
chmod -R 775 wp-content. This will update the permissions on the wp-content directory to be 775, allowing uploads, including from the media library.
You only have to do steps 1 and 3 once. Steps 4 to 8 have to be performed for upgrade.
Although not essential, the last three steps should be performed, as it is highly insecure to leave permissions set as public (777).
Also using SSH rather than FTP conforms with the view of NearlyFreeSpeech.net that FTP should not be used as passwords are transferred in plaintext.
Thanks to SNARP for the original article.
Tags: Interests, NearlyFreeSpeech, Personal, PHP, WordPress
July 7th, 2011
I recently had to perform a change on any stored procedures that contained a certain piece of text. Not knowing how to search for text across a database, I googled it and found the following small piece of useful code:
SELECT [ROUTINE_NAME], [ROUTINE_DEFINITION]
FROM [INFORMATION_SCHEMA].[ROUTINES]
WHERE [ROUTINE_DEFINITION] LIKE '%<insert_text_here>%'
AND [ROUTINE_TYPE] = 'PROCEDURE'
[Via: ASP FAQ]
Tags: Computing, SQL
March 29th, 2011
I did not brandish two knives outside a nightclub.
Nor did I say “‘Mon then! I’ll hae ye a’!”.
Tags: Opinion, Personal
December 29th, 2010
Radio North Angus, the independent local and healthcare radio service, has moved into the 21st century by having their broadcasting streaming on their website.
The service, having had some teething troubles, is now fully functional with availability 24 hours a day.
The transmission is fed from the desk at Arbroath Infirmary into a Barix Instreamer 100 (which is also used to trasmit the DAB service), and the streaming service itself is supplied by MixStream. A very big thanks to the guys on the service desk who provided some much need support.
This is the first streaming service I have set-up, so hopefully it will be well received.
Tags: Blog Add-ons, Gadgets & Gizmos, Interests, Personal, Projects, Technology
November 23rd, 2010
I’ve just added a new Bingo simulator that we will be using with the Company Section.
It’s written using jQuery, which I’m thoroughly enjoying; as is another larger project that I’m working on.
More on that soon, but until then, have a look at the Bingo at let me know what you think…
Tags: Interests, jQuery, Links, Personal, Projects
August 4th, 2010
Since implementing crossfading of tracks in Karaokidex, I’ve indicated the crossfading by gradually fading out the background colour of the first track’s row in the playlist DataGridView and fading in the background colour of the second track’s row. This caused a really annoying flickering.
The problem is the DataGridView is not double-buffered by default, nor is there any visible property on the DataGridView object to set it as double-buffered.
Google to the rescue!
Thanks to the guys at StackOverflow.com for this elegant solution that uses reflection rather than defining a custom class.
typeof(DataGridView).InvokeMember(
"DoubleBuffered",
BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.SetProperty,
null,
myDataGridViewObject,
new object[] { true });
[Via: stackoverflow]
Tags: C#, Computing, Interests, Opinion, Projects
August 2nd, 2010
Since Service Pack 1 of Visual Studio 2008, setting file associations has never been easier. The publish options dialog has four pages; once of which is the “File Associations” page. After one or more entries has been added, and the app published, the ClickOnce app will now be launched whenever an associated file is opened from explorer.
This is fine, unless you only want one instance of your app to be running at any one time. Each time an associated file is opened, a new instance of the ClickOnce app will be launched. If your single-instance app is open and you try to open an associated file, the reference to the file will be lost when the new instance detects that the original instance is running and terminates. Grrr.
However, you can get round this. After detecting that there is another instance of your app running, simply pass the file reference to the original instance before closing.
Note the callback is made using an IpcChannel rather than a TcpChannel. If a TcpChannel is specified, Vista and Windows 7 will require permission from the user to allow communication through the firewall.

Here is the code:
// Single instance checked
bool IsFirstInstance;
Mutex theMutex =
new Mutex(false, "Local\\" + Application.ProductName, out IsFirstInstance);
string[] theActivationData =
AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData;
if (IsFirstInstance)
{
IpcChannel theChannel =
new IpcChannel(Application.ProductName);
try
{
ChannelServices.RegisterChannel(theChannel, false);
RemotingServices.Marshal(this._MainView, "MainView");
this.MainView_Show();
this.ConsumeLaunchParameters(theActivationData);
Application.Run(this._AppContext);
}
catch (SocketException) { }
finally
{
ChannelServices.UnregisterChannel(theChannel);
}
}
else
{
if (null != theActivationData &&
theActivationData.Length > 0)
{
try
{
MainView theOriginalMainView =
(MainView)RemotingServices.Connect(
typeof(MainView),
"ipc://" + Application.ProductName + "/MainView");
theOriginalMainView.ConsumeArguments(theActivationData);
}
catch (SocketException) { }
}
}
theMutex.Close();
Application.Exit();
Since my app uses a centralised controller system, I had to add the following code to the MainView form to pass the arguments back to the controller:
public void ConsumeArguments(
string[] theArguments)
{
// Note that it is not allowed for non-UI thread to access
// controls on the form, instead, we should use the Invoke method of the form
// to execute a delegate on the UI thread that own's the control's underlying
// windows handle.
if (this.InvokeRequired)
{
this.Invoke(
new MethodCallback(ConsumeArguments),
new object[]
{ theArguments });
return;
}
else
{
if (null != this.ArgumentsConsumed)
{
this.ArgumentsConsumed(theArguments);
}
}
}
public event MethodCallback ArgumentsConsumed;
public delegate void MethodCallback(string[] args);
Tags: C#, Computing, Interests, Personal, Projects
August 2nd, 2010
Up ’til now, when I’ve been developing and ClickOnce application, I’ve had to include a UACLauncher as a default option to support any user that is not the administrator on their own machine.

The console app has elevated privileges that are passed on to the re-launched ClickOnce app.
If I didn’t include this, the application would fail with (what I assumed was the first of many permissions errors) a registry access error. I decided to remove the UACLauncher and debug each error as it occurred. All my ClickOnce applications that require registry access to store settings store them in the LocalMachine hive. After googling the registry permission error, the main suggestion that came back was to move the settings to the CurrentUser hive.
Fair enough, but upon publishing the new version, there were no more errors. It seems that the only thing the app was doing that required administrator-level access was to attempt to write to the LocalMachine hive of the registry.
Tags: C#, Computing, Interests, Personal, Projects