Showing posts from September, 2009

Asp.NET redirect

Response.Redirect( "" )

Umbraco C# Open Source CMS Installation

Install IIS on your windows machine if it’s not there yet   Control Panel Add or Remove Programs Add/Remove Windows Components (on the left) Install SQL Server Express Edition Make the following changes after the installation SQL Server Configuration Manager Go to SQL Native Client Configuration/Client Protocols and Enable TCP/IP & Named Pipes SQL Server Surface Area Configuration Go to Surface Configuration for Services and Connections/Database Engine/Remove Connections and set remote connections to TCP/IP and Named Pipes SQL Server Management Studio Right click on top node (database name) and go to Properties/Security and set Server Authentication to SQL Server and Windows Authentication mode (mixed mode) Enable sa account (temporarily, only for Umbraco installation). Go to Security/Logins, right click on sa account choose Properties. On Genera

Open command line from context menu

This is the x64 version of Open Command Windows Here from PowerToys for Windows XP Create .reg file with this script and execute it. Windows Registry Editor Version 5 . 00 [HKEY_LOCAL_MACHINE \S OFTWARE\Classes\Folder \s hell\Command Prompt] @="Open Command Window Here" [HKEY_LOCAL_MACHINE \S OFTWARE\Classes\Folder \s hell\Command Prompt\command] @="Cmd . exe /k pushd %L"

Open cygwin command line from context menu

This script will add extra option to context menu to open cygwin command line. Create .reg file with this script and execute it. Windows x86 REGEDIT4 [HKEY_CLASSES_ROOT \D irectory \s hell \B ashHere] @="&Open Cygwin Window Here" [HKEY_CLASSES_ROOT \D irectory \s hell \B ashHere\command] @="c:\\cygwin\ \b in\ \b ash . exe --login -c \"cd '%1' ; exec /bin/bash -rcfile ~/ . bashrc\"" [HKEY_CLASSES_ROOT \D rive \s hell \B ashHere] @="&Open Cygwin Window Here" [HKEY_CLASSES_ROOT \D rive \s hell \B ashHere\command] @="c:\\cygwin\ \b in\ \b ash . exe --login -c \"cd '%1' ; exec /bin/bash -rcfile ~/ . bashrc\"" Windows x64 Windows Registry Editor Version 5 . 00 [HKEY_LOCAL_MACHINE \S OFTWARE\Classes\Folder \s hell \B ashHere] @="&Open Cygwin Window Here" [HKEY_LOCAL_MACHINE \S OFTWARE\Classes\Folder \s hell \B ashHere\command] @="c:\ \D evelopment\\tools\\Cygwin\ \b in\ \b

SQL Server Copy Table

This SQL will create another table from the select statement SELECT * INTO table2 FROM table1

C# LoopFileSystemWatcher

This is another implementation of FileSystemWatcher as FileSystemWatcher doesn’t work in all cases. public class LoopFileSystemWatcher { public delegate void LoopFileSystemEventHandler( object source, LoopFileSystemEvent e); public event LoopFileSystemEventHandler created; readonly List<string> fileCache = new List<string>(); private readonly string folderPath; private readonly string fileFilter; private readonly int checkFrequency; private bool cancelled = false ; public LoopFileSystemWatcher(string folderPath, string fileFilter, int checkFrequency) { this.folderPath = folderPath; this.fileFilter = fileFilter; this.checkFrequency = checkFrequency; DirectoryInfo dir = new DirectoryInfo(folderPath); foreach (FileInfo file in dir.GetFiles(fileFilter)) { fileCache. Add ( file .Name); } } public void Wait( int waitSeconds) { Thread t = n

C# Pub/Sub example

public class PubSub { readonly Queue<string> queue = new Queue<string>(); object locker = new object (); public string Subscribe() { string text; lock (locker) { while (queue. Count == 0) { Monitor.Wait(locker); } text = queue.Dequeue(); } return text; } public void Publish(string request) { lock (locker) { queue.Enqueue(request); Monitor.PulseAll(locker); } } } class Program { Random r = new Random(); public Program() { PubSub pubSub = new PubSub(); Thread t1 = new Thread(delegate() { Publish(pubSub); }); Thread t2 = new Thread(delegate() { Subscribe(pubSub); }); t1. Start (); t2. Start (); t1. Join (); t2. Join (); Console.WriteLine("Completed."); Console