For smart Primates & ROBOTS (oh and ALIENS ).

Tuesday, April 19, 2016

how to fix Configure the viewport

How to fix Configure the viewport

Sometime when you increase score of your site in Google PageSpeed Insights for SEO purpose and optimize it's responsiveness you can face the issue Configure the viewport. It is simple to fix the Configure the viewport issue. use only this below meta tag. if you have already this similar meta tag with extra aruments then just delete that one and use below code.

Tag is:
<meta name="viewport" content="width=device-width, initial-scale=1.0">
Share:

Sunday, February 28, 2016

how to include js file in JavaScript code

How to include js file in JavaScript code

Sometime you need to include js file in javaScript code. below is the code that will solve this problem.

<script type="text/javascript">//<![CDATA[
document.write('<script src="url_path/js/js-file.js"><\/script>');
}
//]]>
</script>
Share:

delete multiple emails in Gmail basic HTML mode


How to delete multiple emails in Gmail basic HTML mode

Sometime you have slow internet connect, so at that time you will not able to open gmail in standard mode. at that time you will open it in HTML mode.
It is okay. now when you want to delete multiple emails(100 emails at a time) then you need to click checkbox one by one. this will take many times and frustration.
here is the solution for this types of situation. see below image and follow instructions.
.















Share:

Monday, February 08, 2016

XSS Exploits


XSS Exploits

It is XSS, It is Web site hacking. It is cross site scripting (XSS). 
The most usual form of Web site hacking . hackers force a site to perform certain actions like inject a client side scripting code (JavaScript) mixed with submitted content.


so that when a user visits a Web page with the submitted content, the malicious script gets downloaded automatically in his web browser and gets executed.

Using this types of hacking user's cookies and session stolen and sent to site of the attacker.
the user may get redirected to a targeted Web site for instance.
XSS may also be used for user account hacking. When the attacker is able to steal the session cookie value, he may be able to access to the user account as if it was the real user.

Prevention of XSS Exploits

XSS vulnerabilities can be avoided by properly encoding HTML using entities for <, >, " and '. Escaping of HTML characters on online forums can also be avoided by using bbcodes usually offered there.

The htmlpecialchars() function can be helpful in this regard as it converts content automatically into HTML entities. It also converts single quotes by using ENT_QUOTES as second argument. The strip_tags() function also removes PHP and HTML tags from string.
Share:

Saturday, February 06, 2016

update control value in C# Thread

How to update control value in C# Thread.



Use below sample of code:

Thread t1=new Thread();
String b="";
int all=0;
 private void button5_Click(object sender, EventArgs e)
 {
         
            t1 = new Thread(new ThreadStart(MyCodeRun));  t1.Start();
 }

void MyCodeRun()
{
           while (String.IsNullOrEmpty(b) || String.IsNullOrWhiteSpace(b))
            {
                this.BeginInvoke(new MethodInvoker(changeValue));
                all = all + 1;
                System.Threading.Thread.Sleep(1000);
            }
 }

 private void changeValue()
{
            label1.Text =all + "";
}
Share:

Friday, February 05, 2016

JSON parse in PHP

JSON parse in PHP



Suppose you want to parse listed below JSON data in PHP and you only needed to print objectId values. you can see here 3 records under merchants value "RPEZF3MRM39Z0"

-----------------------------------------------------------------------
{
"appId": "0QA16KMMVJAQR",
"merchants": {
"RPEZF3MRM39Z0": [{
"objectId": "O:S1MXC6FCY6GDW",
"type": "UPDATE",
"ts": 1453110818494
}, {
"objectId": "O:S1MXC6FCY6GDW",
"type": "UPDATE",
"ts": 1453110818913
}, {
"objectId": "P:SYD46NHH64EQG",
"type": "CREATE",
"ts": 1453110818913
}]
}
}
------------------------------------------------------------------------

php code:

suppose $st is hlding the above json data.

