Archive for 'Coding'

Rotating URL Script – Dashboard Display

Iv been looking for a tool that will display web pages for a period of time and then cycle through to the next page,  performing a loop for usage on large LCD TV screen at work,  this is to be used to display IT Service performance information and status reports.

I was unable to find one that did what I wanted,  bar 1, although it suffered from a problem where after a few hours Internet Explorer would start to die, and it had to be restarted.

I decided to write my own script, and so here it is.
Read more

T-SQL Setting Date Format

Occasionally you need to run a DATEDIFF or DATEADD against some dates that are in a reverse format, ie Day:Month:Year instead of Month:Day:Year, theres a simple way to set this in your query without having to string handle it all, using the SET DATEFORMAT parameter.

1
2
SET DATEFORMAT dmy
SELECT DATEDIFF(MINUTE,'29-01-2010 09:13:18','29-01-2010 09:18:18')

Copy your servers PHP.INI

Occasionally you may need to override your hosts or servers PHP.INI config file.  If you do, you’ll want a copy of the original PHP.INI as a basis for your modifications.
You can make a copy of it to your new directory by running a PHP script with the following

1
< ?php system("cp /usr/local/php5/lib/php.ini /home/your-new-path/php.ini"); ?>

Ping Host From VB.Net

1
2
3
4
5
6
7
8
9
10
11
12
13
14
' --- ping the ip adress in the string s_ipaddr, and get
'     the response time in the int32 n_response

 
Imports system.net.networkinformation
Dim ping As New System.Net.NetworkInformation.Ping
Dim reply As System.Net.NetworkInformation.PingReply
reply = ping.Send(s_ipaddr)
If reply.Status = IPStatus.Success Then
' --- handle reachable here
MsgBox("ping time " &amp; reply.RoundtripTime)
Else
' --- handle non reachable here
End If

Pinger! – The Mass Host Ping Tool

Current Version v1.3 – Download Now

Pinger! is a tiny ping utility (13KB) that is used to quickly ping a large list of hosts and save the resulting successful and failure host lists into a text file.

Why?

When developing scripts and applications that will touch a large number of hosts,  if many of those hosts are offline or no longer exist, the timeouts involved with this can slow down execution time and dramatically slow down your script or application.

In my case, I was presented with a list of 600+ servers that needed to have the exact same script run against them, a successful server took only several milliseconds to finish,  a failed host took around 4 seconds to time out, clearly I needed to find out which servers were alive and which weren’t and further again I needed to list the successful servers in a clean text file, 1 host per line, so I could import this into my application as an array.

And hence Pinger! was born :)

Usage

Very simple, Pinger.exe when run looks for hosts.txt in the same directory. Simply enter in your list of host names in this text file,  one per line and Pinger! will run over them 1 by 1 and output the results.
Simply extract the .zip containing Pinger.exe and hosts.txt to the same directory and open Pinger.exe.

Output

2 files are outputted.  these are:

  • success.txt  – The list of successfully pinged hosts, in per line format
  • failure.txt – The list of hosts that failed to ping, in line by line format.
pinger

 

Download v1.0

T-SQL Copy Table To Another Database

Occasionally, you might do something stupid like run a SQL script on the wrong database, or setup your application to configure its table structure on the master DB.

When you do, here’s an easy way to copy the tables to another database (on the same server)

1
2
SELECT * INTO target_db.target_table_name
FROM source_db.source_table_name

SQL Replace Nulls With Blank String

Simple way to replace NULL values in your queries with blank strings by using the IsNull function.

This will allow for problem free string creation etc.

1
2
3
SELECT IsNull(ColumnName, '') 
As NewColumnName 
FROM TableName

More information can be found here: http://msdn.microsoft.com/en-us/library/ms184325.aspx

VBScript To Pull Events From Event Log And Email To Yourself – Past 24 Hours

So, you want to see what events have occured on a server in the past 24 hours. Maybe you have a problematic server, throwing errors but your event log is so massive , its hard to sort through.

This script will sift through your entire event log, searching for any events in the past 24 hours that match your event code, it will save the results to a .TXT file , and then email them to you. v.handy


Read more

VB.Net Forms Confirmation Box

How to create a simple confirmation box in a VB.Net WinForms application.    This will pop up a typical “Do You Wish To Continue ? ” Box , to which each button has a different action.


Read more

Kill All Processes Of Certain Application In Unix/Linux

This is a very helpful command I use regularly.

If your like me, you open several instances of applications like “VI” and leave them in the background, most of the time without meaning to.  Eventually you run a “PS -U” to view all your processes running and realize that theres 10 copies of the application running in the background which you havnt closed. Heres a command to quickly clear that up.
Read more