Pages

Friday, October 25, 2013

How-to Opt-out from Google Ads not to spoof your Gmail emails

In recent times, there has been a lot of controversy around Google and its ad behavior in Gmail. Microsoft claims that Google is reading all your Gmail emails to display relevant ads. Microsoft goes a step further and created a television ad campaign called "SCROOGLED!" to fight against Google and help netizen to safeguard their private information and to shift from Gmail to Outlook.

Here are the steps for all Gmail users to maintain their privacy settings and opt-out from share their information like age, gender, location and interests.

Step 1: As you can notice from the below image there are different ad slots in your Gmail inbox. Click on "Why this ad?" or "Ads (i)" link and modify your Google ad Settings.

Step 2: Control your ads settings.

Step 3: You can control your ads on Google and Google Ads across the web.

Step 4: At the bottom of the screen on Step 3, you can see Opt-Out links for both Google and the web.

Step 5: Opt-Out confirmation for Ads on Google.

Step 6: Opt-Out confirmation for Google Ads across the Web

Step 7: Finally, go to aboutads.info (see Step 4 image) choice page to opt-out from DoubleClick and other companies cookies used for internet based ads.

There by following the above steps, you can safeguard your private information like emails, chat conversations between wife and a husband or close friends from being spoofed.

Let me know your personal experience and hope this helps :)

Thursday, April 18, 2013

Tips: Simplify code for better approach

Developers always concentrated on the problem and try different algorithms. Often the first solution won’t be the best. They think again, be creative, try a different approach. Come up with more ideas and choose from better. The better the algorithm is, the better the solution.

However in this blog post, I'm not going to discuss about algorithms. I will be concentrating on tips which (C#) developer neglect in a hurry to solve problems. Just by following the items one can simplify the code for better understanding and readability.

1.  Never use unused “using” statements within a class/page. Use “Remove and Sort” under “Organize Usings” from the context menu
2.    Pascal Casing (first word capitalized). Use PascalCasing for classes, types, methods and constants
3.    Camel Casing (all but first word capitalized). Use camelCasing for local variables and method arguments
4.    Try to skip underscores (“_”) to separate words
5.    Variables names may follow Hungarian Notation or camel case
Ex:
string firstName;
6.    Method names must follow Pascal Notation
Ex:
public string GetUserFirstName()
       {
              // Some statements...
       }
7.  Class variables or member names should start with an “_”
Ex:
int _familyId;
8.    Always check the negative conditions first to exit the method
Ex:
Old:
            if (!IsPostBack)
       {
           // Some Statements
       }
New:
            if (IsPostBack) return;
       // Some Statements
9.    Never use “this” keyword to identify page controls or properties
10.  Try to reduce the no. of lines of code as well as unused variable declarations
Ex: The method allows us to create a random string using Global unique Identity class (GUID)
Old:
private string generateString()
       {
            string pName;
            Guid fileName = Guid.NewGuid();
            pName = fileName.ToString().Substring(0, 8);
            return pName;
       }
New:
private string generateString()
       {
            return Guid.NewGuid().ToString().Substring(0, 8);
       }
11.  Use implicitly typed local variable declaration (var) only when necessary
Note1: When the class name of an object declaration and initialization is same, we can replace the declaration with var keyword.
Ex:
Old:
BlogBase bb = new BlogBase();
New:
var bb = new BlogBase();

Note2: We need to declare the object with class name only if the initialization of an object is done by the resultant output of a method or function.
Ex:
FamilyMember fm = FamilyMember.SelectByMultipleFields("FamilyID", familyId, "MemberId", memberId); // The method will return an object of type FamilyMember class
12.  Try to reduce if... else... statements either using logical assignment or ternary operator ( ? : )
Ex1: Using logical assignment
Old:
            if (Emailids.Tables.Count == 0)
       {
              lbtnDelete.Visible = false;
       }
       else
       {
              lbtnDelete.Visible = true;
       }
New:
            lbtnDelete.Visible = Emailids.Tables.Count != 0;
Ex2: Using ternary operator
Old:
if (stringMode.Equals("new"))
ViewState.Add("Mode", "new");
else
ViewState.Add("Mode", "ex");
New:
ViewState.Add("Mode", stringMode.Equals("new") ? "new" : "ex");
13.  Use LINQ & lambda expressions whenever necessary
Ex:
Old:
string bColor = "";
for (int i = 0; i < aColor.Length; i++)
bColor = bColor + aColor[i];
New:
string bColor = aColor.Aggregate(bColor, (current, t) => current + t);
14.  We can reduce the delegate creation by skipping the associated event handler Class
Old:
Master.FamilyRefreshed += new EventHandler(MasterFamilyRefreshed);
New:
Master.FamilyRefreshed += MasterFamilyRefreshed;
15.  Use null-coalescing operator (??) whenever necessary
Ex:
int? x = null;
// y = x, unless x is null, in which case y = -1.
int y = x ?? -1;
16.  Declare local variables as close as possible to the first time they're used
17.  Try to avoid global variables
18.  Never make redundant “toStrings()” calls
Ex:
string code = Request.QueryString["Code"].ToString();
19.  Don’t comment the trivial statements, but strategically write paragraphs if needed in specific sections
20.  Make sure your code is source safer with tools viz. VSS, SVN, TFS, Git etc.,
21.  Never be in a state of “Probably be ok” w.r.t use-case; Test and Verify each use-case
22.  Communicate with team when in doubt
23.  Never reinvent/rewrite the code from scratch. Always check your existing code base from same or different projects, teams and if nothing stands go for Google
24.  An engineer truly becomes a wiser "professional" only after the software been released only then 80% of blood, sweat and tears in maintenance

