Wednesday, May 13, 2009

JQuery Mobile alert box open after completion of task

JQuery Mobile alert box open after completion of some task


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html class="ui-mobile">
<head>
<title>Products</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.css" />
<script src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
<script src="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.js"></script>
<link type="text/css" href="http://dev.jtsage.com/cdn/simpledialog/latest/jquery.mobile.simpledialog.min.css" rel="stylesheet" />
<link type="text/css" href="http://dev.jtsage.com/jQM-DateBox/css/demos.css" rel="stylesheet" />
<script type="text/javascript" src="http://dev.jtsage.com/cdn/simpledialog/latest/jquery.mobile.simpledialog.min.js"></script>
<script type="text/javascript" src="http://dev.jtsage.com/gpretty/prettify.js"></script>
<link type="text/css" href="http://dev.jtsage.com/gpretty/prettify.css" rel="stylesheet" />
</head>
<body class="ui-mobile-viewport">
<div data-role="page" data-theme="b" data-content-theme="d">
  <div data-role="header" data-position="inline" data-theme="b">
    <h1>Products Listing </h1>
    <a href="#" id="addToCartButton" onclick="addToCart();" data-role="button" data-icon="myapp-shopping" data-theme="c">Add to Cart</a>
</div>
    <div data-role="content">
        Open jQuery Mobile alert box after completion of some task.
    </div>
</div>
<script>
function openDialog(msg) {
    $(document).delegate('#
addToCartButton', 'click', function() {
    $(this).simpledialog({
        'mode' : 'bool',
        'prompt' : msg+"<br/><br/><br/><br/>",
        'useModal': true,
        'buttons' : {  'OK': {  click: function () {   }  } }
                    })
            });
}
function addToCart() {
    // task goes here.....
    var msg="Product added in you cart";
    openDialog(msg);
}
/*$(document).delegate('#addToCartButton', 'click', function() {
    var msg=addToCart();
    $(this).simpledialog({
    'mode' : 'bool',
    'prompt' : msg,
    'useModal': true,
    'buttons' : {
      'OK': {
        click: function () {
           
          //$('#dialogoutput').text('OK');
        }
      }
    }
  })
});*/
</script>
</body>
</html>










Wednesday, May 6, 2009

Read yahoo groups rss by curl and SimpleXmlElement in PHP

..< ?php
// Read yahoo groups rss by curl and SimpleXmlElement
// by Amit gaur  $url = "http://rss.groups.yahoo.com/group/tm_informatikleri/rss"; $req = curl_init(); curl_setopt($req, CURLOPT_URL, $url);
curl_setopt($req, CURLOPT_RETURNTRANSFER, 1);
$xml = curl_exec($req);
curl_close($req);
$doc = new SimpleXmlElement($xml, LIBXML_NOCDATA);
if(isset($doc->channel))
{
showRSS($doc);
}
function showRSS($xml)
{
echo "".$xml->channel->title."
";
$cnt = count($xml->channel->item);
for($i=0; $i<$cnt; $i++)
{
$url = $xml->channel->item[$i]->link;
$title = $xml->channel->item[$i]->title;
$desc = $xml->channel->item[$i]->description;
$pubDate=$xml->channel->item[$i]->pubDate;
echo ''.$title.'
'.$pubDate.'
'.$desc. ' '. $guid. '

';
}
}
?>

How to send email from Gmail in Java.

import java.io.*;
import java.net.InetAddress;
import java.util.Properties;
import java.util.Date;
import javax.mail.*;
import javax.mail.internet.*;

// Created by Amit Gaur May-4-2009

// How to send email from Gmail in Java

public class GMail
{
public static void main(String ss[])
{
String host = "smtp.gmail.com";
String username = "a";// Put here only Gmail username not full email id
String password = "amitamit";// Put here Gmail password
int i;
i=1;
try
{
Properties props = new Properties();
props.put("mail.smtps.auth", "true");
//props.put("mail.from", "a@gmail.com");
props.put("mail.from",""); // put here from full gmail email id
Session session = Session.getInstance(props, null);
Transport t = session.getTransport("smtps");
t.connect(host, username, password);
MimeMessage msg = new MimeMessage(session);
msg.setFrom();
//msg.setRecipients(Message.RecipientType.TO, "a@gmail.com");
msg.setRecipients(Message.RecipientType.TO, ""); // put here receiver mail id

msg.setSubject("hello amit"+i);
msg.setSentDate(new Date());
msg.setText("Hello, Hi!"+i);
t.sendMessage(msg, msg.getAllRecipients());

}
catch(Exception ee)
{
System.out.println(ee.toString());
}
}
}

