Rss Feed Like Us on facebook Google Plus

March 8, 2013

Check String is Palindrome or Not using T-Sql Script +Reverse Funtion


The palindrome is a word, phrase, or sequence that reads the same backward as forward. 

"A palindrome is a word, phrase, number, or other sequence of symbols or elements, whose meaning may be interpreted the same way in either forward or reverse direction."

For example  
A man, a plan, a canal – Panama! is palindrome 
so as Was it a car or a cat I saw?

Palindrome in Sanskrit --


सारस नयना घन जघ
नारचित रतार कलिक हर सार रसा
सार रसारह कलिकर
तारत चिरनाघ जनघ नायनसरसा |
SQL Script



DECLARE @PalinString VARCHAR(256);
SET @PalinString = 'सारस नयना घन जघ नारचित रतार कलिक हर सार रसा सार रसारह कलिकर तारत चिरनाघ जनघ नायनसरसा';
SELECT CASE WHEN REPLACE(@PalinString, ' ', '') = REVERSE(REPLACE(@PalinString, ' ', ''))
THEN 'Palindrome'ELSE 'Not Palindrome' END AS [Answer]
GO
 

Sql Script - "Was it a car or a cat I saw"

DECLARE @PalinString VARCHAR(256);
SET @PalinString = 'Was it a car or a cat I saw';SELECT CASE WHEN REPLACE(@PalinString, ' ', '') =REVERSE(REPLACE(@PalinString, ' ', ''))THEN 'Palindrome'ELSE 'Not Palindrome' END AS [Answer]
GO
 


Again, if the word is not Palindrome you can just will get answered as it is not a palindrome. My script currently is removing all the spaces from the string. However, if your string is like A man, a plan, a canal – Panama! you may have to remove the exclamation mark and comma too using the REPLACE function.

Sql Script - " A man, a plan, a canal – Panama! "



DECLARE @PalinString VARCHAR(256);
SET @PalinString = 'A man, a plan, a canal - Panama!';
SELECT CASE WHEN REPLACE(REPLACE(REPLACE(REPLACE(@PalinString, '-',''), '!',''), ',',''), ' ', '')
= REVERSE(REPLACE(REPLACE(REPLACE(REPLACE(@PalinString, '-',''), '!',''), ',',''), ' ', ''))
THEN 'Palindrome'
ELSE 'Not Palindrome' END AS [Answer]
GO
Read More

March 6, 2013

Task Manager Disabled in Windows XP, Enable It.

Question: - How to Enable Task Manager in Windows XP?
Problem: It is due to some kind of virus/ trojan activity which normally disables the task manager.Now due to this problem when ever the user press alt+ctrl+del to launch windows task manager it gives an error saying “Task Manager is being disabled by your administrator”.
Solution:
To Enable the Disabled Task Manager on your system
1. Press window key+r to show run prompt
2. Follow the following steps
  1. Enter gpedit.msc in the run prompt and click OK
  2. In the Group Policy settings window
  3. Select User Configuration
  4. Select Administrative Templates
  5. Select System
  6. Select Ctrl+Alt+Delete options
  7. Select Remove Task Manager
  8. Double-click the Remove Task Manager option’.
  9. Set the property of this item as disabled.
______________________________________________________________________
For Those who use Windows XP Home Edition can use the registry to enable Task Manager
1. open start >> run and type regedit 
2. Navigate to the following path:
Hive:HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System 
3. You will find a registry key with name DisableTaskMgr of type: REG_DWORD
4. Double click the key with and set the Value to 0
5. Exit the registry and restart to see the effect.
If you still get problems in enabling the disabled task manager on your windows XP system , please let us know through your comments
Read More

March 5, 2013

Export Query Results to CSV by using SQLCMD