Feel free to add tips within the comments section below based on your experience.

Sunday, March 3, 2013

Resume: How to seek world attention

This is a blog post in contribution to the article 11 Resumes that Got Worldwide Attention posted on yahoo finance. This guy used flipkart as the base layout to showcase his talent.

Although, copying an item is the simplest thing to do. However, there are lots of things to keep in mind like getting handful tips from the available resources, using the right tools and services and a lot of thought process;

Definitely, this is one of the best ways in the world to set your positivist impression.


Saturday, February 2, 2013

SQL CLR Functions

We can create a function within SQL Server that depend on a SQL assembly which itself is compiled using any of the .Net framework Common Language Runtime (CLR) managed code.

Beginning with SQL Server 2005, we can write user-defined functions which are of scalar (which returns single value) and table-valued function types. However, in this blog post we are dealing with Scalar type CLR functions.

T-SQL has lot of inbuilt functions and features. However to custom our own complex logic we use any CLR managed code like C# or VB.Net etc., and incorporate it in SQL environment.

Here are the steps to create a Scalar CLR functions:

1. Create a project of type "Class Library" using Visual Studio.

2. Add your static methods in our case "Encrypt" and "Decrypt” methods to the class.


3. Specify "SqlFunction()" attribute to all the functions that can be accessed from SQL Server function/stored procedure.

4. Compile & build the application in "Release" mode to get the assembly (.dll)

5. Now go to SQL Server MS; select your database and create New Query and execute the following statements below to enable CLR:
sp_configure 'clr enabled', 1;
GO
reconfigure
GO
6. If you encounter any compatibility level errors then check to see you database compatibility level using
sp_dbcmptlevel

If it is set to 100 or above, execute the following statement to set it to 90
sp_dbcmptlevel 'SQLCLR', 90

7. Before adding the 'dll' to the SQL assemblies you need to set the database to trustworthy using the following statement
ALTER DATABASE SET TRUSTWORTHY ON

8. Now expand your database node to go to Assemblies located within Programmability and create new assembly.

9. Choose the assembly file path and set the permissions for assembly owner.
(Note: In case you get any errors check the steps #5, #6 and #7)

10. Later to access the external CLR functions from within assembly we need to create a function in SQL Server. External name should be like ...
Execute following queries to encrypt and decrypt functions:

CREATE FUNCTION [dbo].Encrypt(@Input nvarchar(max)) RETURNS nvarchar(max)
EXTERNAL NAME  EDCLR.EDCLR.Encrypt

Go

CREATE FUNCTION [dbo].Decrypt(@Input nvarchar(max)) RETURNS nvarchar(max)
EXTERNAL NAME EDCLR.EDCLR.Decrypt;
 


11. When everything is ready; use the following query to encrypt

Select dbo.Encrypt('Hello World')

and use function to decrypt the encrypted string

Select dbo.Decrypt('i9E2KOEoT7D+Doc2CBdjDA==')

This can be use to encrypt passwords, credit card details and other sensitive information within SQL. Visit MSDN to know further about CLR

Happy Coding :)

Thursday, January 17, 2013

Struggling to answer very basic math equations?

These days it is quiet common to see challenging posts on social media to answer the very basic math equations. To my surprise people often reveal wrong answers.

Say for example here is a small math equation: 3 + 9 - 2 * 4 + 5

What do you think is the answer 45 or 9?!!

To answer this we need to get familiar with the very basic rule of math which is called Order of Operations often called BODMAS (Bracket - Order - Division - Multiplication - Addition - Subtraction) mnemonic.

Bracket often represented as () or {} or [] to distinguish between different sets.

Order is nothing but the exponential of a number. Ex. 52

Division/Multiplication: Both are of same precedence. Division is nothing but the multiplicative inverse. Ex: 5/2 = 5 * (1/2)

Addition/Subtraction: Like Division - Multiplication, Addition and Subtraction are of same precedence.  Subtraction is nothing but the additive inverse. Ex: 5 - 3 = 5 + (-3)

The order of operations used throughout mathematics, science, technology and many computer programming languages is expressed here:
1. Brackets or Parentheses
2. Exponents and Roots
3. Multiplication and Division
4. Addition and Subtraction

BODMAS is often used in UK. However its equivalent mnemonics are PEMDAS (Parentheses - Exponents - Multiplication - Division - Addition - Subtraction) which is used in United States. Orders can be replaced with Exponents or Indices or Powers to name a few BEDMAS and BIDMAS.

The answer to the above equation is:

3 + 9 - 2 * 4 + 5
   = 3 + 9 - (2 * 4) + 5
   = 3 + 9 - 8 + 5
   = 3 + 1 + 5
   = 9