Tuesday, October 14, 2008

How to use getParameter on jsp page in liferayportlet

How to use getParameter on jsp page in liferayportlet

First you need to import this liferayportlet package in your JSP page:

<%@ page import="com.liferay.portal.util.PortalUtil" %>

HttpServletRequest myReq = PortalUtil.
getOriginalServletRequest(PortalUtil.getHttpServletRequest(renderRequest));
String myid = myReq.getParameter("myid")
;
out.println("myid="+myid);

Thursday, September 18, 2008

Create new HttpServletRequest object in Servlet

Create new HttpServletRequest object in Servlet

Sometimes you not need to use default object of HttpServletRequest in Servlet, you need to create new object of HttpServletRequest, in this situation you can use listed below code to create new object of HttpServletRequest. in this code just use default object " request" of HttpServletRequest in "doPost" or "doGet" method.



public void doPost(HttpServletRequest request, HttpServletResponse res)
        throws IOException, ServletException {

HttpServletRequest hsr = (HttpServletRequest) request;
// now use hsr

}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

public void doGet(HttpServletRequest request, HttpServletResponse res)
        throws IOException, ServletException {

HttpServletRequest hsr = (HttpServletRequest) request;
// now use hsr

}

Wednesday, September 10, 2008

Download image without cURL and with cURL

Download image without cURL and with cURL

<?php
// without cURL
$downloadImageUrl="http://fc04.deviantart.net/fs26/f/2008/072/b/1/Frozen_Galaxy_by_Vpr87.jpg";
////// Using without CURL
$img = file_get_contents($downloadImageUrl);
$file1 = dirname(__file__).'/aaa.jpg';
file_put_contents($file1, $img);



////// // with cURL
$fileName=$downloadImageUrl;
$header = array(
            "Accept-Encoding: gzip,deflate",
            "Accept-Charset: utf-8;q=0.7,*;q=0.7",
            "Connection: close"
        );
