Rahul Kumar
Friday, April 19, 2013
How to use with Cookies in Javascript.
function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}
function eraseCookie(name) {
createCookie(name,"",-1);
}
createCookie("username","rkumar670","30");
var val = readCookie("username");
output = rkumar670
eraseCookie('rkumar670');
Wednesday, April 10, 2013
LocalStorage
LocalStorage works mostly as you expect it; it’s a simple key-value-store with a finite amount of storage, and once you hit that you get an exception. But we got a really wierd bug report from a user where he would browse to another site, and come back to the application to find that all of his settings and data were gone.
Turns out that under some circumstances, Android doesn’t load the localStorage data when you hit the back button. I’m guessing it has something to do with the fact that Android doesn’t always reload the page when you go back, it loads it from the browser cache (not the application cache) instead.
So to get around this Android bug, we set a persistent value in localStorage which we use as a check to see if localStorage is correctly loaded.
var check = "1234567890"
localStorage.setItem("android_check", check);
and when we want to fetch something from localStorage, we do:
var hasItem = function() {
return (typeof localStorage[key] != "undefined" && localStorage[key] !== null);
}
var getItem = function(key, def) {
if (!hasItem(key)) {
if (localStorage.getItem("android_check") !== check) {
// Reload the page so Android reloads localStorage
window.location.reload();
}
return def;
}
return localStorage.getItem(key);
}
Saturday, March 16, 2013
Gmail Tip: Mark All Unread Mail as Read
I Have thousand of unread mails. it is time consuming to make all mails to read.
1.Go to your Settings/Filters page and create a new filter.
2. In the Has the words field enter “is:unread” (without quotes), and click the Next Step button
3.You’ll get a message warning you that this type of filter won’t be applied to new mail, but that’s OK. Click OK to continue.
4.Check the boxes next to Mark as read and Also apply filter to … conversations below.
5.Click Create Filter button, and you’re done. You might want to should delete the filter once you finish since it won’t be needing it anymore.
1.Go to your Settings/Filters page and create a new filter.
2. In the Has the words field enter “is:unread” (without quotes), and click the Next Step button
3.You’ll get a message warning you that this type of filter won’t be applied to new mail, but that’s OK. Click OK to continue.
4.Check the boxes next to Mark as read and Also apply filter to … conversations below.
5.Click Create Filter button, and you’re done. You might want to should delete the filter once you finish since it won’t be needing it anymore.
PhoneGap Android XhrFileReader
This post is copy from the simon macdonst blog this help me a lot in my one of the app.
The FileReader API works great as long as the file you want to read is on the device's file system. However if you want to read a file you've packed in the Android assets folder you would need to use XHR to read the file. I'm providing an interface that follows the same API as the regular FileReader. Of course the XhrFileReader is not limited to only reading files from the assets folder, it can also read files from the file system and over HTTP.
Adding the plugin to your project
To install the plugin, move XhrFileReader.js to your project's www folder and include a reference to it in your html files.
Using the plugin
To instantiate a new reader use the folling code:
Github: https://github.com/macdonst/XhrFileReader
The FileReader API works great as long as the file you want to read is on the device's file system. However if you want to read a file you've packed in the Android assets folder you would need to use XHR to read the file. I'm providing an interface that follows the same API as the regular FileReader. Of course the XhrFileReader is not limited to only reading files from the assets folder, it can also read files from the file system and over HTTP.
Adding the plugin to your project
To install the plugin, move XhrFileReader.js to your project's www folder and include a reference to it in your html files.
Using the plugin
To instantiate a new reader use the folling code:
var reader = cordova.require("cordova/plugin/xhrfilereader");Setup your event handlers:
// called once the reader beginsUnfortunately, you will only get an error on files read over HTTP. When you specify a file:// path the request status is always 0. There is no way to tell between a successful read or an error. So if you specify a file that does not exist like "file:///does.not.exist.txt" you will get an empty evt.target.result in your onloadend handler.
reader.onloadstart = function() {
console.log("load start");
};
// called when the file has been completely read
reader.onloadend = function(evt) {
console.log("File read");
console.log(evt.target.result);
};
// called if the reader encounters an errorProgress events are fired but are not very useful as they don't contain partial results.
reader.onerror = function(error) {
console.log("Error: " + error.code);
};
// called while the file is being readFinally call your read method, for instance:
reader.onprogress = function(evt) {
console.log("progress");
};
reader.readAsText("http://www.google.com"); reader.readAsText("file:///android_asset/www/config.json"); reader.readAsText("file:///sdcard/error.log");and that's about it. Obviously, this plugin is most useful when you need to read a text file from the assets folder.
Github: https://github.com/macdonst/XhrFileReader
How can I add older version of iOS SDK in Xcode
I create a Iphone app is working fine in the iOS 5.1 sdk but now in iOS 6.1 sdk. Then i update my Xcode to 4.6.1 now what happen i sort out the app issue but when i am trying to submit the app was trying to build the ipa file it gave an error
Apple Mach-o linker error
linker command failed with exit code 1 (use -v to see invocation)
Here is my solution note.
- Download xcode_4.4.1_6938145.dmg in https://developer.apple.com/downloads/
- Load up the dmg file then go to Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/ you will find iPhoneOS5.1.sdk (this is what i want in this case).
- Copy iPhoneOS5.1.sdk folder into your Xcode folder /Applications/Xcode/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs
- Restart Xcode
- Open Xcode project setting->build settings->base SDK, then you will see iOS 5.1 option.
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk
and iPhoneSimulator5.1.sdk to/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk
Now restart your Xcode change the iOS to 6.1 to 5.1 THen it will compile the app into your iPhone. if it is helpful then post a comment below.
Monday, July 23, 2012
what is the shortcut key in eclipse? ( Eclipse Shortcuts)
Essential
Shortcuts
The list of shortcuts in
Eclipse is fairly long yet readily available. In fact starting with Eclipse 3.1
the full list of shortcuts can be displayed from anywhere via Ctrl+Shift+L.
Nevertheless, call it information fatigue or simply a matter of style, deserving
shortcuts frequently remain overlooked.
Below is a list of those
shortcuts I find essential. What I mean by that is if you don't use them then
you probably need additional time to execute essential everyday tasks and are
not very comfortable navigating around.
So without further ado here
is the list:
Ctrl+Shift+T
|
Find Java Type
|
Start typing the name and
the list gets smaller. Try typing the capital letters of the class only (e.g.
type "CME" to find "ConcurrentModificationException")
|
||||||||||||||||||||||||||||||||||||||||||
Ctrl+Shift+R
|
Find Resource
|
Use this to look for XML
files, text files, or files of any other type. which are in your workspace.
|
||||||||||||||||||||||||||||||||||||||||||
Ctrl+E
|
Open Editor Drop-Down
|
Presents a popup window
listing currently opened files. Start typing to limit the list or simply use
the down arrow key.
|
||||||||||||||||||||||||||||||||||||||||||
Ctrl+O
|
Quick Outline
|
Use this to find a method
or a member variable in a class. Start typing to limit the choices. Press
Ctrl+O a second time to include inherited methods.
|
||||||||||||||||||||||||||||||||||||||||||
Ctrl+Space
|
Content Assist
|
Context sensitive content
completion suggestions while editing Java code.
|
||||||||||||||||||||||||||||||||||||||||||
Ctrl+Shift+Space
|
Context Information
|
If typing a method call
with several parameters use this to show the applicable parameter types. The
current parameter where the cursor is will be shown in bold.
|
||||||||||||||||||||||||||||||||||||||||||
Ctrl+Shift+O
|
Organize Imports
|
After typing a class name
use this shortcut to insert an import statement. This works if multiple class
names haven't been imported too.
|
||||||||||||||||||||||||||||||||||||||||||
F3
|
Open Declaration
|
Drills down to the
declaration of the type, method, or variable the cursor is on. This works
much like a browser hyperlink.
|
||||||||||||||||||||||||||||||||||||||||||
Alt+Left
|
Backward History
|
This works like a
browser's Back button.
|
||||||||||||||||||||||||||||||||||||||||||
Alt+Right
|
Forward History
|
This works like a
browser's Forward button
|
||||||||||||||||||||||||||||||||||||||||||
Ctrl+L
|
Go to Line
|
Go to a specific line
number.
|
||||||||||||||||||||||||||||||||||||||||||
F4
|
Open Type Hierarchy
|
Show the type hierarchy
(downward tree) or the supertype hierarchy (upward tree).
|
||||||||||||||||||||||||||||||||||||||||||
Ctrl+Alt+H
Ctrl+Shift+F
|
Open Call Hierarchy
|
Show where a method is
called from. In the Call Hierarchy view keep expanding the tree to continue
tracing the call chain.
Auto align the code
|
||||||||||||||||||||||||||||||||||||||||||
Ctrl+H
|
Open Search Dialog
|
Opens a search dialog
with extensive search options for Java packages, types, methods, and fields.
|
||||||||||||||||||||||||||||||||||||||||||
Alt+Shift+R
|
Rename - Refactoring
|
Use this to rename type,
method, or field. All existing references will be refactored as well.
|
||||||||||||||||||||||||||||||||||||||||||
Alt+Shift+L
|
Extract Local Variable
|
Use this to create a
local variable from the selected expression. This is useful for breaking up
larger expressions to avoid long lines.
|
||||||||||||||||||||||||||||||||||||||||||
Alt+Shift+M
|
Extract Method
|
Use this to extract a new
method from existing code. The parameter list and return type will be
automatically created.
|
A few things to keep in
mind as you try the above shortcuts. If a shortcut doesn't have the described
effect check if one of these is the cause of your problem:
·
Do you have an older version of Eclipse? Check the Help section to
confirm the shortcut is available.
·
Is the shortcut applicable to the context (perspective) you're in?
For example Ctrl+Shift+T (Open Type) is applicable in the Java perspective but
not in the Resource perspective. You can find out where each shortcut is
applicable by pressing Ctrl+Shift+L or by checking the Help section.
·
Is the shortcut already taken by another application? If so the
other application will probably come to the foreground when you use the
shortcut.
·
Is the shortcut defined twice in Eclipse? This can happen on
occasion if you install additional plugins with overlapping shortcuts or more
likely if you've tried to map shortcuts of your own. If there is conflict the
shortcut won't work. To check this go to the Preferences or press Ctrl+Shift+L
twice.
Friday, July 20, 2012
How to call .ashx file through jquery
your aspx page.
add the latest jquery into the head section
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
<script>
//document ready
$(function(){
$.ajax({
type: "POST",
url: "handler.ashx",
data: { firstName: 'Rahul', lastName: 'Kumar' },
// DO NOT SET CONTENT TYPE to json
// contentType: "application/json; charset=utf-8",
// DataType needs to stay, otherwise the response object
// will be treated as a single string
dataType: "json",
success: function (response) {
alert(response.d);
}
});
});
</script>
your handler.ashx file
using System;
using System.Web;
using Newtonsoft.Json;
public class Handler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
string myName = context.Request.Form["firstName"];
// simulate Microsoft XSS protection
var wrapper = new { d = myName };
// in order to use JsonConvert you have to download the
// Newtonsoft.Json dll from here http://json.codeplex.com/
context.Response.Write(JsonConvert.SerializeObject(wrapper));
}
public bool IsReusable
{
get
{
return false;
}
}
}
Subscribe to:
Posts (Atom)