$json_a=json_decode($st,true);
foreach ( $json_a['merchants']['RPEZF3MRM39Z0'] as $objectId )
{
    echo $objectId['objectId']."</br>";
}




Share:

Wednesday, February 03, 2016

Video Cutter

Video Cutter

A Windows based Video cutter application. compatible with Windows 7, Windows 8,Windows 10 for 32 and 64 bit.

You do not stop or pause movie while cutting any part from video. just watch video while my application cut the part which you set.

Video Cutter

Video Cutter



Cut part/parts of large video files. This can be useful for cutting favorite or removing unwanted sections of video, such as commercials, outtakes and trailers.


The application is easy to use and has a simple, standard interface. What is really noticeable about this application is the speed.

Overall, Free Video Cutter is a relatively lightweight application that has good options to choose from and to select portion. It is rapid at standard conversions and the user interface is uncluttered and standard. If you want a basic video cutter application, then Free Video Cutter is a good choice.

Key features include:
Support for numerous formats including AVI, MP4, FLV, WMV, MOV, VOB, and 3GP.
Loss-less video cutting quality.
Rapid file processing.
Standard user interface.


Download links:

Download all the files and remove ".txt" extension. extract it.
Password is VideoCutter

http://agalaxycode.blogspot.com/2012/01/video-cutter-file-1.html
http://agalaxycode.blogspot.com/2012/01/video-cutter-file-2.html
http://agalaxycode.blogspot.com/2012/01/video-cutter-file-3.html
http://agalaxycode.blogspot.com/2012/01/video-cutter-file-4.html
http://agalaxycode.blogspot.com/2012/02/video-cutter-file-5.html
http://agalaxycode.blogspot.com/2012/02/video-cutter-file-6.html
http://agalaxycode.blogspot.com/2012/02/video-cutter-file-7.html
http://agalaxycode.blogspot.com/2012/02/video-cutter-file-8.html
http://agalaxycode.blogspot.com/2012/02/video-cutter-file-9.html
http://agalaxycode.blogspot.com/2012/02/video-cutter-file-10.html
http://agalaxycode.blogspot.com/2012/02/video-cutter-file-11.html
http://agalaxycode.blogspot.com/2012/02/video-cutter-file-12.html
http://agalaxycode.blogspot.com/2012/02/video-cutter-file-13.html
http://agalaxycode.blogspot.com/2012/02/video-cutter-file-14.html
http://agalaxycode.blogspot.com/2012/01/video-cutter-file-15.html
http://agalaxycode.blogspot.com/2012/02/video-cutter-file-16.html
http://agalaxycode.blogspot.com/2012/02/video-cutter-file-17.html


Share:

Tuesday, December 01, 2015

Remove version number from JS and CSS in WordPress

Problem:


How to Remove version number / querystring from JS and CSS in WordPress.

Solution:

goto your active theme folder and open functions.php file
and add below lines at the bottom.

function del_queryandversion_from_css_js( $style_or_js_url ) {
if ( strpos( $style_or_js_url, 'ver=' ) )
$css_js = remove_query_arg( 'ver', $style_or_js_url );
return $css_js;
}
add_filter( 'style_loader_src', 'del_queryandversion_from_css_js', 10 );
add_filter( 'script_loader_src', 'del_queryandversion_from_css_js', 10 );
Share:

Tuesday, November 17, 2015

How to use ON DUPLICATE KEY in insert statement

How to use ON DUPLICATE KEY in insert statement

Problem:
In case of inserting or updating record we use separate logic using if statement or case statement:
e.g.:

if(i==0)
insert here

if(i=1)
update here

we can terminate the above if statement by using On Duplicate Key.
by using this only one statement can be use for insert and update record.

*note: user_nm coulmn must be unique

Example:

INSERT INTO `posts` (`user_nm`, `no_of_update`, `inserted_on`, `update_on`)
VALUES ('a_user', 1, NOW(), NOW())
ON DUPLICATE KEY
UPDATE `no_of_update` = `no_of_update` + 1, `update_on` = NOW()



















