Featured post

Popular Topics

Popular Topics


How To Read Articles On Financial Times For Free Saving £5.19 or $6.25 a week
13-06-2012 It usually costs £5.19 or $6.25 a week to get unlimited access to FT (Financial Times). You can open a free account which will allow you to access a certain number of articles a month. Or You can follow below steps :) What you need to do is : Search of Brows through FT and find the article you want to read. Copy the article heading Paste it into Google Google will show you a link to the appropriate FT article on ...

The Structure-Conduct-Performance Model
2010-04-01 In 1930s, a group of economists developed an approach to understand relationship among a firm’s environment, behaviour and performance. This theoretical framework, since then, is known as the Structure-Conduct-Performance (S-C-P) Model.                       Structure, in this model refers to the structure of the industry in which the...

Using TextEditSettings.DisplayFormat To Format Your Data In DevExpress DataGrid
07-03-2012 // // Devexpress doesn't provide much information about how you can use this to format your data when you use DevExpress DataGrid. I have a code to create and format a devexpress datagrid dynamically at run time. I had to automatically format date to match the British system if the current data is of type DateTime. Basically, what you have to use as the string for the Display format is exactly what you would use if you w...

How To Check For NULL Values Correctly In SQL


Change the Firefox Address Bar Search Engine
17-07-2012 1. Type about:config in your address bar 2. Search and locate the key called "keyword.url" 3. Double click on the key and update the search URL to match the search engine you desire. Following are the URLs for common search engines: Google: http://www.google.com/search?&q= Yahoo: http://search.yahoo.com/search?p= Ask: http://www.ask.com/web?q= Bing: http://www.bing.com/search?ie=UTF-8&oe=UTF-8&sourceid=n...

How to force your website to download a file (rather than opening)
07/05/2013 I wanted to add a download link to one of my products. The file was an Windows Installer Package (*.msi). However, FireFox started to open the file on the browser rather than downloading it so when my visitors tried to download the installer they would rather see some gibberish on the browser because FireFox was trying to "open" the MSI file. There's a simple fix. Just add following line to your .htaccess file so that your ...

How To Check For Full SubStrings In A Comma Separated String
22/07/2013 How to avoid detecting substrings, how to check for perfect substrings, avoid detecting substrings, avoid detecting substrings when checked for substrings. Today I needed to find if a string is contained within a string. So I used the most straight forward method (I used SQL but this works for any language) declare @msgsToSkip varchar(max) = 'geoLocation,statusUpdateCheck,forceClose'; ...

How To Check For Full SubStrings In A Comma Separated String

22/07/2013

How to avoid detecting substrings, how to check for perfect substrings, avoid detecting substrings, avoid detecting substrings when checked for substrings.

Today I needed to find if a string is contained within a string.

So I used the most straight forward method (I used SQL but this works for any language)

declare @msgsToSkip varchar(max) = ‘geoLocation,statusUpdateCheck,forceClose';
declare @msg varchar(max)= ‘statusUpdate’
if(charindex(@msg, @msgsToSkip) > 0)
begin
print ‘found’
end
else
print ‘not found’

Problem – as you can see, this code is written to messages with caption as either “geoLocation”, “statusUpdateCheck”, or “forcedClose”

But I also receive a message with caption “statusUpdate” this is different to “statusUpdateCheck” and must be allowed but obviously the code returns true for statusUpdate as it is a substring of statusUpdateCheck.

The Solution,

Simply make each word dirty by adding a character to it. It could be any character as long as you keep the code consistent. In more simple words, simply add a character to the string you are

Looking For and the string you are Searching In.

This is the fixed code

declare @msgsToSkip varchar(max) = ‘geoLocation-,statusUpdateCheck-,forceClose-‘; — <– Notice that a ‘-‘ is added to make each word dirty
declare @msg varchar(max)= ‘statusUpdate’
if(charindex(@msg + ‘-‘, @msgsToSkip) > 0) — <- Notice the + ‘-‘
begin
print ‘found’
end
else
print ‘not found’

This will not detect statusUpdate as statusUpdateCheck because at the checking time, the code sees statusUpdate as statusUpdate- and it is not a substring of statusUpdateCheck (note that  statusUpdateCheck is now statusUpdateCheck- but it’s the ‘-‘ in the statusUpdate that does the trick.)

Menol
ILT

ILT – Simple technique to toggle between true and false or one and zero

20/06/2013

If you want to toggle a value from 1 to 0 or 0 to 1 depending on the current value then you are at the right place.
(i.e. change the value to 0 only if it’s 1 now and change it to 1 only if it is 0 at the moment)

You can use this to toggle between true and false as well.

Problem: Convert the value to zero if it’s one or convert the value to one if it’s zero.

Solution:
Use this formula : New Value = (Old value -1) * -1
e.g. zero = (one – 1) * -1;
e.g. one = (zero – 1) * -1;

Example:

private void myCode()
{
int x;

/ * — case 1: value of x is one. The expected result after applying the formula is 0 — */
x = 1;
printX(x); // prints Value of X is : 1

// apply
x = toggleOneZero(x);
//Check the output
printX(x); // prints Value of X is : 0

/ * — case 2: value of x is zero. The expected result after applying the formula is 1 — */
x = 0;
printX(x); // prints Value of X is : 0

// apply
x = toggleOneZero(x);
//Check the output
printX(x); // prints Value of X is : 1
}

private int toggleOneZero(int originalValue)
{
int newValue = (originalValue -1) * -1
return newValue;
}

private void printX(int x)
{
Console.WriteLine(“Value of X is :” + x.ToString());
}

[/sourcecode]
Menol

ILT