Monthly Archives: September 2013

RewriteRule ASP.NET Tutorial

The RewriteRule in htaccess looks like this in C#

RewriteRule ^match-site-url$  redirect-to-this

Example

RewriteRule ^hammadk.com/\d*/\d$ /test.php?id=$1&id2=$2

This will match the following patterns

hammadk.com/1234/5678
and the page will be send to test.php that is sitting in the root directory. 1234 is the first match located by \d* and will be passed in the query string as test.php?id=1234.
1234 is followed by “/”. Since this is just static text (not a pattern) and thefefore will not be hold in any variable.
After this comes another integer, 5678. This will be catched by the second \d*. Since this is the second regex expression, it will be held in variable$2. This string is passed to the query in this form
id2=5678

The complete redirect, takes this form

^hammadk.com/1234/5678$ #pattern
/test.php?id=1234$id=5678

Get computer locale in C#

using System.Globalization;
using System.Threading;
CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture;
currentCulture.Name = “en-US”; /* contains country code */

List of Culture Code (Country Codes)

A list of culture codes can be found on this link. First two abbreciation (small) are for language, the second two letters (in CAPs) are for country. Example
fr-CA — Canadian French
en-CA — Canadian English

How to drag formula over thousand of empty rows with one click

If rows are empty, double click short cut on extend formula hand will not work. So what can you do? How can you resolve it?

The trick

Copy cells from left side column into the one that you want to update. There is likely that data exists in columns somewhere. Once data is there, you can use double click shortcut to extend the formula to all rows that you just copied.

Copy Cells Conditionally in Excel

How to copy cells conditionally in Excel? You have a huge list, you have highlighted them in colors (using some formula), you want to move over the IDs that are not highlighted. How can you do it?

There is really no copy method or function in Excel. One may say you can use VBA to copy cell over, but you can do that right in Excel, using some improvisation. Instead of spending effort on copying data, we are going to use IF formula in the column where you want to copy the cells. If it meets the criteria, it will be copied, if it did not, it will not be copied.

Example

Comming up

Example 2 – more complicated criteria

This example will copy cell overs to the new column if the ID in the original column does not exists in the column where you are looking at the IDs

Use the following formula in the cell where you want to copy the cell conditionally. Then drag this cell over the number of rows depending on how many rows of data you want to copy.

=IF(COUNTIF($E$3:$E$30195,A2492),,A2492)

How to open remote desktop on extended monitor – For Mac

Method 1

On remote desktop connection window, there is an option to open remote desktop on secondary screen.

Open Remote Desktop on second screen

Method 2

In preference, displays, in the middle tab, drag the white bar on top of one window to the other window. That way the other window will become your main screen. That means Remote Desktop will open in the window you want the menu to see.
Screen Shot 2013-09-11 at 9.43.31 PM

Quartz.net Working Example

I could not find a working example for Quarts.net. The examples at Quart.net site, does not compile. Found out they are build against Quartz.net version 1.0. The following is a working Quartz.net example that is built against Quartz.net 2.0 (Latest). What this job does is write a text message, “Hello Job is executed” in the console every 5 sec.

Tutorial

Start a Visual Studio 2012 project. Select Windows Console Application. Name it Quartz1 or what ever you like.

Requirements

Download Quartz.NET assembly using NUGET. Right click on project, select “Manage Nuget Packages”. Then search for Quart.NET. Once found select and install. Note that you have to have online connection for this.

Copy and past the following Code

How to delete Quartz.net job

Debug C# Application without running code

You can debug/test your code without running the application itself. There is a neat feature in Visual Studio (I am using VS 2012) where you can go to Debug menu -> Windows -> Immediate. In this window, you can type in the name of the function you want to execute and it will execute and return result. Pretty nice feature!

More on this link from Microsoft

Pubs database for SQL Server 2012 (slim down version)

The original pubs database is available for SQL Server 2000. It cannot be attached to SQL Server 2012. The following script produces a slim down version of the database. Esp it uses the Authors table only. It was needed in one of the Microsoft Example

Download Pubs database scrip slim version

create database Pubs
GO

use Pubs
GO

CREATE TABLE authors
(
au_id id

CHECK (au_id like ‘[0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9][0-9][0-9]’)

CONSTRAINT UPKCL_auidind PRIMARY KEY CLUSTERED,

au_lname varchar(40) NOT NULL,
au_fname varchar(20) NOT NULL,

phone char(12) NOT NULL

DEFAULT (‘UNKNOWN’),

address varchar(40) NULL,
city varchar(20) NULL,
state char(2) NULL,

zip char(5) NULL

CHECK (zip like ‘[0-9][0-9][0-9][0-9][0-9]’),

contract bit NOT NULL
)

GO

