This is so annoying! You go to use telnet on Windows 7, via the command prompt, and you get 'telnet' is not recognized as an internal or external command. There are loads of articles on how to enable telnet on Windows 7 (here's one of many!).
But after having enabled it in programs and features, I was still getting the not recognised error. I checked that I had the telnet.exe file in the C:\Windows\System32 and I did. So I double clicked it and sure enough it pops up and works.
The only other difference is that I need to remember to use the o command to open a connection:
Telnet> o my_domain
SyntaxHighlighter
Friday, 18 May 2012
Tuesday, 15 May 2012
Configure IIS7 for Custom Error Pages
I've recently (and finally!) moved to Windows 7 and with it IIS 7. I got PHP installed (using FastCGI) all fine, but was having major issues getting my custom 404 handlers to work with PHP. I found loads of articles all over the web that directed me in the right direction. But no one single article worked for me so this is what worked for me...
All the following settings can be done via the IIS Manager (Control Panel > Administrative Tools), but for me, I created the following Web.config file and put that in the root of the site that I wanted the 404 handler to be working on.
Note the use of errorMode="Custom" and existingResponse="Replace". Hope this works out for you :)
All the following settings can be done via the IIS Manager (Control Panel > Administrative Tools), but for me, I created the following Web.config file and put that in the root of the site that I wanted the 404 handler to be working on.
Note the use of errorMode="Custom" and existingResponse="Replace". Hope this works out for you :)
Test an IMAP Connection (Telnet)
Following on from post about how to test a POP3 connection using telnet, I thought I'd add a quick one about testing an IMAP connection. It's pretty much the same, but you use the 143 port number instead:
> telnet mail.mydomain.com 143
> login my_user_name my_password
Happy days :)
Update:
Recently I started getting an error when using the login command. Turns out I needed to do the following:
> 10 login my_user_name my_password
All subsequent commands needed to use 20, 30, etc. This is a good resource for more commands.
> telnet mail.mydomain.com 143
> login my_user_name my_password
Happy days :)
Update:
Recently I started getting an error when using the login command. Turns out I needed to do the following:
> 10 login my_user_name my_password
All subsequent commands needed to use 20, 30, etc. This is a good resource for more commands.
Friday, 20 April 2012
How To MD5 in SQL Server / MSSQL
If you need to MD5 a string in MSSQL then use the HASHBYTES function. You can also use other formats too, such as SHA and SHA1. It's as simple as:
PRINT HASHBYTES('MD5', 'MY_STRING')
If you want to return back a string rather than the varbinary HASHBYTES does return, then try the following:
PRINT SUBSTRING(master.dbo.fn_varbintohexstr( HASHBYTES ('MD5', ' MY_STRING ')), 3, 32)
PRINT HASHBYTES('MD5', 'MY_STRING')
If you want to return back a string rather than the varbinary HASHBYTES does return, then try the following:
PRINT SUBSTRING(master.dbo.fn_varbintohexstr( HASHBYTES ('MD5', ' MY_STRING ')), 3, 32)
Tuesday, 17 April 2012
.NET Round Date to Nearest Hour
A quick little snippet here for those needing to round a DateTime in VB.NET or C# to the nearest hour
VB.NET
C#
VB.NET
Public Shared Function RoundedHour(ByVal dt As DateTime) As DateTime
Return DateTime.Parse( _
String.Format("{0:yyyy-MM-dd HH:00:00}", _
IIf(dt.Minute > 30, dt.AddHours(1), dt) _
)
End Function
C#
public static DateTime RoundedHour(ByVal dt As DateTime) {
Return DateTime.Parse(
String.Format("{0:yyyy-MM-dd HH:00:00}",
(dt.Minute > 30 ? dt.AddHours(1) : dt)
)
}
It's pretty straight forward. If the minutes of the time are over 30 then add an hour. If not, keep using the given date. Format the date to have the minutes and seconds set to 0 and parse it back as a date.
Thursday, 5 April 2012
How To Remember Password in Mercurial TortoiseHg
I've just started using BitBucket as a remote repository for code sharing and how sweet it is too :) I decided to use Mercurial as the repository type and using TortoiseHg with it. A frustration I was having with it, was each time I did a commit or update I was getting prompted to enter my password - grrr!
I tried adding an [auth] entry to to the ini file, but that didn't work. I then came across this little 3 click gem:
I tried adding an [auth] entry to to the ini file, but that didn't work. I then came across this little 3 click gem:
And now it works a treat!
Monday, 19 March 2012
How To Dial a Phone Number From a Webpage on an iPhone or Android Device
I always find it a ball ache when I am on a mobile device, see a telephone number on a webpage but it's not clickable to automatically dial the number for me. So if you need to do this on your websites, set up the anchor element as such:
<a href="tel:01234 567 8910">01234 567 8910</a>
Jobs dones! Nice and simple :)
<a href="tel:01234 567 8910">01234 567 8910</a>
Jobs dones! Nice and simple :)
Friday, 9 March 2012
How To Call PHP From a Cron in Plesk
Like a lot of people I needed to run a PHP script from a cron (crontab) via the Plesk server admin tool. Simply putting the path to the file (from root) does not run it. The way to do this is by calling the php processor with some parameters. So do the following:
php -q /var/www/vhosts/mywebsite.com/httpdocs/cron/my-file.php
Obviously use the path that relates to your file.
This seems to work for a lot of people, but as my script had includes in it I was getting failure to open stream errors when it was called. So to get round this, I changed the directory prior to the call. So it now looks like this:
cd /var/www/vhosts/ mywebsite.com /httpdocs/cron; php -q my-file .php
Hey presto, it all works a treat now!
You may need to set permissions on the script to be executed. By default, the task will email the output of the script to you (click the Settings option on the Scheduled Tasks page to change the address - see image below). This can be turned off by adding 2>&1 to the end of the command. making the it look like this:
cd /var/www/vhosts/ mywebsite.com /httpdocs/cron; php -q my-file .php /dev/null 2>&1
Credit to http://daipratt.co.uk/crontab-plesk-php/ and http://stackoverflow.com/questions/3140675/php-cron-job-including-file-not-working for helping to work this mess out ;)
php -q /var/www/vhosts/mywebsite.com/httpdocs/cron/my-file.php
Obviously use the path that relates to your file.
This seems to work for a lot of people, but as my script had includes in it I was getting failure to open stream errors when it was called. So to get round this, I changed the directory prior to the call. So it now looks like this:
cd /var/www/vhosts/ mywebsite.com /httpdocs/cron; php -q my-file .php
Hey presto, it all works a treat now!
You may need to set permissions on the script to be executed. By default, the task will email the output of the script to you (click the Settings option on the Scheduled Tasks page to change the address - see image below). This can be turned off by adding 2>&1 to the end of the command. making the it look like this:
cd /var/www/vhosts/ mywebsite.com /httpdocs/cron; php -q my-file .php /dev/null 2>&1
Credit to http://daipratt.co.uk/crontab-plesk-php/ and http://stackoverflow.com/questions/3140675/php-cron-job-including-file-not-working for helping to work this mess out ;)
Friday, 2 March 2012
PHP: Last Modified Date of Folder / Directory
It turns out it's really easy to get the the last modified date of a folder/directory using PHP. You use the filemtime() function. It returns a timestamp for us so we would do something like:
$lastModifed = filemtime($dir);
print "Last modified on ".date("Y-m-d H:i:s", $lastModifed );
Monday, 6 February 2012
Reduce Used Space on Android
I have an android HTC Desire and am constantly running out of space on it - boo! A funky trick I recently came across, via a friend, was to un-install the Google Maps app. Then go back to the market and install it again. It seems that the Maps app keeps a copy of itself on the device each time an update occurs. I can't be sure about this, but I had a whole load of space free up after the re-install.
Obviously in the first instance, make sure your have used the "Clear Data" feature on all appropriate apps. Some apps store loads of data that you may not really want.
Another funky little app I came across was Phone Space Saver. A simple little app that tells you which apps you can move to the SD card - and free :)
Obviously in the first instance, make sure your have used the "Clear Data" feature on all appropriate apps. Some apps store loads of data that you may not really want.
Another funky little app I came across was Phone Space Saver. A simple little app that tells you which apps you can move to the SD card - and free :)
Monday, 23 January 2012
How to Play MP4 Files on Your Xbox 360
I recently purchased a GoPro HD2 and what a fine piece of equipment it is too! The GoPro records the video in MP4 format and by default the Xbox 360 won't play this format (even though it claims it does).
Anyway...
After numerous fails to convert the files to AVI (a format that is supported), it turns out all you need to do is change the file extension from MP4 to AVI. Hey presto, it shows up on the Xbox now!
Anyway...
After numerous fails to convert the files to AVI (a format that is supported), it turns out all you need to do is change the file extension from MP4 to AVI. Hey presto, it shows up on the Xbox now!
File Transfers with Android - FTPDroid
After coming back from a great snowboarding holiday in Les Deux Alpes, I had loads of photos and videos that I needed to move from my Android tablet to my home PC.
I present to you FTPDroid.
It's a cracking little app that turns your android device into an FTP server. You connect your FTP client to it and off you go. It works a treat when you have large numbers of files to transfer and you don't have time to sit there while they move across your network.
I present to you FTPDroid.
Wednesday, 14 December 2011
PHP header 200 Status Not Being Sent
I'm having a real mare with this PHP site I am working at the moment. Having constant configuration problems - grrr!
I am using a .htaccess file to handle the a 404 (ErrorDocument 404 /404.php). It's used to handle friendly URLs mainly. One of the other things I use it for is allowing JavaScript files to be PHP processed before they are served to the browser. This is dead useful as I can modify and customise the scripts where required.
Anyway...
In the code I use header("HTTP/1.1 200 OK") and in nearly all instances that works fine. Except for when it is processing the the JavaScript files. After massive annoyance and trying loads of different things, it turns out there is a bug in PHP 5. As they suggest at the bottom, the workaround is:
header("Status: 200 OK");
Fixed!
I am using a .htaccess file to handle the a 404 (ErrorDocument 404 /404.php). It's used to handle friendly URLs mainly. One of the other things I use it for is allowing JavaScript files to be PHP processed before they are served to the browser. This is dead useful as I can modify and customise the scripts where required.
Anyway...
In the code I use header("HTTP/1.1 200 OK") and in nearly all instances that works fine. Except for when it is processing the the JavaScript files. After massive annoyance and trying loads of different things, it turns out there is a bug in PHP 5. As they suggest at the bottom, the workaround is:
header("Status: 200 OK");
Fixed!
Tuesday, 8 November 2011
Add a Border to a Panel Using .NET Compact Framework
After spending quite some time working out how to add a border round a panel control in the .NET compact framework, I finally got it working. It's pretty easy to be honest.
VB.NET
C#
You need to make sure that this code is put in the Paint event of your panel.
VB.NET
Using g As Graphics = e.Graphics
Using p As New Pen(Color.Black, 1)
g.DrawRectangle(p, 0, 0, MyPanel.Width - 1, MyPanel.Height)
End Using
End Using
C#
Using (Graphics g = e.Graphics) {
Using (Pen p = New Pen(Color.Black, 1)) {
g.DrawRectangle(p, 0, 0, MyPanel.Width - 1, MyPanel.Height);
}
}
You need to make sure that this code is put in the Paint event of your panel.
Monday, 31 October 2011
HSBC API: PayerTxnId is not in a valid base64 encoding
That pesky HSBC API caused me a lot of grief when I first had to set it up on a client site. For various reasons I ended up using the XML method of performing the transaction.
Anyway...
Having recently implemented the 3D secure (Payer Authentication Specification (PAS)) I was getting a PayerTxnId 'LOADS_OF CHARS' is not in a valid base64 encoding. The PayerTxnId is pulled from the posted data from HSBC. It comes from the XID field.
It took me a while to spot it and, to be honest, I thought I would have to contact HSBC technical support yet again (who , by the by, are very good). But I did spot it! There was a space in the string. I swapped that out for a + and hey presto, the HSBC API processed it just fine.
Anyway...
Having recently implemented the 3D secure (Payer Authentication Specification (PAS)) I was getting a PayerTxnId 'LOADS_OF CHARS' is not in a valid base64 encoding. The PayerTxnId is pulled from the posted data from HSBC. It comes from the XID field.
It took me a while to spot it and, to be honest, I thought I would have to contact HSBC technical support yet again (who , by the by, are very good). But I did spot it! There was a space in the string. I swapped that out for a + and hey presto, the HSBC API processed it just fine.
Wednesday, 19 October 2011
Block IP Addresses on Windows Server 2003
A big thank you goes out to CodeHill today for allowing me to find out how to easily block IP addresses with built-in Windows server functionality.
The idea is that you create an IP Security Policy on the server and add each IP, range or subnet to it. Perfect :)
The idea is that you create an IP Security Policy on the server and add each IP, range or subnet to it. Perfect :)
Tuesday, 18 October 2011
Unicode Characters in an Email Subject using PHP and PEAR
I've been working on a PHP site recently where I have had to cater for all languages and more importantly Unicode languages.
So after quite a lot of messing about and hunting around I found that I needed to do the following with the subject:
Obviously if you know if the mb_* functions are available, then you can do away with the if statements.
This works using the PEAR Mail_Mime library. I haven't tested it with the built-in PHP mail function. I would assume it does not work.
So after quite a lot of messing about and hunting around I found that I needed to do the following with the subject:
if (function_exists("mb_internal_encoding"))
mb_internal_encoding("UTF-8");
if (function_exists("mb_encode_mimeheader"))
$subject = mb_encode_mimeheader($subject, "UTF-8", "B", "\n");
Obviously if you know if the mb_* functions are available, then you can do away with the if statements.
This works using the PEAR Mail_Mime library. I haven't tested it with the built-in PHP mail function. I would assume it does not work.
Tuesday, 4 October 2011
How To Reset an Identity Column in MSSQL / SQL Server
Something I often find myself needing to do is reset the identity column on auto incrementing field in MS SQL / SQL Server.
There are a couple of ways of doing it:
There are a couple of ways of doing it:
- If you are emptying the table, instead of using a DELETE, use a TRUNCATE. That will automatically reset the identity.
- The ID can be set to a specific number by using DBCC CHECKIDENT([TABLE_NAME], RESEED, n). Where n is the number that is to be set.
DBCC CHECKIDENT([TABLE_NAME], RESEED, 0) DBCC CHECKIDENT([TABLE_NAME], RESEED)
Monday, 19 September 2011
Android: Starts in Car Mode
When I turn on my HTC Desire android phone, the device is automatically in car mode. I get a notification item allowing me turn it off, so that does the job. But I couldn't find any way of stopping it starting automatically.
Now if like me, you couldn't find the "dock" app (that seems to be mentioned all over the Internet) anywhere you need to do following:
Now if like me, you couldn't find the "dock" app (that seems to be mentioned all over the Internet) anywhere you need to do following:
- From the home screen: Menu > Settings > Search > Searchable Items
- Make sure the Settings options is checked
- Press the physical search key (usually a magnifying glass)
- Click the Google logo and choose Settings
- Type car
- Choose Dock
- Make sure the Auto-launch option is un-checked
Hey presto!
Android version: 2.2
Thursday, 1 September 2011
Compressing JPG/JPEG Images
If you need to compress and reduce the disk footprint and reduce bandwidth use, then check out JPEGmini. They are managing a 5 times reduction in the size of images!
Subscribe to:
Posts (Atom)
Labels
.net
(7)
ajax
(1)
android
(7)
apache
(1)
asp.net
(3)
asus
(2)
blogger
(2)
blogspot
(3)
c#
(16)
compact framework
(2)
cron
(1)
css
(1)
data
(1)
data recovery
(2)
dns
(1)
eclipse
(1)
encryption
(1)
excel
(1)
font
(1)
ftp
(1)
gmail
(5)
google
(4)
gopro
(1)
html
(1)
iis
(3)
internet explorer IE
(1)
iphone
(1)
javascript
(3)
kinect
(1)
linux
(1)
macro
(1)
mail
(9)
mercurial
(1)
microsoft
(3)
microsoft office
(3)
monitoring
(1)
mootools
(1)
ms access
(1)
mssql
(13)
mysql
(2)
open source
(1)
openvpn
(1)
pear
(2)
permissions
(1)
php
(12)
plesk
(4)
proxy
(1)
qr codes
(1)
rant
(4)
reflection
(3)
regex
(1)
replication
(1)
reporting services
(5)
security
(2)
signalr
(1)
sql
(11)
sqlce
(1)
sqlexpress
(1)
ssis
(1)
ssl
(1)
stuff
(1)
svn
(2)
syntax
(1)
tablet
(2)
telnet
(3)
tools
(1)
twitter
(1)
unix
(3)
vb script
(3)
vb.net
(9)
vba
(1)
visual studio
(2)
vpc
(2)
vpn
(1)
windows
(4)
woff
(1)
xbox 360
(1)




