Monday, January 5, 2015

Record Count of all table

To get the record count of each table in the database at once.

CREATE TABLE #RecordCount
(
    TableName varchar(500),
    NoOfRows int
)

EXEC sp_MSForEachTable @command1='INSERT #RecordCount(TableName  NoOfRows) SELECT ''?'', COUNT(*) FROM ?'
SELECT TableName NoOfRows  FROM #RecordCount ORDER BY TableName NoOfRows DESC

Wednesday, October 1, 2014

Flash trace() in browser Console

This is Super awesome. You can view the Flash trace in browser console, using the following commands in Actionscript. It works fine in Chrome and FireFox.
You are free to debug your swf in your website.


import flash.external.ExternalInterface;

ExternalInterface.call("console.log", "YourString");

Thursday, September 18, 2014

Secure file copy to Amazon Elastic Compute Cloud (Amazon EC2)

1. First connect to the instance using ssh command, make sure .pem (private key) is available in your ssh directory in ~/.ssh with permission chmod 400 <<my-key-pair.pem>>

ssh -i my-key-pair.pem ec2-user@ec2-198-51-100-1.compute-1.amazonaws.com

2.  After successfully connected, Execute the following command

scp -ir my-key-pair.pem <<Source path>> ec2-user@ec2-198-51-100-1.compute-1.amazonaws.com:<<destination path>>


Friday, September 12, 2014

Rails Routing

Understanding Rails routing. Notes taken from the source (http://guides.rubyonrails.org/routing.html)
 
resources :photos
Creates seven different routes in your application, all mapping to the Photos controller:

HTTP Verb Path Controller#Action Used for
GET /photos photos#index display a list of all photos
GET /photos/new photos#new return an HTML form for creating a new photo
POST /photos photos#create create a new photo
GET /photos/:id photos#show display a specific photo
GET /photos/:id/edit photos#edit return an HTML form for editing a photo
PATCH/PUT /photos/:id photos#update update a specific photo
DELETE /photos/:id photos#destroy delete a specific photo

Thursday, September 4, 2014

gpg: public key decryption failed: Bad passphrase

When I  try to decrypt a file using GPG, for which I use "Starksoft.Cryptography.OpenPGP". I got the following error
Starksoft.Cryptography.OpenPGP.GnuPGException: An error occurred while trying to execute command --list-secret-keys.
But when I execute the command through command prompt ">gpg --list-secret-keys", it does list the keys. I could not get "Starksoft.Cryptography.OpenPGP" to work correctly.
Next I tried to get a solution by running the process directly using cmd.exe, which worked perfectly.

>echo Mypasspharse|gpg.exe --passphrase-fd 0 -o "C:\successtest.txt" --decrypt "C:\testfile.txt.gpg"
Note:
If Mypassphare contain a character ">" which will get interpreted as std out redirect in windows command prompt. So, passphase will not pass to the next command properly. So make sure you are not using  ">" in Passphase, if you are planning to use command prompt for gpg decryption

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