This is indeed very easy process and very simple command to export any query data. For example we will use AdventureWorks2012 database. Here is the query we will be using for our demonstration.
USE AdventureWorks2012
GO
SELECT TOP 10 sp.BusinessEntityID,sp.TerritoryID, sp.SalesQuota,sp.Bonus, sp.CommissionPctFROM Sales.SalesPerson sp
GO
The above query will return following result set.
Now we can export above data to CSV using SQLCMD using following command.
SQLCMD -S . -d AdventureWorks2012 -Q “SELECT TOP 10 sp.BusinessEntityID, sp.TerritoryID, sp.SalesQuota, sp.Bonus, sp.CommissionPct FROM Sales.SalesPerson sp” -s “,” -o “e:\result.csv”
Generically you can use the following syntax:
SQLCMD -S YourSQLServer -d YourDatabase -U YourUserName -P YourPassword -Q “Your Query” -s “,” -o “C:\Yourfilename.csv”
Now you can go to your file location and open the file and you will see that new csv file created there. When you open the csv file you will notice the results of the query.
Read More

March 1, 2013

New Faster & Lighter Facebook Like Box

If you have the Facebook Like box embedded in your website, the good news is that the plugin should have little impact on the performance, or page speed, of your pages.
Stoyan Stefanov of the Facebook engineering team shares that the updated Like box is 2-4x faster and is considerably lighter than the previous version. The Facebook Like plugin now loads in 0.5 seconds, as opposed to 2.3 seconds and while the previous version was 245KB in size, it now weighs a mere 46KB.
Facebook Like Box - Old
Earlier, Facebook Like box made 24 web requests and would load in 2.4 seconds
Facebook improved the performance of the plugin by switching to inline CSS styles (as opposed to using external stylesheets) and by squeezing multiple scripts into one – the plugin thus has to make fewer web requests.
Facebook Like Box - New
Facebook Like box now loads in .7 seconds and makes just 13 requests (for photos)
How do you get the faster Facebook Like box for your website? First, does the Facebook embed code on your website look anything like this?
XFBML version (old)
<script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script>
<fb:fan stream="false" name="PAGE_NAME"></fb:fan>
IFRAME version (old):
https://www.facebook.com/plugins/fan.php?connections=10&name=PAGE_NAME
If your embed codes are different, you are covered as Facebook will automatically serve you the improved Like box. Else, you are using the older /deprecated version of the Facebook Like box  so head over to developers.facebook.com and generate the new embed codes.
Read More

February 28, 2013

HTML 5 Web Storage

In this article we are going to see some good stuff and example of Web Storage. We are developing TODO list for the individual. All the TODO data will be stored in your local browser.
Learning any new stuff with example always helps us to understand it very deeply. So here we have used TODO list example.

Above screenshot is what we are going to develop. Let me give you basic idea about our requirement.
1) Notes should be stored and retrieved very quickly.
2) Notes should be filter with Category.
3) Notes should be color with different category
4) Notes should be removed if user wants.

Use of Web Storage:

Web storage can hold data in MBs. It can hold 2.5 to 10 MB of data depending on browsers. you can even test yourself. Although i have never tried it but some wiki documents provides such data.
Let we start with providing you basic operations like add/update/delete on web storage data. After getting idea about basic concept we will create simple TODO application as shown in above screen. We have used CSS and Javascript to make it like professional application. We will take code snippet from our example to present basic operations.
1) Add new item in Web Storage
 var storage = JSON.parse(localStorage.getItem('ToDoList')); 
            if (!storage) { 
                storage = []; 
                localStorage.setItem('ToDoList', JSON.stringify(storage));
            } 
As you can see in above code we have used localStorage.getItem to check if 'ToDoList' key is exist in the local storage for particular browser.
Secondly, We are using JSON.parse to get array data. We need to store TODO category and information. we have used single dimensional array for datastorage. JSON.parse is used to convert array data into string repesentation. AndJSON.Stringify can be used to convert array into string representation to store it back in local storage.
you need to keep it in mind that Web storage can hold only string data.
2) Update item in Web Storage
localStorage.setItem method in the first code snippet can be used to update item in the web storage. if you have existing key ToDoList in the web storage then it will update it's data specified by second parameter.
3) Remove item in Web Storage
var storage = JSON.parse(localStorage.getItem('ToDoList'));
storage.splice(itemId - 1, 2);
localStorage.setItem('ToDoList', JSON.stringify(storage));  
In our case we need to remove item from the array list. we have one dimensional array to store category and it's note value. category will be stored in all odd indexes while todo notes will be stored in all even indexes. We need to remove two item from array to remove particular notes.
In given example we have used splice to remove from the array. first parameter of splice define index from where we need to remove item while the second parameter defines number items we need to be removed.
And at last we have update array list. if we are not using array and if we have single key/value pair for storing in web storage then we can use removeItem method of localStorage.
Hope this information is enough to start working with web storage of html5. Now we will see the code for creating your personal todo list.