Share:

Saturday, October 31, 2015

Mysql Database access using PDO

How to access Mysql Database using PDO:

PHP is changing day by day. in old days we were use mysql_connect(...) but now in current days it is not supported. current days we can use mysqli_connect(...). but it is better if we use PDO (PHP Data Object).

PHP Data Objects (PDO) is a very lightweight, consistent interface for accessing different types of databases in PHP. for this you simply tell the PDO database driver.

by using PDO you use the same functions to issue queries and fetch data in different types of database. PDO also remove all possibility of sql injections. for this it provide bind parameter facility.

Example:

Listed below full code that insert update delete list of all records. this code is in OOP based.


File: Db.php

<?php
class Db {
    private $pdo;
    private $stmt;

    function __construct() {
// set database setting here
$host='localhost'; $db='student_db'; $u='root'; $p='';
        try {
$this->pdo = new PDO("mysql:host={$host};dbname={$db}", $u,$p);
          $this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        } catch(PDOException $e) {
            $this->pdo = null;
echo $e->getMessage();
            return 'oops: ' . $e->getMessage();
        }
    }

    function __destruct() {
// release all resource
        $this->stmt = null;
        $this->pdo = null;
    }

// initialize prepare statement
    public function prepare_statement($sql) {
        $this->stmt = $this->pdo->prepare($sql);
    }

// bind parameter
    public function set_val($field_nm, $field_val) {
        $this->stmt->bindParam($field_nm, $field_val);
    }

// initialize prepare statement for update data using array
public function update_by_array($tbl_name, $where, $array_data) {
$sets="Update {$tbl_name} set ";
foreach ($array_data as $field => $value) {
$sets .= "{$field} = :{$field}, ";
}
$sets= substr($sets,0,-2).$where;
$this->prepare_statement($sets);
foreach ($array_data as $field => $value) {
$this->set_val(":{$field}", $value);
}
        return $this->exe_update_insert();
    }

//////// execute statement and return records from mysql
    public function get_record_exe_stat() {
        try {
            $this->stmt->execute();
            return $this->stmt->fetchAll(PDO::FETCH_ASSOC);
        } catch(PDOException $e) {
echo $e->getMessage();
            $this->pdo = null;
            return 'oops: ' . $e->getMessage();
        }
    }

/// execute statement and return updated/inserted no of rows/row
    public function exe_update_insert() {
        try {
           
$this->stmt->execute();
//$this->stmt->debugDumpParams();
            return $this->stmt->rowCount();
        } catch(PDOException $e) {
//$this->stmt->debugDumpParams();
//echo $e->getMessage();
            $this->pdo = null;
            return 'oops: ' . $e->getMessage();
        }
    }

/// Return number of rows that are after delete/update/insert
    public function get_row_count() {
        try {
            $this->stmt->rowCount();
        } catch(PDOException $e) {
echo $e->getMessage();
            $this->pdo = null;
            return 0;
        }
    }
/// Return last auto increment id after insert record
    public function get_last_id() {
        try {
            return $this->pdo->lastInsertId();
        } catch(PDOException $e) {
$this->pdo = null;
            return 0;
        }
    }
/// Return records of sql query
    public function get_record_by_sql($sql)
    {
        try {
            $stmt = $this->pdo->prepare($sql);
            $stmt->execute();
            return $stmt->fetchAll(PDO::FETCH_ASSOC);
        } catch(PDOException $e) {
echo $e->getMessage();
            $this->pdo = null;
            return 'oops: ' . $e->getMessage();
        }
    }
/// Insert record and return number of rows effected
    public function insert_by_sql($sql)
    {
        try {
            $stmt = $this->pdo->prepare($sql);
            $stmt->execute();
            return $stmt->rowCount();
        } catch(PDOException $e) {
echo $e->getMessage();
            $this->pdo = null;
            return 'oops: ' . $e->getMessage();
        }
    }
}