$useragent = 'Amit Kumar Gaur a@gmail.com  http://amitkgaur.blogspot.com';
$file2 = dirname(__file__).'/bbb.jpg';
$curlObj=curl_init();
curl_setopt($curlObj, CURLOPT_HTTPHEADER, $header);
curl_setopt($curlObj, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curlObj, CURLOPT_HEADER, false);
curl_setopt($curlObj, CURLOPT_USERAGENT, $useragent);
curl_setopt($curlObj, CURLOPT_CONNECTTIMEOUT, 999);
curl_setopt($curlObj, CURLOPT_TIMEOUT, 9999);
curl_setopt($curlObj, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($curlObj, CURLOPT_URL, $downloadImageUrl);
$response = curl_exec($curlObj);
$return = false;
if(!curl_errno($curlObj)) {
    file_put_contents($file2, $response);
}










Wednesday, April 23, 2008

Show confirm message during browser window close.


Here is the code that will show a confirmation message if user want to close browser window/close.




<form name="form1" id="form1">
     <input type="submit" name="btn1" value="Submit1" onclick="return chk();">
 </form>
 <form name="form2" id="form2">
     <input type="submit" name="btn1" value="Submit2">
</form>
<script language="javascript">
    var fillout = false;
    window.onbeforeunload=function verifyclose() {
        var undefined;
        var msg;
        if (document.forms[0] == undefined)
            return;
        if (!fillout) {
            msg = " Do you want quit/close this window?";
        }
        return msg;
    };   
   
    function chk() {
        return false;   
    }
 </script>

Thursday, November 22, 2007

Paging in CodeIgniter PHP

Paging in CodeIgniter PHP


CONTROLLER

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class City extends CI_Controller {
    public function __construct() {
        parent:: __construct();
        $this->load->helper("url");
        $this->load->model("Cities");
        $this->load->library("pagination");
    }
    public function index() {
        $this->load->view('welcome_message');
    }
    public function page() {
        $config = array();
        $config["base_url"] = base_url() . "city/page";
        $config["total_rows"] = $this->Cities->city_record_count();
        $config["per_page"] = 20;
        $config["uri_segment"] = 3;
        $this->pagination->initialize($config);
        $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
        $data["results"] = $this->Cities->fetch_cities($config["per_page"], $page);
        $data["links"] = $this->pagination->create_links();
        $this->load->view("city_view", $data);
    }
}


MODEL

<?php class Cities extends CI_Model {
    public function __construct() {
        parent::__construct();
        $this->load->library('pagination');
        $this->load->database();
    }
    public function city_record_count() {
        $this->db->where('city_id >', 10);
        $this->db->from('cities');
        return $this->db->count_all_results();
        //return $this->db->count_all("cities");
    }

    public function fetch_cities($limit, $start) {
        $this->db->limit($limit, $start);
        $this->db->where('city_id >', 10);
        $this->db->order_by("city_name", "asc");
        $query = $this->db->get("cities");
        if ($query->num_rows() > 0) {
            foreach ($query->result() as $row) {
                $data[] = $row;
            }
            return $data;
        }
        return false;
   }
}



VIEW

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Welcome to CodeIgniter</title>
</head>
<body>
 <div id="container">
  <h1>Cities</h1>
  <div id="body">
<?php
foreach($results as $data) {
    echo $data->city_id . " - " . $data->city_name . "<br>";
}
?>
   <p><?php echo $links; ?></p>
  </div>
  <p class="footer">Page rendered in <strong>{elapsed_time}</strong> seconds</p>
 </div>
</body>
</html>

Tuesday, November 20, 2007

config.getServletContext().getRealPath() is not working

config.getServletContext().getRealPath() is not working

This is the very common problem in Servlet and JSP while you deploy WAR file in tomcat or any other server. to over come this problem just extract the .WAR file in the "tomcat/webapps" directory.
and problem will be solved.


Wednesday, November 14, 2007

Sort Alphanumeric Data in Real Number in Sql

Sort Alphanumeric Data in Real Number in Sql


Suppose you have a table with columns pID Autonumber, registrationNo varchar(50) ,pName varchar(100)
registrationNo value is the first character is alphabets and rest is the number listed below:


pID registrationNo
1,    A1315
2,    A1
3,    A132
4,    A2
5,    A1316
6,    A1317
7,    A1318
8,    A133
9,    A1330
10,   A1331
11,   A3
12,   A1450
13,   A4
14,   A5643
15,   A5
16,   A1390
17,   A6


My client want to see those records in ascending number order as listed below order:
pID registrationNo
2,    A1
4,    A2
11,   A3
13,   A4
15,   A5
17,   A6
3,    A132
8,    A133
9,    A1330
10,   A1331
1,    A1315
5,    A1316
6,    A1317
7,    A1318
16,   A1390
12,   A1450
14,   A5643


but when retrieve the order by registrationNo. records was coming in ascending order,
because registrationNo are not a integer data type , those are Alphanumeric data type.

So how to show the Alphanumeric data in real ascending number order?
I have solved this problem with using listed below Sql. listed below sql will show the records which start with character 'a' :

SELECT pID,CAST(SUBSTRING(registrationNo, 2, 10) AS INT) as registrationNoNew
FROM [patientdb].[dbo].[Patients] where registrationNo like '%a1%' order by registrationNoNew


Tuesday, November 13, 2007

Failed to create sessionFactory object.org.hibernate.MappingException Could not get constructor for org.hibernate.persister.entity.SingleTableEntityPersister Exception in thread main java.lang.NullPointerException

You can face this problem during Java Hibernate application development:

Failed to create sessionFactory object.org.hibernate.MappingException: Could not get constructor for org.hibernate.persister.entity.SingleTableEntityPersister
Exception in thread "main" java.lang.NullPointerException



Solution:
The most common mistake is that you have you have
missed any one getXXXX() or setXXXX() methods.

So check again your code and make the missed getXXXX() or setXXXX() methods.

Wednesday, October 24, 2007

Send Files to IP address in C#


 Send Files to IP address in C#
=============================

string sourceDir = @"C:\\tt";
string destIP = @"\\10.10.10.10\shared-folder-amit";
string[] sourceFiles = Directory.GetFiles(sourceDir, "*", SearchOption.AllDirectories);
foreach (string files in sourceFiles) {
  string localFile = files.Replace(sourceDir, "");
  if (!Directory.Exists(Path.GetDirectoryName(destIP + "\\" + localFile)))
    Directory.CreateDirectory(Path.GetDirectoryName(destIP + "\\" + localFile));
  File.Copy(files, destIP + "\\" + localFile, true);
}

Tuesday, October 16, 2007

Image rotate in jQuery

Image rotate in jQuery



<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
</head>
<body>
<img style="transform: rotate(285.4deg);" id="myimg"  src="WOW.jpg">
<script type="text/javascript">
    jQuery(function($) {
        $(document).ready(function() {
            window.imagerotate = function () {
                $('#myimg').rotate({
                                angle:0,
                                animateTo:-360,
                                callback: imagerotate,
                                //t: current time,b: beginning value,c: change in value,d: duration
                                easing: function (x,t,b,c,d) {
                                    return c*(t/d)+b+10000;
                                }
                            });
                        };
                        setTimeout('imagerotate()', 1000);
                });
});
</script>
</body></html>

Thursday, September 20, 2007

Floating effect with jQuery

Floating effect with jQuery

Listed below the code for how to make any object float-able in html webpage .

aa.html

<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<script>
//jqfloat.js
(function(e){var t={init:function(t){return this.each(function(){e(this).data("jSetting",e.extend({},e.fn.jqFloat.defaults,t));e(this).data("jDefined",true);var n=e("<div/>").css({width:e(this).outerWidth(true),height:e(this).outerHeight(true),"z-index":e(this).css("zIndex")});if(e(this).css("position")=="absolute")n.css({position:"absolute",top:e(this).position().top,left:e(this).position().left});else n.css({"float":e(this).css("float"),position:"relative"});if((e(this).css("marginLeft")=="0px"||e(this).css("marginLeft")=="auto")&&e(this).position().left>0&&e(this).css("position")!="absolute"){n.css({marginLeft:e(this).position().left})}e(this).wrap(n).css({position:"absolute",top:0,left:0})})},update:function(t){e(this).data("jSetting",e.extend({},e.fn.jqFloat.defaults,t))},play:function(){if(!e(this).data("jFloating")){e(this).data("jFloating",true)}n(this)},stop:function(){this.data("jFloating",false)}};var n=function(t){var r=e(t).data("jSetting");var i=Math.floor(Math.random()*r.width)-r.width/2;var s=Math.floor(Math.random()*r.height)-r.height/2-r.minHeight;var o=Math.floor(Math.random()*r.speed)+r.speed/2;e(t).stop().animate({top:s,left:i},o,function(){if(e(this).data("jFloating"))n(this);else e(this).animate({top:0,left:0},o/2)})};e.fn.jqFloat=function(n,r){var i=e(this);if(t[n]){if(i.data("jDefined")){if(r&&typeof r==="object")t.update.apply(this,Array.prototype.slice.call(arguments,1))}else t.init.apply(this,Array.prototype.slice.call(arguments,1));t[n].apply(this)}else if(typeof n==="object"||!n){if(i.data("jDefined")){if(n)t.update.apply(this,arguments)}else t.init.apply(this,arguments);t.play.apply(this)}else e.error("Method "+n+" does not exist!");return this};e.fn.jqFloat.defaults={width:100,height:100,speed:1e3,minHeight:0}})(jQuery)
</script>
<script>
$(document).ready(function() {
    $('#nato').jqFloat({
        width:10,
        height:50,
        speed:1800
    });
   
    $('#butterfly').jqFloat({
        width:400,
        height:100,
        speed:3500
    });
});
</script>
</head>
<body>
<div id="nato" style="width:106px;height:105px;position:absolute;z-index:8;top:12%;right:15%"><img src="2.jpg"/></div>
    <div id="butterfly" style="width:35px; height:27px; position:absolute; z-index:20; left: 383px; top: 77px;"><img src="butterfly.JPG"/>
   </div>
</body>
</html>

Thursday, September 13, 2007

Date and Time with AM/PM Format in mysql

Date and Time with AM/PM Format in mysql:
use listed below sql:



SELECT DATE_FORMAT(my_entry_date_time, '%d/%M/%Y %r') FROM my_table