Thursday, September 3, 2009

Simple Html Editor

Simple HTML Editor

I have faced a new problem. client want WYSIWYG editor. there are lot of free HTML editor
available and I can use those very easily, but he don't want those , he want custom simple
HTML editor. so I have create the simple HTML editor. the entire code is listed below:


1) download latest jquery from it's site.

2) create a div

<div contenteditable="true" style="width:600px; height:150px; overflow:scroll; background-color:#CCC" id='my_text'></div>

3) create a textarea
<textarea name="my_text1" id="my_text1" style="display:none;"></textarea>

4) create a submit button.

5) and on click on submit button use this javascript code:
   var my_text=jQuery.trim($("#my_text").html());
   $("#my_text1").val(my_text);

6) and finally submit the form.

in server side code , I have used JSP here:

7) String my_text=request.getParameter("my_text").trim();


Thursday, August 6, 2009

Csv to Html generator

CSV to HTML Generator
==================================
The Csv to Html generator software is a robust software,that can generate html file(s) for each record
which are existing in the csv file. it take only three input A) CSV file B) Html template file
3) Destination directory.

The csv file must be comma separated.
Feature: You can double quotes in the records and in that record you can use comma.

Suppose you have listed below columns 15 in your csv file having many records

sku,standard-product-id,product-id-type,title,manufacturer,mfr-part-number,description,product_type,item-type,search-terms1,search-terms2,search-terms3,search-terms4,search-terms5,main-image-url


and you want to generate individually htnl file with predefined template for the listed below columns
for ex:
sku,product-id-type,manufacturer,description,search-terms2

0 for sku,
2 for product-id-type,
4 for manufacturer
6 for description
9 for search-terms1


then just create a listed below HTML template format file:
<html>
<body>
    Sku of item: [0], <br/>
    Product type  ID: [2], <br/>
    Manufacturer of item: [4] <br/>
    Description:  [6] <br/>
    Search terms 1: [9] <br/>
</body
</html>

Download Here

You need to install Dot Net Framework 4.0 distribution before  run to this Application.


Wednesday, July 8, 2009

Latest Posts

View here my latest posts.

Want to look my latest Posts? just Click here

Wednesday, June 24, 2009

Solid border of table

Solid border of table.


<!DOCTYPE html>
<html>
<head>
<style>
table
{
border-collapse:collapse;
}
table, td, th
{
border:2px solid red;
}
</style>
</head>

<body>
<table>
<tr>
<th>Test1</th>
<th>Test2</th>
</tr>
<tr>
<td>1</td>
<td>2</td>
</tr>
<tr>
<td>3</td>
<td>4</td>
</tr>
</table>
</body>
</html>

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.