test.php

<?php
require_once('Db.php');
$db= new Db();
$i=0;

///// simple insert //////////
$number_of_rows_updated=$db->insert_by_sql("insert into std_info(std_full_nm,address,phone,class_cat) values ('xyz name','address123','1231231234','class 3')");

/////////////////////////insert by bind parameter prepare statement /////////////////////////////////////////////////////////
for($i=1;$i<=10;$i++) {
$std_full_nm = "AA".$i;
$address = "12/76 my address".$i;
$phone='12345678'.$i;
$class_cat='class'.$i;
$db->prepare_statement("insert into std_info(std_full_nm,address,phone,class_cat) values (:std_full_nm,:address,:phone,:class_cat)");
$db->set_val(":std_full_nm", $std_full_nm);
$db->set_val(":address", $address);
$db->set_val(":phone", $phone);
$db->set_val(":class_cat", $class_cat);
$up = $db->exe_update_insert();
if($up>=1){
$id=$db->get_last_id();
echo "Last id is =". $id."<br/>";
}
}

//////////////// return multiple row by prepare statement ////////////////////////////////////////////////////////////////
$id = "1";
$db->PrepareStatement("SELECT * FROM std_info WHERE std_id>= :id");
$db->set_val(":id", $id);
$userData = $db->get_record_exe_stat();
print_r($userData);
if (count($userData) < 1)
return;
for($i=0;$i<count($userData);$i++) {
echo $userData[$i]['std_id']."<br/>";
echo $userData[$i]['std_full_nm']."<br/>";
echo $userData[$i]['address']."<br/>";
echo $userData[$i]['phone']."<br/>";
echo $userData[$i]['class_cat']."<br/>";
echo "<hr/>";
}

///////////////////// return single row //////////////
$id = "1";
$db->PrepareStatement("SELECT * FROM std_info WHERE std_id= :id");
$db->set_val(":id", $id);
$userData = $db->get_record_exe_stat();
if (count($userData)>= 1) {
echo $userData[0]['std_id']."<br/>";
echo $userData[0]['std_full_nm']."<br/>";
echo $userData[0]['address']."<br/>";
echo $userData[0]['phone']."<br/>";
echo $userData[0]['class_cat']."<br/>";
echo "<hr/>";
}

///////////// update by using bind parameter ////////////////
$std_id = "1"; // Some ID to update
$std_full_nm = "zz";
$address = "55/76 my address";
$phone='0987654321';
$class_cat='10 class';

$db->prepare_statement("UPDATE std_info SET std_full_nm=:std_full_nm,address=:address,phone=:phone,class_cat=:class_cat WHERE std_id=:std_id");
$db->set_val(":std_id", $std_id);
$db->set_val(":std_full_nm", $std_full_nm);
$db->set_val(":address", $address);
$db->set_val(":phone", $phone);
$db->set_val(":class_cat", $class_cat);
$updated_row = $db->exe_update_insert();

///////////// update by using array ////////////////
$tbl_name='std_info';
$where=' WHERE std_id=1';
$sets = "";
$array_data = array(
'std_full_nm' => 'somename1',
'address' => 'someaddress1',
'phone' => 'Somephone1',
'class_cat' => 'Somecat1'
);
$db->update_by_array($tbl_name,$where, $array_data);

/////////////////// return records by simple sql //////////////
$id = "1";
$userData = $db->get_record_by_sql("SELECT * FROM std_info");
if (count($userData) < 1)
return;
for($i=0;$i<count($userData);$i++) {
echo $userData[$i]['std_id']."<br/>";
echo $userData[$i]['std_full_nm']."<br/>";
echo $userData[$i]['address']."<br/>";
echo $userData[$i]['phone']."<br/>";
echo $userData[$i]['class_cat']."<br/>";
echo "<hr/>";
}
Share:

Ads Inside Post

Powered by Blogger.

Archive