Thursday, August 28, 2014

Panda::APIError: NotAuthorized: Account with access key does not exist

Do anyone frustrated because of the NotAuthorized issue?

1.9.2-p320 :001 > Panda::Profile.all

Panda::APIError: NotAuthorized: Account with access key <<key>> does not exist

If you are setting the PandaStream Add ons through heruku document (https://devcenter.heroku.com/articles/pandastream), Please make sure you create an account in http://www.pandastream.com/ to get you access key and secret key. 

NOTE : PandaStream access key and secret key are different from Amazon S3 access key and secret key.


Notes from https://www.pandastream.com/docs/integrate_with_rails

Configuration

First you must log in to your account where you can find your credentials as follows:
  • Under Api Access: Access key, Secret key, API URL
  • After selecting your Cloud: Cloud ID

Notes from https://www.pandastream.com/docs/api#api_authentication

The Panda API requires all requests must also be signed to ensure they are valid and authenticated. For GET and DELETE requests the additional parameters must be url encoded and added to the parameters in the url. When making a POST or PUT request they should be included in the usual parameters payload submitted.
The access_key and secret_key used to authenticate the request are provided when you sign up for your Panda account. Your keys can always be found by logging in to your account by visiting pandastream.com


Friday, August 1, 2014

autocomplete="off" is not working in chrome

This is one simple issue drove me crazy all afternoon...

I want to ignore the browser autofill option to save the password. Like, sometimes user select the option to save password for the website and Chrome just autofills the password for the user. But, the same machine can be used by multiple users. So you might want to protect the user password, even through user selects to save the password by mistake.

I started searching the solution in Google and I tried, autocomplete="off" for the <input />, it doesn't work, then someone in another post suggested, it will work only if you add autocomplete="off" to the <form /> tag.

Guess what? It didn't work. Since chrome is just ignoring the autocomplete="off" option.

I found a workaround to solve this issue. 

"Chrome autofill the password <input /> tag and the previous <input /> tag. 
So , I added 

<input style="display:none" />
<input type="password" style="display:none" />

It works like a charm. Autofill goes to these <input /> tag, which will not display and the real one works as expected.

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;
        }