Archive for the Category: Programming

Oracle Insert Date

A simple SQL example of using the To_Date function to format a date. INSERT INTO EXAMPLETBL (EXAMPLEID, EXAMPLEDATE) VALUES (‘5’, TO_DATE(‘2014-05-08 08:06:24’, ‘YYYY-MM-DD HH24:MI:SS’))

Also posted in Oracle Tagged , , , Leave a comment

Backup Oracle database with Windows Batch Script

This simple batch script creates a new folder based on the date and time and then executes a oracle database dump. REM Backup oracle database @echo Starting database backup REM get the current datestamp in the format year-month-day-hour-minute SET DATESTAMP=%date:~6,4%-%date:~3,2%-%date:~0,2%-%time:~0,2%-%time:~3,2% REM Create a new directory md “c:\backup\%DATESTAMP%” REM backup database REM Dont forget to change […]

Also posted in Command Scripts Leave a comment

Split a name into First name and Last name using PHP

/** split a name into the first name and last name * @param input The name eg ‘John Doe’ * @return Array containing firstname and lastname eg array(‘firstname’=>’John’, ‘lastname’=>’Doe’); */ function splitname($input) { $output = array(“firstname”=>””, “lastname”=>””); $space = strpos($input, ” “); if ($space !== false) { $output[‘firstname’] = substr($input, 0, $space); $output[‘lastname’] = substr($input, […]

Also posted in PHP 1 Comment

Convert a url data in to Name Value Pairs array PHP

Convert a url data in to Name Value Pairs array. /** Convert a url data in to Name Value Pairs array * @param url The url and the data string * @return array of named value pairs */ function urlToNvp($url) { $output = array(); $questionmark = strpos($url, ‘?’); if ($questionmark !== false) { $url = […]

Also posted in PHP Leave a comment

Using OpenCV inside a C# WPF application

In this example I will create a C++ dll that with contain the OpenCV image processing code. I then will create a C# WPF application, within this application i will then include the dll and using the image processing function. Install OpenCV http://docs.opencv.org/doc/tutorials/introduction/windows_install/windows_install.html#windows-installation Create a C++ Win32 console Application, in this example it will be […]

Also posted in C#, Digital Image Processing 1 Comment

Simple Write File using C#

A very simple method for writing to a file, not forget to include using System.IO;. string filename = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @”\test.txt”; string content = “This is the new file content”; File.WriteAllText(filename, content);

Also posted in C# Leave a comment

Data Validation and Exceptions in C#

The setName funcion demostrates simple data validation on the argument value. void setName(string value) { // validate empty if (string.IsNullOrWhiteSpace(value)) { throw new ArgumentNullException(“Please enter a value”); } // validate length if (value.Length > 10) { throw new ArgumentException(“The value is too long”); } // value is valid MessageBox.Show(“The value is valid”); } When calling […]

Also posted in C# Leave a comment

C# type checking with the is statement

A var type can be checked using the ‘is’ statement var a = 1.0; if (a is int) { MessageBox.Show(“int”); } else { MessageBox.Show(“is NOT int”); }

Also posted in C# Leave a comment

C# class properties

The code below shows the short hand and long hand syntax for defining class properties. public class Example { // class property short hand public string Firstname {get; set;} // class property long hand private string _Lastname; public string Lastame { get {return _Lastname} set {_Lastname = value} } }

Also posted in C# Leave a comment

Simple C# LINQ example

The LINQ example below creates a generic collection of the class Car. Then using a LINQ statement the collection is filtered to find cars that are newer than 2009. List myCars = new List() { new Car() { Make=”BMW”, Model=”550i”, Year=2009 }, new Car() { Make=”Toyota”, Model=”4Runner”, Year=2010 }, new Car() { Make=”BMW”, Model=”745li”, Year=2008 […]

Also posted in C# Leave a comment