Wednesday, April 2, 2014

Date Functions in TSQL

To get the first date of the week by passing the week id

dateadd(wk, datediff(wk, 0, getdate()), 0)

To get the last date of the week by passing the week id

dateadd(wk, datediff(wk, 0, getdate()), 0) + 6

Tuesday, January 28, 2014

Apply CSS to IE10 and IE11

CSS Compatability trick for Ie10 and ie11 browser. Probably, it will work for IE12, IE13....etc ;-)

<style type="text/css">

 @media screen and (-ms-high-contrast: active), (-ms-high-contrast: none) {
        /*include style here*/
 </style>

Friday, December 13, 2013

Check whether xp_cmdshell is disabled or not

Xp_Cmdshell

- Spawns a Windows command shell and passes in a string for execution.

The Windows process spawned by xp_cmdshell has the same security rights as the SQL Server service account.
xp_cmdshell operates synchronously. Control is not returned to the caller until the command-shell command is completed.
xp_cmdshell can be enabled and disabled by using the Policy-Based Management or by executing sp_configure
To check whether xp_cmdshell is disabled or not. Run the following Query.
SELECT CONVERT(INT, ISNULL(value, value_in_use)) AS config_value
FROM sys.configurations
WHERE name = 'xp_cmdshell' ;


To enable the xp_cmdshell, you can refer the following msdn doc.

Reference : http://technet.microsoft.com/en-us/library/ms175046(v=sql.105).aspx
                 http://technet.microsoft.com/en-us/library/ms190693(v=sql.105).aspx
                 

Thursday, December 12, 2013

JQuery InnerFade Issue

I have recently used the Jquery plugin "Innerfade",  to fade in and out any element included in the container.

Reference : http://medienfreunde.com/lab/innerfade/

Its very easy and so simple. But, one issue that really bugged me is that, if i left my browser open for awhile, then all the images with in the container will start fading fast on top of the another image

I found the bug fix for this. If you experiencing the same issue using innerfade plugin. You can modify the "jquery.innderfade.js" script line 93 and 96 as i did. It fixed the issue.


line 93...$(elements[last]).stop(true,true).slideUp(settings.speed);
line 96...$(elements[last]).stop(true,true).fadeOut(settings.speed);
Reference link : http://computeraxe.com/jquery-stop-action-improves-innerfade-plugin/

Wednesday, December 11, 2013

PHP and C#.Net MD5 code mismatch

Are you experiencing the MD5 code mismatch, even though you are using the same string and key in Php and dot net? Of course it does... Since we need to convert the string + key into ASCII bites. You can use the below code in C#.Net to match the MD5 code in php.


               var strKey = "********";
               var strValue = "abcd";

                byte[] asciiBytes = ASCIIEncoding.ASCII.GetBytes(strValue  + strKey);
                byte[] hashedBytes = MD5CryptoServiceProvider.Create().ComputeHash(asciiBytes);
                string hashedString = BitConverter.ToString(hashedBytes).Replace("-", "").ToLower();

Tuesday, November 26, 2013

Sass Vs SCSS

Css is taking its form to next level, by including scripts in it and I'm seeing lot of question, discussion about the SASS and SCSS... which one to follow, which is easy....what is the difference...

Here, I'm going to summarize what i found and examples are taken from wikipedia...;-)

SASS


Sass (Syntactically Awesome Stylesheets) is the scripting laugage that is interpreted into CSS. And It has 2 syntaxes.

1.  Indented syntax - uses indentation to separate code blocks
2. SCSS (Sassy CSS) - uses block formatting like that of CSS

SassScript provides the following mechanisms: variables, nesting, mixins, and selector inheritance

Variables : 

$margin: 20px;

body
 margin : $margin / 2

Nesting:

table.hl {
  margin: 2em 0;
  td.ln {
    text-align: right;
  }
}

Equilent CSS : 

table.hl {
  margin: 2em 0;
}
table.hl td.ln {
  text-align: right;
}

Mixins:

Most helpful feature, to avoid repeated code and easy modification in CSS.

@mixin table-base {
  th {
    text-align: center;
    font-weight: bold;
  }
  td, th {padding: 2px}
}

#data {
  @include table-base;
}

Equivalent Css:

#data th {
  text-align: center;
  font-weight: bold;
}
#data td, #data th {
  padding: 2px;
}

Selector Inheritance:

Interestingly, you can implement inheritance as like java / c# by using extend keyword.

.error {
  border: 1px #f00;
  background: #fdd;
}
.error.intrusion {
  font-size: 1.3em;
  font-weight: bold;
}

.badError {
  @extend .error;
  border-width: 3px;
}

Equivalent to

.error, .badError {
  border: 1px #f00;
  background: #fdd;
}

.error.intrusion,
.badError.intrusion {
  font-size: 1.3em;
  font-weight: bold;
}

.badError {
  border-width: 3px;
}

You can get more information from : http://sass-lang.com/guide

SCSS


The new main syntax (as of Sass 3) is known as “SCSS” (for “Sassy CSS”)

So, most people with interchange the term SASS and SCSS...Dont get confused....
When you become the master of SASS, check out the "Foundation" framework....
http://foundation.zurb.com/docs/index.html

