Posts

Showing posts from September, 2009

Asp.NET redirect

Response.Redirect("http://www.microsoft.com")

Umbraco C# Open Source CMS Installation

Install IIS on your windows machine if it’s not there yetControl Panel
Add or Remove Programs
Add/Remove Windows Components (on the left)Install SQL Server Express EditionMake the following changes after the installationSQL 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 General Page set password (if not set yet) and on Status Page set Login to Enabled. Install XP PRO IIS AdminAllows to…

Open command line from context menu

This is the x64 version of Open Command Windows Here from PowerToys for Windows XPCreate .reg file with this script and execute it.Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Folder\shell\Command Prompt] @="Open Command Window Here" [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Folder\shell\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\Directory\shell\BashHere]
@="&Open Cygwin Window Here"

[HKEY_CLASSES_ROOT\Directory\shell\BashHere\command]
@="c:\\cygwin\\bin\\bash.exe --login -c \"cd '%1' ; exec /bin/bash -rcfile ~/.bashrc\""

[HKEY_CLASSES_ROOT\Drive\shell\BashHere]
@="&Open Cygwin Window Here"

[HKEY_CLASSES_ROOT\Drive\shell\BashHere\command]
@="c:\\cygwin\\bin\\bash.exe --login -c \"cd '%1' ; exec /bin/bash -rcfile ~/.bashrc\"" Windows x64 Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Folder\shell\BashHere]
@="&Open Cygwin Window Here"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Folder\shell\BashHere\command]
@="c:\\Development\\tools\\Cygwin\\bin\\bash.exe --login -c \"cd '%1' ; exec /bin/bash -rcfile ~/.bashrc\"&q…

SQL Server Copy Table

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

C# LoopFileSystemWatcher

This is another implementation of FileSystemWatcher as FileSystemWatcher doesn’t work in all cases.publicclass 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 filein dir.GetFiles(fileFilter))
{
fileCache.Add(file.Name);
}
}

public void Wait(int waitSeconds)
{
Thread t = new Thread(delegate() { WaitThread(waitSeconds,false); });
t…

C# Pub/Sub example

publicclass PubSub
{
readonly Queue<string> queue = new Queue<string>();

object locker = newobject();

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.ReadLine();
}

void Publish(PubSub pubSub)
{
for (int i = 1; i <= 10; i++)
{