insert authors
values(‘409-56-7008’, ‘Bennet’, ‘Abraham’, ‘415 658-9932’,
‘6223 Bateman St.’, ‘Berkeley’, ‘CA’, ‘94705’, 1)
insert authors
values(‘213-46-8915’, ‘Green’, ‘Marjorie’, ‘415 986-7020’,
‘309 63rd St. #411’, ‘Oakland’, ‘CA’, ‘94618’, 1)
insert authors
values(‘238-95-7766’, ‘Carson’, ‘Cheryl’, ‘415 548-7723’,
‘589 Darwin Ln.’, ‘Berkeley’, ‘CA’, ‘94705’, 1)
insert authors
values(‘998-72-3567’, ‘Ringer’, ‘Albert’, ‘801 826-0752′,
’67 Seventh Av.’, ‘Salt Lake City’, ‘UT’, ‘84152’, 1)
insert authors
values(‘899-46-2035’, ‘Ringer’, ‘Anne’, ‘801 826-0752′,
’67 Seventh Av.’, ‘Salt Lake City’, ‘UT’, ‘84152’, 1)
insert authors
values(‘722-51-5454’, ‘DeFrance’, ‘Michel’, ‘219 547-9982’,
‘3 Balding Pl.’, ‘Gary’, ‘IN’, ‘46403’, 1)
insert authors
values(‘807-91-6654’, ‘Panteley’, ‘Sylvia’, ‘301 946-8853’,
‘1956 Arlington Pl.’, ‘Rockville’, ‘MD’, ‘20853’, 1)
insert authors
values(‘893-72-1158’, ‘McBadden’, ‘Heather’,
‘707 448-4982’, ‘301 Putnam’, ‘Vacaville’, ‘CA’, ‘95688’, 0)
insert authors
values(‘724-08-9931’, ‘Stringer’, ‘Dirk’, ‘415 843-2991’,
‘5420 Telegraph Av.’, ‘Oakland’, ‘CA’, ‘94609’, 0)
insert authors
values(‘274-80-9391’, ‘Straight’, ‘Dean’, ‘415 834-2919’,
‘5420 College Av.’, ‘Oakland’, ‘CA’, ‘94609’, 1)
insert authors
values(‘756-30-7391’, ‘Karsen’, ‘Livia’, ‘415 534-9219’,
‘5720 McAuley St.’, ‘Oakland’, ‘CA’, ‘94609’, 1)
insert authors
values(‘724-80-9391’, ‘MacFeather’, ‘Stearns’, ‘415 354-7128′,
’44 Upland Hts.’, ‘Oakland’, ‘CA’, ‘94612’, 1)
insert authors
values(‘427-17-2319’, ‘Dull’, ‘Ann’, ‘415 836-7128’,
‘3410 Blonde St.’, ‘Palo Alto’, ‘CA’, ‘94301’, 1)
insert authors
values(‘672-71-3249’, ‘Yokomoto’, ‘Akiko’, ‘415 935-4228’,
‘3 Silver Ct.’, ‘Walnut Creek’, ‘CA’, ‘94595’, 1)
insert authors
values(‘267-41-2394’, ‘O”Leary’, ‘Michael’, ‘408 286-2428′,
’22 Cleveland Av. #14’, ‘San Jose’, ‘CA’, ‘95128’, 1)
insert authors
values(‘472-27-2349’, ‘Gringlesby’, ‘Burt’, ‘707 938-6445’,
‘PO Box 792’, ‘Covelo’, ‘CA’, ‘95428’, 3)
insert authors
values(‘527-72-3246’, ‘Greene’, ‘Morningstar’, ‘615 297-2723′,
’22 Graybar House Rd.’, ‘Nashville’, ‘TN’, ‘37215’, 0)
insert authors
values(‘172-32-1176’, ‘White’, ‘Johnson’, ‘408 496-7223’,
‘10932 Bigge Rd.’, ‘Menlo Park’, ‘CA’, ‘94025’, 1)
insert authors
values(‘712-45-1867’, ‘del Castillo’, ‘Innes’, ‘615 996-8275’,
‘2286 Cram Pl. #86’, ‘Ann Arbor’, ‘MI’, ‘48105’, 1)
insert authors
values(‘846-92-7186’, ‘Hunter’, ‘Sheryl’, ‘415 836-7128’,
‘3410 Blonde St.’, ‘Palo Alto’, ‘CA’, ‘94301’, 1)
insert authors
values(‘486-29-1786’, ‘Locksley’, ‘Charlene’, ‘415 585-4620′,
’18 Broadway Av.’, ‘San Francisco’, ‘CA’, ‘94130’, 1)
insert authors
values(‘648-92-1872’, ‘Blotchet-Halls’, ‘Reginald’, ‘503 745-6402′,
’55 Hillsdale Bl.’, ‘Corvallis’, ‘OR’, ‘97330’, 1)
insert authors
values(‘341-22-1782’, ‘Smith’, ‘Meander’, ‘913 843-0462′,
’10 Mississippi Dr.’, ‘Lawrence’, ‘KS’, ‘66044’, 0)

GO

Post-build Event Command Line

How to write a command line argument in Post Build event in Visual Studio? To get to the setting, right click on project, select properties, then go to the third entry on left “Build Events”. Mostly like you will need to copy from one folder to another, you either hardcode the full path or use macros to accomplish the task. The macros can bee see on this Microsoft link

If the path of the project contains white spaces in directories, then use quotes to enclose the path name.

Example: copy “$(ProjectDir)SharedLib\Nhibernate\Required_Bins\sqlce*.dll” “$(ProjectDir)$(OutDir)”

Here

$(ProjectDir) = The directory of the project (full path)
$(OutDir) = Path to the output file directory, relative to the project directory