Monthly Archives: May 2013

C# gives no error but does not run

Did you run you C# or PHP or ASP.NET code. The code does not run but it does not give any error either? In my case, the page which was generating error was sending code to JavaScript. There I could not see any error. But once I went to browser and looked at the render code (View Code on page), the exception was there. It was just hidden under html :)

Might be handy if you come across something like this, where the program does not give any error but it does not run either.

stretch outer div to inner div

Problem

You have floating contents inside a parent div and the parent div does not stretch to encompass all the contents.

Example

Jsfiddle of the below code is here

I am in the inner div.
#css to the above code. #outer { border:1px solid red; } #inner { background-color:blue; float:left; }

This will render as

contents don't stretch

Solution

Set the overflow:auto for the outer div as follows.

#outer {
    overflow:auto;
}

Problem solved. Here is the jsfiddle of the solution.

Output after applying overflow property to outer div.
stretch div to fit contents

search all tables sql

The following query, original from this site, searches all integer columns only to find a value. It does not find string but integer value. This query may run faster on large databases and can be more usefully. Basically your search by table id which is usually an index field and runs faster.

CREATE PROC SearchAllTablesForValue
(
	@value int
)
AS
BEGIN

	-- Originally from : http://vyaskn.tripod.com
	-- Modified by Hammad. Test on SQL Server 2012

	CREATE TABLE #Results (ColumnName nvarchar(370), ColumnValue nvarchar(3630))

	SET NOCOUNT ON

	DECLARE @TableName nvarchar(256), @ColumnName nvarchar(128), @SearchStr2 nvarchar(110)
	SET  @TableName = ''
	SET @SearchStr2 = QUOTENAME( @value,'''')

	WHILE @TableName IS NOT NULL
	BEGIN
		SET @ColumnName = ''
		SET @TableName = 
		(
			SELECT MIN(QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME))
			FROM 	INFORMATION_SCHEMA.TABLES
			WHERE 		TABLE_TYPE = 'BASE TABLE'
				AND	QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME) > @TableName
				AND	OBJECTPROPERTY(
						OBJECT_ID(
							QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME)
							 ), 'IsMSShipped'
						       ) = 0
		)

		WHILE (@TableName IS NOT NULL) AND (@ColumnName IS NOT NULL)
		BEGIN
			SET @ColumnName =
			(
				SELECT MIN(QUOTENAME(COLUMN_NAME))
				FROM 	INFORMATION_SCHEMA.COLUMNS
				WHERE 		TABLE_SCHEMA	= PARSENAME(@TableName, 2)
					AND	TABLE_NAME	= PARSENAME(@TableName, 1)
					AND	DATA_TYPE IN ('int')
					AND	QUOTENAME(COLUMN_NAME) > @ColumnName
			)
	
			IF @ColumnName IS NOT NULL
			BEGIN
				INSERT INTO #Results
				EXEC
				(
					'SELECT ''' + @TableName + '.' + @ColumnName + ''', LEFT(' + @ColumnName + ', 3630) 
					FROM ' + @TableName + ' (NOLOCK) ' +
					' WHERE ' + @ColumnName + ' LIKE ' + @SearchStr2
				)
			END
		END	
	END

	SELECT ColumnName, ColumnValue FROM #Results
END

mac terminal find command recursive

For reference, Find command documentation on apple

Find command lets you search a particular file or files depending on the criteria. Some of the things about find command may not be intuitive. I will explain it here

  • Find command is case sensitive. That is *.JPG and *.jpg will be interpreted as different files.
  • Find Command is recursive by nature. It does not need any switch to force looking into subdirectories.

Usage or Syntax

find [path/directory] -name [pattern]

directory = directory (or path) name where you want to perform search.
-name = is going to match the [pattern] to the filename (and path). Not that this is case sensitive. On the other hand -iname is case insensitive
[pattern] = quoted string, that can contain *, ? or \ (escape) characters.

In mac terminal and other operating systems, a single dot (.) is used for current folder. And ~ (tilde) is used to user home directory (this is specific to mac). ~ = /Users/username/

Example usage of find

find . -name *.mp3  # this will find all files in current directory(.)
that has mp3 extension. But will not match .MP3 because it is case sensitive.

find . -iname *.mp3 # will find all mp3 files 
regardless of case sensitivity

Using Regular Expression in Find

Find also supports regular expression (RegEx in short). The syntax is similar to string search.

find [directory] -regex [pattern]

In this case the pattern is a valid regex pattern. Otherwise you will get no results.

RegEx is a separate topic in itself. You may find the documentation online.

 

Example of Regular Expression in Mac Terminal

find . -iregex "[a-z\/\. ]*"

[a-z] is pseudo class used in regular expression. This means A-Z characters (all 26 included).

\/ = The file name (and path) may contain backspace character (\).

\. = The file name may contain . character.

[space] = There is a space character after (\.). This means the filename may contain a space character.

Remove Product Ads in Chrome Browser

If you come across these annoying product ads in Google Chrome browser, here is how to remove them.

QuickMarkup Ads

If you read the text on ads, it says QuickMarkup. These ads come from QuickMarkup Extension that you may have installed sometime ago.

How to disable QuickMarkup Ads

In google chrome, select the very first item in menu, Chrome and then select preference.
Disable Product Ads in Chrome

This will take you to setting (preferences) tab. Select Extensions as show below.

Extensions in Google Chrome

Scroll down to QuickMarkup Plugin and select options as shown in the screenshot below.
Screen Shot 2013-05-24 at 8.48.12 PM

Uncheck the “Enable Shopping Assistant” check mark in Quick Markup Extension.

Disable products ads in google

Remove similar products ads

You might come across these annoying adds on amazon.com or craigslist that come in your way.

Similar Products Ads

These says “Similar Products” and their url points to superfish.com adds. Here is how to disable or remove them.

How to remove Similar Products Ads or Superfish Ads

 

Similar Products Ads from Awesome Screenshot

If you hover over the close button, it says “Close AwesomeScreen shot Plus side up”

 

 

To resolve this click Safari > Preferences. Then go to Extension tabs. Locate Awesome Screen Shot and uncheck “Enable Similar Product Search powered by Superfish”. Screen shot is below. You should be all set.

Superfish Ads

If you are having this issue in Google Chrome Browser, click here to resolve.

Can not log on locally to as user x with virtual directory password

If you look close at the error, it will say
Module : IIS Web Core

This means it is coming from IIS. The problem is you do not have permission to access the config file. The error actually quotes config file as well, esp the line that says

Resolution

Go to the location where your config file is located. The IIS should give you that location in the error message. Right click in the folder and check directory permission. See what permission user ‘x’ has. In my case, somehow it has a cross sign on top of it. I dont know how it happened. It was working fine. Note that IIS is configured to access the site (and hence the location) via user ‘x’.