Regular Expressions Cheat Sheet
Created 08 April 2003 00:00
<

A less than at the start of the string matches the start of a line.

% A percent sign at the start of the string matches the start of a line.
^ A circumflex at the start of the string matches the start of a line.
. A period matches any character.
* An asterisk after a string matches any number of occurrences of that string followed by any characters, including zero characters. For example, bo* matches bot, bo and boo but not b.
$ A dollar sign at the end of the expression matches the end of a line.
> A greater than at the end of the expression matches the end of a line.
? A question mark matches any single character.
@ An at sign after a string matches any number of occurrences of that string followed by any characters, including zero characters. For example, bo@ matches bot, boo, and bo.
+ A plus sign after a string matches any number of occurrences of that string followed by any characters, except zero characters. For example, bo+ matches bot and boo, but not b or bo.
| A vertical bar matches either expression on either side of the vertical bar. For example, bar|car will match either bar or car. ~ A tilde matches any single character that is not a member of a set.
[ ] Characters in brackets match any one character that appears in the brackets, but no others. For example [bot] matches b, o, or t.
[^] A circumflex at the start of the string in brackets means NOT. Hence, [^bot] matches any characters except b, o, or t. [-] A hyphen within the brackets signifies a range of characters. For example, [b-o] matches any character from b through o.
[-] A hyphen within the brackets signifies a range of characters. For example, [b-o] matches any character from b through o.
{ } Braces group characters or expressions. Groups can be nested, with a maximum number of 10 groups in a single pattern. . For the Replace operation, the groups are referred to by a backslash and a number according to the position in the ?Text to find? expression, beginning with 0. For example, given the text to find and replacement strings, Find: {[0-9]}{[a-c]*}, Replace: NUM1, the string 3abcabc is changed to NUMabcabc.
A backslash before a wildcard character tells the IDE to treat that character literally, not as a wildcard. For example, ^ matches ^ an d does not look for the start of a line.
VB6 : Associating file extensions with your app
Created 08 April 2003 00:00
  string keyName = "MyApp";
  string keyValue = "My Application";
  RegistryKey key = null;

  key = Registry.ClassesRoot.CreateSubKey(keyName);
  key.SetValue("",keyValue);
  key = key.CreateSubKey("shell");
  key = key.CreateSubKey("open");
  key = key.CreateSubKey("command");
  key.SetValue("","c:tempmy.exe %1");
            
  keyName = ".bar";	// file association you want
  keyValue = "MyApp";	// must correspond to above!!
  key = Registry.ClassesRoot.CreateSubKey(keyName);
  key.SetValue("", keyValue);
Linux : Scripting automatic file transfers via FTP
Created 08 April 2003 00:00
You can FTP in script files as a scheduled tasks by doing the following:

Create the shell file that will be run by the cron job:

  echo "FTP process commencing"
  su <youruser> -c "ftp 192.1.2.2 < /home/youruser/prodftp.txt"
  echo "FTP process completed"
In the above file, the user must be a user that has been setup to automatically log into the FTP service on the remote machine 192.1.2.3 (see FTP: Automatic login under the Operating Systems/Linux category).

The text file /home/youruser/prodftp.txt will contain the actual FTP information, for example:

  cd backups
  ls
  binary
  prompt
  mdelete *.dmp
  ls
  mput *.dmp
  ls
  close
  exit
The prompt command is very important - it turns off the interactive prompting for moving multiple files.
C# : Capturing process output
Created 08 April 2003 00:00
By running external commands using the System.Diagnostics.Process class, you can also retrieve the output from that command by using it's StandardOutput property:

  Process p = new Process();
  StreamReader sr = null;
  ProcessStartInfo psi = new ProcessStartInfo("D:\Matt\test.bat");
  psi.UseShellExecute = false;
  psi.RedirectStandardOutput = true;
  psi.CreateNoWindow = true;
  p.StartInfo = psi;
  p.Start();
  sr = p.StandardOutput;
  string line = null;
  while ((line = sr.ReadLine()) != null) {
    Console.WriteLine(line);
  }
PHP dynamic file downloads
Created 03 April 2003 00:00
The following forces the user's browser to open a save dialog for the file:
  header("Content-type: application/pdf");
  header("Content-Disposition: inline; filename=downloaded.pdf");
C# Windows API Calls
Created 30 April 2003 00:00

If, for example you want to send a message to you window to bring it to the top of the z-order, add the following code into your class declaration, e.g.:

  public class MyClass {

    private bool x = false;

   [DllImport("user32.dll",EntryPoint="BringWindowToTop")]
   private static extern int BringWindowToTop(int hWnd);

The EntryPoint is not required - if omitted the entry point into the dll will be the name of the method.

To use the imported method, just call as normal, e.g.

  BringWindowToTop(MyForm.Handle.ToInt32());
Running command-line queries on a PostgreSQL database
Created 08 April 2003 00:00
To run command-line queries on a PostgreSQL database running on Linux, you need to locate the psql executable, connect to the database and run queries manually:
locate psql
(e.g. returns /usr/bin/psql)
/usr/bin/psql <database_name>
SELECT * FROM <table> LIMIT 200;
q (to quit)