Its simply awesome (http://foundation.zurb.com/business/why-foundation.html ).... You can design the website so quick and fast with Responsive Web design. 

Thursday, November 14, 2013

Git Commands - Quick Reference

Install git in Mac
http://code.google.com/p/git-osx-installer, Other OS, please refer here : http://git-scm.com/book/en/Getting-Started-Installing-Git


Initialize a Git repository and make the first commit

$ git init
$ git add .
$ git commit -m "Initial commit"

Create a new repository and push it up to GitHub:

$ git remote add origin git@github.com:<username>/demo_app.git
$ git push origin master

Create a branch and switch to the branch at the same time

$ git checkout  - b newbranch-dev
(or)

$ git branch  newbranch-dev
$ git checkout newbranch-dev

To List out the available Branch

$ git branch -a

To switch to master branch

$ git checkout master
$ git branch -a

To push the changes to particular branch. (origin is the remote created for the git url using <<git remote add command>>)

$ git push origin newbranch-dev

To get the latest version by cloning the git project, for first time (Reference : http://git-scm.com/book/en/Git-Basics-Getting-a-Git-Repository)

$ git clone <<git clone public URL>>

To get the latest version from the git project after cloning. (origin is the remote created for the git url using <<git remote add command>>)

$ git pull origin newbranch-dev

To find the difference between current working copy and last version

$ git diff HEAD


To find the difference between any commit and Last version, you can get the commit_id by using this command(
$ git log -4 --pretty="%h - %s" - will give last 4 commits)

$ git diff commit_id HEAD


To find the difference between last version and previous commit


$ git diff HEAD^ HEAD

Thursday, November 7, 2013

Parameter Count Mismatch

O boy!.... Today, I bang my head to solve this issue....

I was trying to Send an attachment email through Dot Net Amazon SDK. But, got stuck with this issue.. Since the following code is standard, that you can get from internet, to convert the MailMessage To MemoryStream. Finally identify the issue and solved.

public static MemoryStream ConvertMailMessageToMemoryStream(MailMessage message)
        {
            Assembly assembly = typeof(SmtpClient).Assembly;
            Type mailWriterType = assembly.GetType("System.Net.Mail.MailWriter");
            MemoryStream fileStream = new MemoryStream();
            ConstructorInfo mailWriterContructor = mailWriterType.GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic, null, new[] { typeof(Stream) }, null);
            object mailWriter = mailWriterContructor.Invoke(new object[] { fileStream });
            MethodInfo sendMethod = typeof(MailMessage).GetMethod("Send", BindingFlags.Instance | BindingFlags.NonPublic);
            sendMethod.Invoke(message, BindingFlags.Instance | BindingFlags.NonPublic, null, new[] { mailWriter, true}, null); // Throws Error , Parameter Count Mismatch
            MethodInfo closeMethod = mailWriter.GetType().GetMethod("Close", BindingFlags.Instance | BindingFlags.NonPublic);
            closeMethod.Invoke(mailWriter, BindingFlags.Instance | BindingFlags.NonPublic, null, new object[] { }, null);
            return fileStream;
        }


You have to change the parameter array object. Since "Send" Private method has three parameters System.Net.Mail.MailMessage.Send(BaseWriter writer, bool sendEnvelope, bool allowUnicode).

Correct Code


public static MemoryStream ConvertMailMessageToMemoryStream(MailMessage message)
        {
            Assembly assembly = typeof(SmtpClient).Assembly;
            Type mailWriterType = assembly.GetType("System.Net.Mail.MailWriter");
            MemoryStream fileStream = new MemoryStream();
            ConstructorInfo mailWriterContructor = mailWriterType.GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic, null, new[] { typeof(Stream) }, null);
            object mailWriter = mailWriterContructor.Invoke(new object[] { fileStream });
            MethodInfo sendMethod = typeof(MailMessage).GetMethod("Send", BindingFlags.Instance | BindingFlags.NonPublic);
            sendMethod.Invoke(message, BindingFlags.Instance | BindingFlags.NonPublic, null, new[] { mailWriter, true, true}, null); // Success
            MethodInfo closeMethod = mailWriter.GetType().GetMethod("Close", BindingFlags.Instance | BindingFlags.NonPublic);
            closeMethod.Invoke(mailWriter, BindingFlags.Instance | BindingFlags.NonPublic, null, new object[] { }, null);
            return fileStream;
        }

Tuesday, November 5, 2013

Processing the Error Log

It hard to search the specific error occurred in the log file, to go through manually, when the file is of huge size.

- to find number times it occurred
-to find the pattern of the error
-or quick review of the error message

I found an easy way to do that, You can use this command not only for log file, any text file. This commands is for Windows machine

>Find "Sent alert email to admin for email" ErrorLog11052013.log >EmailErr.txt

Display all the line that matches ""Sent alert email to admin for email" in the file "ErrorLog11052013.log" and the Output will be redirected to "EmailErr.txt" file.

Thursday, October 10, 2013

Heroku: Permission denied (publickey). fatal: Could not read from remote repository.

You have make sure, you have added the heroku rsa public key to the server from your local machine

Check whether you have a file called "id_rsa.pub" in the .ssh folder. If not you have generate the key. 

Follow the steps:

1. To generate the key : $ ssh-keygen -t rsa
(You will get these prompts, press enter and continue
Enter file in which to save the key (/Users/TestUser/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: )

2.  Add the key to Heroku server : $ heroku keys:add ~/.ssh/id_rsa.pub

Reference : https://devcenter.heroku.com/articles/keys