Important Code:

        function loadNotes() {
            var storage = JSON.parse(localStorage.getItem('ToDoList'));
            if (!storage) {
                storage = [];
                localStorage.setItem('ToDoList', JSON.stringify(storage));
            }
            var displayArea = document.getElementById("displayArea");
            var currentFilter = document.getElementById("slSearchCategory").value;
            var innerDiv = "";
            for (var i = storage.length - 1; i >= 0; i = i - 2) {
                if (currentFilter == storage[i - 1] || currentFilter == "") {
                    var todoColor = 'AD7460';
                    switch (storage[i - 1]) {
                        case 'HR':
                            todoColor = '90CA77';
                            break;
                        case 'Payroll':
                            todoColor = '81C6DD';
                            break;
                        case 'Sales':
                            todoColor = 'F9D654';
                            break;
                        case 'Personal':
                            todoColor = 'AD7460';
                            break;
                        default:
                            todoColor = 'AD7460';
                            break;
                    }
                    innerDiv += "<div class='displayToDo'  style='background:#" + todoColor + "'><input type='image' src='delete.png' width='15px' height='15px' onclick='removeMe(" + i + ")' /> Category : " + storage[i - 1] + " <hr /> " + storage[i] + "</div>";
                }
            }   
 
            if (innerDiv != undefined) {
                displayArea.innerHTML = innerDiv;
            }
            else {
                displayArea.innerHTML = "";
            }   
First of all we are taking all the todo that we have stored in the array called ToDoList. Once we have data we are ready to render data on the html page. we have one static div with id='displayArea'. Then for each item in the array we will iterate and check for the category of particular todo item. According to category we will assign hex color value into one variable. once we are ready with the color hex code we are dynamically creating html divs. Once we have ready html code we can set as innerHtml.
At last we have added condition to check if innerDiv value is updated with some dynamic data or not. In case of empty web storage array innerDiv value will be undefined.
function SaveNotes() {
            var category = document.getElementById("slSearchCategory").value;
            var todo = document.getElementById("txtToDo").value;

            if (category == "") {
                alert("Please select Category.");
                return;
            }

            var storage = JSON.parse(localStorage.getItem('ToDoList'));
            var arrayLength = storage.length;

            storage[arrayLength] = category;
            storage[arrayLength + 1] = todo;
            localStorage.setItem('ToDoList', JSON.stringify(storage));
            category = "";
            loadNotes();
            clearNote();
        } 
Above Javascript function will be called when you click on the 'Add TODO' button. We need the category and todo note as input from the dropdown list and textArea respectively. After getting data we have added validation to check if user have clicked button without selecting correct category. Once you have correct data you are ready to add new item into the web storage array. And last two steps is to load Notes again and Clear the TextArea(todo that you have entered).
We have also used some CSS3 features to display round corner div. this will really help to designer. when we do not have CSS3 we need to do a lot of work to handle such situation.
 .displayToDo
        {
            -moz-border-radius: 10px<span class="code-none">;
            border-radius<span class="code-none">: 10px<span class="code-none">;
            height<span class="code-none">: Auto<span class="code-none">;
            width<span class="code-none">: 200px<span class="code-none">;
            color<span class="code-none">: #ffffff<span class="code-none">;
            float<span class="code-none">: left<span class="code-none">;
            margin<span class="code-none">: 10px<span class="code-none">;
            padding<span class="code-none">: 10px<span class="code-none">;
        <span class="code-none">} </span></span></
As you can see in the above CSS code we have displayToDo CSS class. if you have observed we are applying this CSS class to dynamically generated div. This style will be applied immediately when DOM will be updated with given innerHTML dynamic text. 
Read More

© 2011-2016 Techimpulsion All Rights Reserved.


The content is copyrighted to Tech Impulsion and may not be reproduced on other websites.