Rss Feed Like Us on facebook Google Plus

March 14, 2013

Load Social Widgets Conditionally

The technique is simple. We calculate the width of the user’s screen /browser and if the width exceeds a particular value (say 480 pixels), we load the associated social widgets.

To implement conditional loading on your blog /website, first add all the necessary social widgets to your blog using the usual procedure. 

For instance, you can visit facebook.com to generate code for the Like button while dev.twitter.com will provides codes the Tweet and Follow widgets of Twitter.

Remove the JavaScript from these generated codes – everything that’s between the <script> tags – and add everything else to your website template. Then copy-paste the following snippet before the closing </body> tag of your website template.
  1. <script type="text/javascript"> (function(doc, script, minimum) {   // Calculate the width of the user's screen var browserWidth = window.innerWidth || doc.documentElement.clientWidth || doc.body.clientWidth;   // Load JavaScript only if the site is being viewed on a wide (non-mobile) screen if (browserWidth > minimum) {   var js, frag = doc.createDocumentFragment(), // Credit : Stoyan Stefanov of phpied.com js_queue = function(url, id) { if ( ! doc.getElementById(id) ) { js = doc.createElement(script); js.src = url; js.id = id; frag.appendChild(js); } }; // These are the most common social widgets, remove the ones you don't need js_queue ("https://apis.google.com/js/plusone.js", "googleplus-js"); js_queue ("//platform.twitter.com/widgets.js", "twitter-wjs"); js_queue ("//connect.facebook.net/en_US/all.js#xfbml=1","facebook-jssdk"); js_queue ("//platform.linkedin.com/in.js", "linkedin-js"); js_queue ("//assets.pinterest.com/js/pinit.js", "pinterest-js");   var fjs = doc.getElementsByTagName(script)[0]; fjs.parentNode.insertBefore(frag, fjs); }   // Set the minimum width here (default is 480 pixels) } ( document, 'script', 480 ) );   </script>

The above JavaScript code asynchronously loads all the popular social widgets – Twitter, Facebook, LinkedIn, Google+ and Pinterest – but you may remove the js_queue calls for widgets that you do not plan to use on your website. Save the changes and you are done.
Read More

March 13, 2013

Sony Xperia-Z Review

Sony launched the Xperia Z, its new flagship smartphone in the Indian market in the first week of March. The USP of the phone is its 5-inch 1080p HD display, in addition to its water and dust resistant build, and a 13.1-megapixel camera. It's the second phone after the HTC Butterfly, to feature a full-HD display. However, it's priced about Rs.7,000 cheaper than the Butterfly at Rs. 38,990. Sony is also trying its best foot forward in promoting the phone in the Indian market with a star-studded marketing campaign.

Comparisons
HTC Butterfly
HTC Butterfly features a 5-inch Super LCD III touch-screen with 441ppi pixel density and 1920x1080p resolution. The display is crisp and vivid, has good viewing angles and makes it a pleasure to watch videos and view just any content. What we do not like about its screen is that the colours wash out when seen under direct sunlight, even at full brightness. 

Sony Xperia ZA 5-inch TFT display is used in Sony Xperia Z; the keys are based on the display itself. The phone supports 1920x1080p resolution and 441ppi pixel density, same as the HTC Butterfly. The screen of this phone is as gorgeous as that of Butterfly but does not have the same contrast level. The two phones also share the poor sunlight legibility as well. 

BlackBerry Z10
Z10 comes with a 4.2-inch with 355ppi pixel density and 1280x768ppi pixel density. Despite the lower pixel density, the screen does not pale much in front of the other three. Moreover, it wins when it comes to sunlight legibility. However, it does lose out to them when it comes to full HD support and the video playback is not as beautiful either.
 
Nokia Lumia 920
Lumia 920 has a 4.5-inch IPS panel with PureMotion HD+ and ClearBlack display technologies. The pixel density of this screen is 332ppi and resolution is 1280x768p. Where the screen of Lumia 920 scores above all others is sunlight legibility as it remains clear and vivid and does not lose contrast at all when viewed during bright sunlight. But again, the lack of full HD support will pinch those who wish to view high resolution movies.

Though the screens of Nokia Lumia 920 and BlackBerry Z10 are very good, the full HD video playback was not as good as what we got with the two Android phones. The video was scaled down to suit the phone's native resolution and video quality was not life-like. If Lumia 920's touchscreen sensitivity is set as High in settings menu, you can operate the phone even while wearing gloves, a feature that will come in handy in colder climes.
FEATURES:
1. DISPLAY

A screen as impressive as HDTV – Full HD Reality Display

Feel like you’re there with the razor sharp and super bright full HD screen. Xperia Z brings you the highest level of HD available – 1080 progressive scan, for incredibly crisp pictures and no jagged edges. Expertise from our BRAVIA® TV engineers goes into our mobile screens, to bring you the same quality you’d expect from a top quality HDTV. The 5” full HD Reality Display also has very high pixel density – 443 pixels per inch, for razor sharp pictures – and superior brightness. And with the wide colour gamut it gives you the widest colour spectrum, so you can view every detail in vivid colour.
2. Camera

Exmor RS™ for mobile – the world’s first image sensor with HDR video for smartphones

HDR for photos and videos captures natural colours in any light. HDR (High Dynamic Range) is an imaging technology used to capture clear photos against strong backlight. With HDR, the camera captures the same image at different exposure levels and layers them to create one optimised photo.
Xperia Z introduces HDR to video, so that you can film even in high contrast situations, like in front of a window or with the sun behind your subject.
3. Design & Durability

Minimal yet distinctive – OmniBalance design

With Xperia Z, we introduce our new OmniBalance design. The design is focused on creating balance and symmetry in all directions. Xperia Z has subtly rounded edges and smooth, reflective surfaces on all sides, which are held together by an innovative skeleton frame.
Both the front and back are made of glass, with a seamless surface. Together with enhanced reflection coating on the top, bottom and sides, Xperia Z actually mirrors the world around you. OmniBalance design balances technology vs. design, letting you get so totally immersed in the content that the hardware disappears. 
4. Connectivity

One-touch connectivity from Sony

Sharing with friends and connecting your world has never been easier. Based on NFC (near field communication), our One-touch functions connect one device to another in a single tap. No wires, cables, or fiddling with settings necessary.
Read More

Cookies in Asp.Net

Introduction

Cookies are also known by many names, HTTP Cookie, Web Cookie, Browser Cookie, Session Cookie, etc. Cookies are one of several ways to store data about web site visitors during the time when web server and browser are not connected. Common use of cookies is to remember users between visits. Practically, cookie is a small text file sent by web server and saved by web browser on client machine.

Use of Cookies?

Cookies may be used for authentication, identification of a user session, user's preferences, shopping cart contents, or anything else that can be accomplished through storing text data. Cookies can also be used for traveling of data from one page to another.

Is Cookies Secured?

Well, this question has no specific answers in YES or NO. Cookies could be stolen by hackers to gain access to a victim's web account. Even cookies are not software and they cannot be programmed like normal executable applications. Cookies cannot carry viruses and cannot install malware on the host computer. However, they can be used by spyware to track user's browsing activities.

Using Cookies

Creating/Writing Cookies

There are many ways to create cookies, I am going to outline some of them below:

Way 1 (by using HttpCookies class)

//First Way
HttpCookie StudentCookies = new HttpCookie("StudentCookies");
StudentCookies.Value = TextBox1.Text;
StudentCookies.Expires = DateTime.Now.AddHours(1);
Response.Cookies.Add(StudentCookies);

Way 2 (by using Response directly)

//Second Way
Response.Cookies["StudentCookies"].Value = TextBox1.Text;
Response.Cookies["StudentCookies"].Expires = DateTime.Now.AddDays(1);

Way 3 (multiple values in same cookie)

//Writing Multiple values in single cookie
Response.Cookies["StudentCookies"]["RollNumber"] = TextBox1.Text;
Response.Cookies["StudentCookies"]["FirstName"] = "Abhimanyu";
Response.Cookies["StudentCookies"]["MiddleName"] = "Kumar";
Response.Cookies["StudentCookies"]["LastName"] = "Vatsa";
Response.Cookies["StudentCookies"]["TotalMarks"] = "499";
Response.Cookies["StudentCookies"].Expires = DateTime.Now.AddDays(1); 

Reading/Getting Cookies

In the above code, I have used many ways to write or create cookies so I need to write here using all the above ways separately.

For Way 1

string roll = Request.Cookies["StudentCookies"].Value; //For First Way

For Way 2

string roll = Request.Cookies["StudentCookies"].Value;  //For Second Way

For Way 3

//For Multiple values in single cookie
string roll;
roll = Request.Cookies["StudentCookies"]["RollNumber"];
roll = roll + " " + Request.Cookies["StudentCookies"]["FirstName"];
roll = roll + " " + Request.Cookies["StudentCookies"]["MiddleName"];
roll = roll + " " + Request.Cookies["StudentCookies"]["LastName"];
roll = roll + " " + Request.Cookies["StudentCookies"]["TotalMarks"];
Label1.Text = roll; 

Deleting Cookies

In the above code, I have used many ways to create or read cookies. Now look at the code given below which will delete cookies.
if (Request.Cookies["StudentCookies"] != null)
{
    Response.Cookies["StudentCookies"].Expires = DateTime.Now.AddDays(-1);
    Response.Redirect("Result.aspx");  //to refresh the page
}

Understanding HttpCookie Class It contains a collection of all cookie values.

We do not need to use any extra namespaces for HttpCookies class (we already have used this in Way 1 above), because this class is derived from System.Web namespaces. HttpCookies class lets us work with cookies without using Response and Request objects (we have already used this in Way 2 and Way 3 above).
image002.jpg  
HttpCookie class has a list of some properties, let us outline them.
  • Domain: It contains the domain of the cookie.
  • Expires: It contains the expiration time of the cookie.
  • HasKeys: It contains True if the cookie has subkeys.
  • Name: It contains the name of the cookie.
  • Path: It contains the virtual path to submit with the cookie.
  • Secure: It contains True if the cookie is to be passed in a secure connection only.
  • Value: It contains the value of the cookie.
  • Values:
Limitations of Cookies
There are following limitations for cookies:
  1. Size of cookies is limited to 4096 bytes.
  2. Total 20 cookies can be used on a single website; if you exceed this browser will delete older cookies.
  3. End user can stop accepting cookies by browsers, so it is recommended to check the users’ state and prompt the user to enable cookies.
Sometimes, the end user disables the cookies on browser and sometimes browser has no such feature to accept cookies. In such cases, you need to check the users’ browser at the home page of website and display the appropriate message or redirect on appropriate page having such message to enable it first. The following code will check whether the users’ browser supports cookies or not. It will also detect if it is disabled too.
protected void Page_Load(object sender, EventArgs e)
{
    if (Request.Browser.Cookies)
    {
        //supports the cookies
    }
    else
    {
        //not supports the cookies
        //redirect user on specific page
        //for this or show messages
    }
}
It is always recommended not to store sensitive information in cookies.
Read More

March 12, 2013

Cure Social Media Addiction

altSocial media has slowly crawled into our lives to become one of the most vital aspects of it in the past few years. Social media addiction has now become an emerging issue
and it may soon turn into a grave one if not curbed at the right time. Let’s take a look at few measures that’ll help you out in the long run!

1. Understand the Issue

alt
Image Credit: Shutterstock
Do you sit on a social media site like Facebook, Twitter, etc. endlessly at a stretch of 4-6 hours refreshing the page over and over again? Do you have no idea why you indulge in that meaningless task for hours without anything productive coming out of it? Beware; you’re slowly turning into a social media addict. The first step is to understand the issue and its magnitude.

2. Understand the Repercussions

alt
Image Credit: Shutterstock
Has something that has occurred on the medium affected you gravely at an emotional level? Have you been pondering over a certain altercation that went down between you and an accomplice on a site which has disrupted your thought pattern? These tend to be the symptoms that point towards social media addiction. Having it affect your day-to-day life reaffirms the impact it is causing over your thinking.

3. Set a Routine

alt
Image Credit: Thinkstock
The first step towards bringing the addiction to a halt is to keep a tab on the amount of time you spend on the sites. Usually addiction is detected when your surfing time starts eating into your work-time or family-time. To avoid that, dedicate a specific time-span that you’d spend on the social networking site on a daily basis. Going ‘Cold Turkey’ and completely shutting out social media networking may not work well and may backfire. To avoid that, set up a timetable and stick to it!

4. Substitute Social Media with a Hobby

alt
Image Credit: Thinkstock
The next step would be to create an equally captivating distraction for yourself, so that you deviate your mind from social media. Pick up a new hobby; revive a hobby that you once cheerfully cherished. Dedicate some of your networking time to it and go ahead. This’ll help you in keeping your mind busy and focused towards something useful and productive and will also assist in slowly easing you out of the social media addiction.

5. Don’t Prioritize

alt
Image Credit: Thinkstock
Never prioritize social media over anything else. Social media has to be the lowest on the priority list. The minute you start prioritizing social media over your job, your family, or your personal health, things start turning ugly. Avoid that. Social media is only a source of entertainment and should be done in your leisure time.
Read More

Insert Multiple Records with One Query and Get Count on the basis of GroupBY +SQL

SQL SERVER 2005

The GROUP BY statement is used in conjunction with the aggregate functions to group the result-set by one or more columns.


DECLARE @ProductDtls  TABLE(id INT, Department VARCHAR(30),Product VARCHAR(100))

--INSERT MULTIPLE RECORDS WITH ONE QUERY
INSERT INTO @ProductDtls (ID, Department, Product)
SELECT 1,'Electronics', 'Cameras & Video' UNION ALL
SELECT 2,'Electronics','Cameras & Video' UNION ALL
SELECT 3,'Electronics','Cell Phones & Accessories' UNION ALL
SELECT 4,'Electronics','Cell Phones & Accessories' UNION ALL
SELECT 5,'Electronics','Cell Phones & Accessories' UNION ALL
SELECT 6,'Electronics','Computers, Tablets & Laptops' UNION ALL
SELECT 7,'Electronics','Computers, Tablets & Laptops' UNION ALL
SELECT 8,'Fashion','Clothing & Accessories' UNION ALL
SELECT 9,'Fashion','Clothing & Accessories' UNION ALL
SELECT 10,'Fashion','Shoes' UNION ALL       
SELECT 11,'Fashion','Shoes' UNION ALL
SELECT 10,'Collectibles & Art','Antiques' UNION ALL
SELECT 11,'Collectibles & Art','Antiques' UNION ALL
SELECT 10,'Collectibles & Art','Antiques' UNION ALL
SELECT 11,'Collectibles & Art','Art' UNION ALL
SELECT 12,'Collectibles & Art','Art'

--SELECT ALL RECORDS
SELECT * FROM @ProductDtls

--GET COUNT ON THE BASIS OF GROUP RECORDS
SELECT Department, COUNT(T.Product) 'ProductCount' FROM
(SELECT DISTINCT Department, Product FROM @ProductDtls) T
GROUP BY Department
Read More

March 11, 2013

Difference Between Dispose vs Finalize

Introduction

We have been using the Dispose method for disposing objects in .NET. For the same purpose, we may also use the Finalize method. In this article I will try to explain what the Dispose and the Finalize methods are and where to use the Finalize and where to use the Dispose. I will also try to explain the difference between them.

Dispose
Garbage collector (GC) plays the main and important role in .NET for memory management so programmer can focus on the application functionality. Garbage collector is responsible for releasing the memory (objects) that is not being used by the application. But GC has limitation that, it can reclaim or release only memory which is used by managed resources. There are a couple of resources which GC is not able to release as it doesn't have information that, how to claim memory from those resources like File handlers, window handlers, network sockets, database connections etc. If your application these resources than it's programs responsibility to release unmanaged resources.

For example, if we open a file in our program and not closed it after processing than that file will not be available for other operation or it is being used by other application than they can not open or modify that file. For this purpose FileStream class provides Dispose method. We must call this method after file processing finished. Otherwise it will through exception Access Denied or file is being used by other program.

Close Vs Dispose

Some objects expose Close and Dispose two methods. For Stream classes both serve the same purpose. Dispose method calls Close method inside.

void Dispose() 
{ 
this.Close(); 
}

Here question comes, why do we need Dispose method in Stream. Having Dispose method will enable you to write below code and implicitly call dispose method and ultimately will call Close method.

using (FileStream file = new FileStream("path", FileMode.Open, FileAccess.Read)) 
{ 
//Do something with file 
} 
 
But for some classes both methods behave slightly different. For example Connection class. If Close method is called than it will disconnect with database and release all resources being used by the connection object and Open method will reconnect it again with database without reinitializing the connection object. However Dispose method completely release the connection object and cannot be reopen just calling Open method. We will have re-initialize the Connection object.

Creating Dispose
To implement Dispose method for your custom class, you need to implement IDisposableinterface. IDisposable interface expose Dispose method where code to release unmanaged resource will be written.

Finalize

Finalize method also called destructor to the class. Finalize method can not be called explicitly in the code. Only Garbage collector can call the the Finalize when object become inaccessible. Finalize method cannot be implemented directly it can only be implement via declaring destructor. Following class illustrate, how to declare destructor. It is recommend that implement Finalize and Dispose method together if you need to implement Finalize method. After compilation destructor becomes Finalize method.

public class MyClass:IDisposable 
{
//Construcotr 
public MyClass() 
{ 
//Initialization: 
}
//Destrucor also called Finalize 
~MyClass() 
{ 
this.Dispose(); 
}
public void Dispose() 
{ 
//write code to release unmanaged resource. 
} 
}

Using Finalize

Now question is, When to implement Finalize? There may be any unmanaged resource for example file stream declared at class level. We may not be knowing what stage or which step should be appropriate to close the file. This object is being use at many places in the application. So in this scenario Finalize can be appropriate location where unmanaged resource can be released. It means, clean the memory acquired by the unmanaged resource as soon as object is inaccessible to application.

Finalize is bit expensive to use. It doesn't clean the memory immediately. When application runs, Garbage collector maintains a separate queue/array when it adds all object which has finalized implemented. Other term GC knows which object has Finalize implemented. When the object is ready to claim memory, Garbage Collector call finalize method for that object and remove from the collection. In this process it just clean the memory that used by unmanaged resource. Memory used by managed resource still in heap as inaccessible reference. That memory release, whenever Garbage Collector run next time. Due to finalize method GC will not clear entire memory associated with object in fist attempt.

Conclusion

It is always recommended that, one should not implement the Finalize method until it is extremely necessary. First priority should always be to implement the Dispose method and clean unmanaged as soon as possible when processing finish with that.
Read More

© 2011-2016 Techimpulsion All Rights Reserved.


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