For smart Primates & ROBOTS (oh and ALIENS ).

Blogroll

Thursday, January 22, 2015

argument replace with string in javascript function dynamic

Problem:

Some time you want to generate dynamic button or any other control which have a click event or any other event. in that event you are replacing that's function arguments with a string value and integer value. The string value which you want to replace must be covered with double quotes "...".
See the Listed below the example:

var tr='<input type="button" value="View" onclick="sh_co(snm ,sno);" />';
you want to see the above statement as below at runtime:
<input type="button" value="View" onclick="sh_co("cpu" ,1234);"/>

Here you can notice that snm replaced with "cpu" string and sno replace as a integer 1234;
when you try to replace those string double quotes value with replace function then you will get un expected result.

So how to overcome this problem?

Solution:

To solve this problem you will use code of double quotes (") in two types. I have described this in below two examples.

The code of double quotes is &quot;

Example:



Example- 1
var tr='<input type="button" value="View" onclick="sh_co(&quot;snm&quot; ,sno);" />';
tr=tr.replace(/snm/g,"cpu");
tr=tr.replace(/sno/g,1234);

Now you can get the result as below at runtime:
<input type="button" value="View" onclick="sh_co("cpu" ,1234);"/>


Example- 2
var tr='<input type="button" value="View" onclick="sh_co(snm,sno);" />';
tr=tr.replace(/snm/g,"&quot;cpu&quot;");
tr=tr.replace(/sno/g,1234);

Now you can get the result as below at runtime:
<input type="button" value="View" onclick="sh_co("cpu" ,1234);"/>


 

Share:

Tuesday, January 20, 2015

mpdf watermark image is front of text problem

Problem:

Some time working with watermark in MPDF you can see that watermark will show in front of texts or images in the PDF document, So how put the watermark image back side of texts or images in the PDF document.

Solution:

To overcome this problem use watermarkImgBehind property to true

Example:

$mpdf->watermarkImgBehind = true;
Share:

Sunday, January 18, 2015

android.os.NetworkOnMainThreadException

Problem:

The runtime this error 
android.os.NetworkOnMainThreadException
at android.os.StrictMode$AnroidBlockGuardPolicy.onNetwork(StrictMode.java
is the common error when working with online activity work in android.
how to remove it?

Solution:

You need to put below lines to solve this:
StrictMode.ThreadPolicy thpolicy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(thpolicy);

Example:

Use below code after setContentView(..);

setContentView(R.layout.activity_main);
if (android.os.Build.VERSION.SDK_INT > 9) {
StrictMode.ThreadPolicy thpolicy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(thpolicy);
}

And also use below code before  onCreate(..)

@SuppressLint("NewApi")
@Override
protected void onCreate(Bundle savedInstanceState) {...}
Share:

unable to start activity ComponentInfo MainActivity java.lang.NullPointer Exception

Problem:

While working with Android you can face the error
Fatal Exception:java.lang.RuntimeException:unable to start activity ComponentInfo
MainActivity : java.lang.NullPointer Exception
So how to overcome this run time error in android?

Solution:

This type of error is occurs when you trying to access android control Button or
EditText before set main activity. so first set you activity and then after it access the control

Example:

Do not use as belowloginBtn = (Button)findViewById(R.id.button1);
u_login = (EditText)findViewById(R.id.editText1);
setContentView(R.layout.activity_main);

Use as belowsetContentView(R.layout.activity_main);
loginBtn = (Button)findViewById(R.id.button1);
u_login = (EditText)findViewById(R.id.editText1);








Share:

Thursday, January 15, 2015

TypeError e is undefined in jquery json

Problem:

jQuery is good JavaScript library. It provide lot of facilities,one of famous facility is it's Ajax. but some time you can get a error message "TypeError e is undefined" or "TypeError: e is undefined" in jQuery Ajax error "TypeError: e is undefined" specially when working with Ajax and JSON.
Normally it occurs when you trying to access a variable without  defined or declare in JavaScript. But when you declare all the variable and error still coming then how to remove it?

Look below code:

In file1.php file

----------------------------------------------------------------------
$c_id=$_GET['c_id'];
$s_id=$_GET['s_id'];
// get result from Database
$rs=$util->get_all_code($c_id, $s_id) ;
$rows = array();
while ($row = $rs->fetch_array(MYSQLI_BOTH)) {
     $rows[]=$row;
}
print '{"All_codes":'. json_encode($rows).'}';
----------------------------------------------------------------------
Keep not that "All_codes" is the top heading array in the above JSON result. And you will use that "All_codes" in jQuery result fetch loop as below code:

 In file2.php file

----------------------------------------------------------------------
 $.ajax({
                type: 'GET', async: false, cache: false, timeout:5000, url: 'ajax_util.php',
                data: { c_id: 1,s_id:2 },
                dataType: 'json',
                success: function (data) {
                                                         $.each(data.All_code, function(idx, obj) {
                                                            var nm=obj.nm;
                                                         });
                                                       }
});
Keep in mind that you have used "All_code" instead of "All_codes"
----------------------------------------------------------------------

Solution:

It's solution is re-again check the variable name in JSON result in PHP and jQuery.

Example:

In file1.php file

----------------------------------------------------------------------
$c_id=$_GET['c_id'];
$s_id=$_GET['s_id'];
// get result from Database
$rs=$util->get_all_code($c_id, $s_id) ;
$rows = array();
while ($row = $rs->fetch_array(MYSQLI_BOTH)) {
     $rows[]=$row;
}
print '{"All_codes":'. json_encode($rows).'}';
----------------------------------------------------------------------

 In file2.php file

 $.ajax({
                type: 'GET', async: false, cache: false, timeout:5000, url: 'file1.php',
                data: { c_id: 1,s_id:2 },
                dataType: 'json',
                success: function (data) {
                                                         $.each(data.All_codes, function(idx, obj) {
                                                            var nm=obj.nm;
                                                         });
                                                       }
});
Keep in mind that you have used "All_codes"



Share:

Get current right time in php

Problem:

Some times when you print current date using  $mydatetime=date("Y-m-d H:i:s"); or print current time using echo $mytime = date("H:i:s");  in php then you will wonder that it will show wrong date time to you. so how you will show correct current date time in php?

Solution:

PHP will not set by default your current timezone, so that's the reason it will show you wrong date time. to show correct current date time in php you need to set your timezone by date_default_timezone_set function.

Example:

Suppose you are Indian then you will use:
date_default_timezone_set('Asia/Culcutta');
$curr_date_time = date("Y-m-d H:i:s");
echo $curr_date_time;
$curr_time = date("H:i:s");
echo $curr_time;
Suppose you are American then you will use:
date_default_timezone_set('America/Los_Angeles');
$curr_date_time = date("Y-m-d H:i:s");
echo $curr_date_time;
$curr_time = date("H:i:s");
echo $curr_time;


and so on set as your timezone as you require.

Share:

Thursday, January 08, 2015

Paragraph overlapping problem in itextsharp

Problem:

If you are working with itextSharp in Dot net winform C# or VB.net then you are very familiar with Paragraph. if  Paragraph font size is big then the Paragraph text will overlap as below example image.

Paragraph overlapping problem in itextsharp
Paragraph overlapping problem in itextsharp


So  how to overcome this problem?

Solution: 

To overcome paragraph text overlapping problem in itextsharp you will use  Paragraph SpacingAfter property.

Example:

Use below C# code, you can convert it into VB.net code if you are working in VB.net.

Paragraph para= new Paragraph("This is a test");
para.Alignment = Element.ALIGN_CENTER;
para.SpacingAfter=50f;
doc.Add(para);
Share:

Wednesday, January 07, 2015

Fatal error: Class PHPExcel_Reader_excel2007 not found in IOFactory.php

Problem:

While working with PHPExcel you can get the following error:
Fatal error: Class 'PHPExcel_Reader_excel2007' not found in IOFactory.php

Solution:

The main reason is you are using "excel2007" or "excel5"
You need to use "Excel2007" or "Excel5" instead of "excel2007" or "excel5"
Please not that difference between "e" and "E".

Example:

Use as below:
$objReader = PHPExcel_IOFactory::createReader('Excel2007');//Excel2007 or Excel5
Share:

ajax in jquery

The simple way to use ajax in jquery is below:

$.ajax({
        type: 'GET', async: false, cache: false, timeout:5000, url: 'ajax_util.php?'+new Date().getTime(),
        data: { f_for: 'get_topic_by_lesson_id',lesson_id:1},
        dataType: 'json',
        success: function (data) {    
            $.each(data.get_topic, function(idx, obj) {
                var topic_id=obj.topic_id;
                var topic_nm_val=obj.topic_nm;
            $('#topic_nm').append('<option value="' + topic_id + '">' +topic_nm_val+ '</option>'); 
            });
        }
    });

The problem is that here we are passing type, async,cashe timeout,data and dataType each time. so can we short cut it? yes we can shortcut it as below:

var variableAndValue={f_for: 'full_test',class_id:class_id,subject_id:subject_id };
var data=myajaxGetJSON('ajax_util.php?'+new Date().getTime(),variableAndValue);

Definition of  myajaxGetJSON function is as below:

function myajaxGetJSON(url,f_for) {
     var result="";
     $.ajax({
        type: 'GET', async: false, cache: false, timeout:5000, url: url,
        data: f_for,
        dataType: 'json',
        success: function (data) {
        result = data;    
        }
    });
    return result;
}
In above function you can use POST instead of GET method.

How use above function?

var class_id=1;
var  subject_id=1;
var variableAndValue={f_for: 'get_emp',class_id:class_id,subject_id:subject_id };
var data=myajaxGetJSON('ajax_util.php?'+new Date().getTime(),variableAndValue);
$.each(data.list_of_emp, function(idx, obj) {
//////   the obj variable is holding all the data
        var q_id=obj.q_id;
        var question_parts=obj.question_parts;
        var question_path=obj.question_path;
        var mark=obj.mark;
});

What about in the 'ajax_util.php'  

$f_for=$_GET['f_for'];
if($f_for=="get_emp") {
        $class_id=$_GET['class_id'];
        $subject_id=$_GET['subject_id'];
        $rs=$full_test->get_one_full_book_random($class_id,$subject_id,$marks,$not_ids);
        // The $rs is holding the data result set from mysql
        $rows = array();
        while ($row = $rs->fetch_array(MYSQLI_BOTH)) {
            $rows[]=$row;
        }
        print '{"list_of_emp":'. json_encode($rows).'}';
}






Share:

Post data using curl

Problem:

How to post data using curl in php?

Solution:

You need to use  POST method in curl.

Example:

$str_to_post = "login=mylogin&pass=mypass";
$crl = curl_init('http://localhost/mysite/dologin');
curl_setopt($crl, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($crl, CURLOPT_POSTFIELDS,$str_to_post );
curl_setopt($crl, CURLOPT_RETURNTRANSFER, true);
$ans = curl_exec($crl);

Other example is:

$postdata = array(
    'login' => 'mylogin',
    'pass' => 'mypass',
    'logintype' => '1'
);
$crl = curl_init();
curl_setopt($crl, CURLOPT_URL, "http://localhost/mysite/dologin");
curl_setopt($crl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($crl, CURLOPT_POST, true);
curl_setopt($crl, CURLOPT_POSTFIELDS, $postdata);
$ans = curl_exec($crl);
Share:

Sunday, January 04, 2015

itextSharp.text.pdf.badpasswordException PdfReader not opened with owner password

Problem:

If you are using iTestShap in Dot net application and generating PDF with owner passward. After that you are trying to open that password protected in again in Dot net code then you may face the error or exception of itextSharp.text.pdf.badpasswordException PdfReader not opened with owner password.

Solution:

This is because you are not supplying the password while you opening that pdf file in itextsharp using PdfReader.

Example:

Creating Pdf file using owner password:

PdfWriter docWriter = PdfWriter.GetInstance(doc, new FileStream(pdfFileName, FileMode.Create));
byte[] OWNER = System.Text.Encoding.UTF8.GetBytes("mypassword");
docWriter.SetEncryption(null, OWNER, PdfWriter.ALLOW_PRINTING, PdfWriter.STANDARD_ENCRYPTION_128);

Now you are trying to open that file:

PdfReader pdfReader = new PdfReader(pdfFileName);

Correct code:

byte[] OWNER = System.Text.Encoding.UTF8.GetBytes("mypassword");
PdfReader pdfReader = new PdfReader(pdfFileName, OWNER);

So conclusion is that be sure you are supplying the password while opening the password protected file in PdfReader in C# or VB.net code:
Share:

Friday, January 02, 2015

KeyLogger

Problem:

Some time you want to tack the person keyboard that what keys are stroking on that keyboard?




Solution:

I have developed a application, so by this application you can achieve your target.
You can track user keyboard keys by this Key Logger Application. This will store all the key stroke of your keyboard and save in the text file, So you can see all the activities of user; what user is typing.



 

 

 

How to download it?

How to run this application?

It is simple , just double click on it and it will open and hide. it will run in background process. so no one see it.

Requirement of system:

To run this application you need to install Microsoft dot.net framework 3.5
Share:

Multiple attribute passing in querySelectorAll

Multiple attribute passing in querySelectorAll     Here I am demonstrating code to how to pass multiple attributes in querySelectorAll. <...

Ads Inside Post

Powered by Blogger.

Arsip