Blogroll

Thursday, December 6, 2012

Get city from lat and lon ( GOOGLE MAP API )

Below is my code :

$status = 'OK'; $value = ''; try { $lat = $_GET ['lat']; $lon = $_GET ['lon']; // TODO: validate input + find city name by coord assert ( is_numeric ( $lat ) ); assert ( is_numeric ( $lon ) ); $google_api_link = 'http://maps.googleapis.com/maps/api/geocode/json?latlng=%s&sensor=false'; $lat = filter_input ( INPUT_GET, 'lat' ); $lon = filter_input ( INPUT_GET, 'lon' ); $link = sprintf ( $google_api_link, $lat . "," . $lon ); $content = httpReq ( $link ); $json_object = json_decode ( $content ); if ($json_object->status != 'OK') { $status = $json_object->status; } else { $address_components = $json_object->results [0]->address_components; for($i = 0; $i < count ( $address_components ); $i ++) { $address_item = $address_components [$i]; if ( in_array('country', $address_item->types) && ( ($i - 1) >= 0 )) { $value = $address_components [$i - 1]->long_name; } } }
Tuesday, November 27, 2012

Fix cross domain request in IE8 and above

I have problem with IE browser when request other link from my site, From IE8 and above, when request you will be get error "Access is deny or no transport". To fix this , you must implement for IE specific funtion ( don't use Ajax jquery ). Detail link read at here http://www.nczonline.net/blog/2010/05/25/cross-domain-ajax-with-cross-origin-resource-sharing/
Thursday, October 18, 2012

emmbed flash to html

This way is most simple and working for all modern browser.

code :


Thursday, September 13, 2012

Fix error bind() fail on sphinx

We should try 2 command before this below guide :


the 'init: ... main process ended, respawning' suggests there is something in the init script that sets a watchdog to make sure sphinx doesnt die.
Perhaps you need to shutdown sphinx via the init script itself
/etc/init.d/sphinxsearch stop


or

By default, it seems like the debian package will start Sphinx with an additional keepalive process. I was able to stop it successfully with this;
sudo service sphinxsearch stop

If 2 way above is not success, you should try.
using config file '/sphinx/conf/sphinx.conf'...
listening on all interfaces, port=9312
bind() failed on 0.0.0.0, retrying...
bind() failed on 0.0.0.0, retrying...
bind() failed on 0.0.0.0, retrying...
bind() failed on 0.0.0.0, retrying...
bind() failed on 0.0.0.0, retrying...
bind() failed on 0.0.0.0, retrying...

If happend error like this, the best way , you should change port in config file
Change 9312 to some other port.


listen = 9312
listen = 9306:mysql41

To 



listen = 9314
listen = 9308:mysql41

Wednesday, September 12, 2012

Simple blog using mongoDb

This is simple blog allow display post , add new post and add comment for post using MongoDb for storage.
Note: Download mongDb for php at this link http://www.mongodb.org/display/DOCS/PHP+Language+Center

And install mongDb before demotrastion.

I pushed source to gitHub att this link https://github.com/bvtuan/blog_mongodb
Hope it useful for who learning mongoDb.

Tuesday, September 11, 2012

Install jdk 7 for ubuntu 12.04

Just use some terminal code below :
sudo rm /var/lib/dpkg/info/oracle-java7-installer*
sudo apt-get purge oracle-java7-installer*
sudo rm /etc/apt/sources.list.d/*java*
sudo apt-get update
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java7-installer

Installing Sphinx 2.0.4 on Ubuntu 10.04 - Lucid


Description: “Sphinx  is a full-text search engine, distributed under GPL version 2. Commercial license is also available for embedded use. Generally, it’s a standalone search engine, meant to provide fast, size-efficient and relevant fulltext search functions to other applications. Sphinx was specially designed to integrate well with SQL databases and scripting languages. Currently built-in data sources support fetching data either via direct connection to MySQL or PostgreSQL, or using XML pipe mechanism (a pipe to indexer in special XML-based format which Sphinx recognizes). As for the name, Sphinx is an acronym which is officially decoded as SQL Phrase Index. Yes, I know about CMU’s Sphinx project“.
Installation:
  • Install the packages needed: apt-get install gcc make libmysqlclient15-dev libmysql++-dev
  • Download Sphinx from here .
  • Decompress it: tar xvfz sphinx-*.tar.gz
  • Enter its directory: cd sphinx-*
  • Run configure: ./configure --prefix=/usr/local/sphinx --with-mysql
  • Compile Sphinx: make
  • Install Sphinx (as root): make install
Configuration:
  • Enter Sphinx’s directory: cd /usr/local/sphinx/etc
  • Make a copy of its default configuration: cp sphinx.conf.dist sphinx.conf
  • Modify it to fit you database schema and preferences (I recommend reading Sphinx’s official documentation   and this tutorial by IBM  first).
  • Create all indexes: /usr/local/sphinx/bin/indexer --all
  • Something like this will be shown:

    Sphinx 0.9.9-rc2 (r1785)
    Copyright (c) 2001-2009, Andrew Aksyonoff
    using config file '/usr/local/sphinx/etc/sphinx.conf'...
    indexing index 'software'...
    collected 10 docs, 0.0 MB
    sorted 0.0 Mhits, 100.0% done
    total 10 docs, 649 bytes
    total 0.013 sec, 48970 bytes/sec, 754.54 docs/sec
    total 2 reads, 0.000 sec, 16.3 kb/call avg, 0.0 msec/call avg
    total 5 writes, 0.000 sec, 0.4 kb/call avg, 0.0 msec/call avg
Use:
  • You can perform a basic search using: /usr/local/sphinx/bin/search desired_word . It matches all words by default, but you can change this behaviour. Run/usr/local/sphinx/bin/search without arguments to show the available options.
  • Example: /usr/local/sphinx/bin/search samba
    Sphinx 0.9.9-rc2 (r1785)
    Copyright (c) 2001-2009, Andrew Aksyonoff


    using config file '/usr/local/sphinx/etc/sphinx.conf'...
    index 'software': query 'samba ': returned 1 matches of 1 total in 0.000 sec


    displaying matches:
    1. document=10, weight=2
    id=10
    url=http://www.samba.org/
    name=Samba
    description=Samba is a SMB/CIFS file, print, and login server. It seamlessly integrates Linux/Unix Servers and Desktops into Active Directory environments using the Winbind daemon.
    stable_version=3.4.3
    stable_date=2009-10-29
    download=http://www.samba.org/samba/ftp/stable/samba-3.4.3.tar.gz


    words:
    1. 'samba': 1 documents, 2 hits
The use of /usr/local/sphinx/bin/search is just for test and debugging purposes. There are native API ports for PHP, Python, Java, Perl, and Ruby. I will explain the integration between PHP  and Sphinx on another post.
Source :http://acidborg.wordpress.com/2009/11/22/how-to-install-and-configure-sphinx-in-ubuntu-9-10-with-mysql-support/

Note :use searchd --config "config file first";
then sudo indexer --config "config file" --all --rotate

Thursday, August 9, 2012

Install mongodb for windows

Follow some below step:
1. Download lasted version at http://www.mongodb.org/downloads and choose right version for your computer.
2. Extract zip file to somewhere, For me is c:\bin\mongodb.
3.Create folder that save mongodb data, For me is c:\data 
4.Open cmd and type cd c:\bin\mongodb\bin
5.Continue and cmd and type mongod --dbpath c:\data to run mongodb as services (c:\data is folder that created before).
In this step, mongdb is running, Remember don't close cmd because it's running.
To do testing with mongDb, do below step:
6. If have no error appear, It mean you installed mongodb  as services successful. Next test it working.
7.Open cmd and type  cd c:\bin\mongodb\bin and type another text is mongo and enter. Mongo shell will be apper.
8. Type code to insert to db db.test.save({a:'abc'}) , It mean add a with value is 'abc' to test collection
9.To show record in test collection , type code db.test.find()

Nodejs with mongodb

Today, I excited to research nodeJs and i find way  how to access db to Mongodb from nodeJS.
At first, install module mongodb for node in this link 
Wednesday, July 25, 2012

Regular express php

Regular express is language to description a group of string pattern. I used to validate url, email, phone, name,,..... Below is table definition some rule for regular express
Tuesday, July 17, 2012

Compress html with php

Compress html help you load page with faster speed, delete your html comment.
Fist : save out html and call function when page load done.
Put below code before show your html code.
Monday, July 16, 2012

13 useful query for wordpress


Change Siteurl & Homeurl

WordPress stores the absolute path of the site URL and home URL in the database. Therefore, if you transfer your WordPress site from the localhost to your server, your site will not load online. This is because the absolute path URL is still pointing to your localhost. You will need to change the site URL and the home URL in order for the site to work.
Solution:
1
UPDATE wp_options SET option_value = replace(option_value, 'http://www.oldsiteurl.com', 'http://www.newsiteurl.com') WHERE option_name = 'home' OR option_name = 'siteurl';

Friday, June 15, 2012

Remove new line php

I'll many way to remove new line in php. Some version not working in some code. Below is code almost working well
$string = preg_replace('@[\s]{2,}@',' ',$value);
$string  = trim(str_replace(array("/\n|\r/","\""),array("", "'"), $string));
Wednesday, May 23, 2012

10 sql tips to speed up your database



On most websites, content is stored in a database and served to visitors upon request. Databases are very fast, but there’s lots of things that you can do to enhance its speed and make sure you won’t waste any server resources. In this article, I have compiled 10 very useful tips to optimize and speed up your website database.

Design your database with caution

This first tip may seems obvious, but the fact is that most database problems come from badly-designed table structure.
For example, I have seen people storing information such as client info and payment info in the same database column. For both the database system and developers who will have to work on it, this is not a good thing.
When creating a database, always put information on various tables, use clear naming standards and make use of primary keys.
Source: http://www.simple-talk.com/sql/database-administration/ten-common-database-design-mistakes/

Know what you should optimize

If you want to optimize a specific query, it is extremely useful to be able to get an in-depth look at the result of a query. Using the EXPLAIN statement, you will get lots of useful info on the result produced by a specific query, as shown in the example below:
EXPLAIN SELECT * FROM ref_table,other_table WHERE ref_table.key_column=other_table.column;

The fastest query… Is the one you don’t send

Each time you’re sending a query to the database, you’re using a bit of your server resources. This is why, on high traffic sites, the best thing you can do in order to speed up your database is to cache queries.
There’s lots of solutions to implement a query cache on your server. Here are a few:
  • AdoDB: AdoDB is a database abstraction library for PHP. It allows you to use the database system of your choice (MySQL, PostGreSQL, Interbase, and way much more) and it is designed for speed. AdoDB provides a simple, yet powerful caching system. And last but not least, AdoDB is licenced under the BSD, which means that you can use freely on your projects. A LGPL licence is also available for commercial projects.
  • Memcached: Memcached is a distributed memory caching system which is often used to speed up dynamic database-driven websites by alleviating database load.
  • CSQL Cache: CSQL Cache is an open-source data caching infrastructure. Never tested it personally, but it seems to be a great tool.

Don’t select what you don’t need

A very common way to get the desired data is to use the * symbol, which will get all fields from the desired table:
SELECT * FROM wp_posts;
Instead, you should definitely select only the desired fields as shown in the example below. On a very small site with, let’s say, one visitor per minute, that wouldn’t make a difference. But on a site such as Cats Who Code, it saves a lot of work for the database.
SELECT title, excerpt, author FROM wp_posts;

Use LIMIT

It’s very common that you need to get only a specific number of records from your database. For example, a blog which is showing ten entries per page. In that case, you should definitely use the LIMIT parameter, which only selects the desired number of records.
Without LIMIT, if your table has 100,000 different records, you’ll extract them all, which is unnecessary work for your server.
SELECT title, excerpt, author FROM wp_posts LIMIT 10;

Avoid queries in loops

When using SQL along with a programming language such as PHP, it can be tempting to use SQL queries inside a loop. But doing so is like hammering your database with queries.
This example illustrates the whole “queries in loops” problem:
foreach ($display_order as $id => $ordinal) {
    $sql = "UPDATE categories SET display_order = $ordinal WHERE id = $id";
    mysql_query($sql);
}
Here is what you should do instead:
UPDATE categories
    SET display_order = CASE id
        WHEN 1 THEN 3
        WHEN 2 THEN 4
        WHEN 3 THEN 5
    END
WHERE id IN (1,2,3)

Use join instead of subqueries

As a programmer, subqueries are something that you can be tempted to use and abuse. Subqueries, as show below, can be very useful:
SELECT a.id,
    (SELECT MAX(created)
    FROM posts
    WHERE author_id = a.id)
AS latest_post FROM authors a
Although subqueries are useful, they often can be replaced by a join, which is definitely faster to execute.
SELECT a.id, MAX(p.created) AS latest_post
FROM authors a
INNER JOIN posts p
    ON (a.id = p.author_id)
GROUP BY a.id

Be careful when using wildcards

Wildcards are very useful because they can substitute for one or more characters when searching for data in a database. I’m not saying that you shouldn’t use them, but instead, you should use them with caution and not use the full wildcard when the prefix or postfix wildcard can do the same job.
In fact, doing a full wildcard search on a million records will certainly kill your database.
#Full wildcard
SELECT * FROM TABLE WHERE COLUMN LIKE '%hello%';
#Postfix wildcard
SELECT * FROM TABLE WHERE COLUMN LIKE  'hello%';
#Prefix wildcard
SELECT * FROM TABLE WHERE COLUMN LIKE  '%hello';

Use UNION instead of OR

The following example use the OR statement to get the result:
SELECT * FROM a, b WHERE a.p = b.q or a.x = b.y;
The UNION statement allows you to combine the result sets of 2 or more select queries. The following example will return the same result that the above query gets, but it will be faster:
SELECT * FROM a, b WHERE a.p = b.q
UNION
SELECT * FROM a, b WHERE a.x = b.y

Use indexes

Database indexes are similar to those you can find in libraries: They allow the database to find the requested information faster, just like a library index will allow a reader to find what they’re looking for without loosing time.
An Index can be created on a single column or a combination of columns in a database table. A table index is a database structure that arranges the values of one or more columns in a database table in specific order.
The following query will create an index on the Model column from the Product table. The index is calledidxModel:
CREATE INDEX idxModel ON Product (Model);
Wednesday, May 16, 2012

Zend Framework: Accessing Request, Response & Router Object from anywhere



On most websites, content is stored in a database and served to visitors upon request. Databases are very fast, but there’s lots of things that you can do to enhance its speed and make sure you won’t waste any server resources. In this article, I have compiled 10 very useful tips to optimize and speed up your website database.

Design your database with caution

This first tip may seems obvious, but the fact is that most database problems come from badly-designed table structure.
For example, I have seen people storing information such as client info and payment info in the same database column. For both the database system and developers who will have to work on it, this is not a good thing.
When creating a database, always put information on various tables, use clear naming standards and make use of primary keys.
Source: http://www.simple-talk.com/sql/database-administration/ten-common-database-design-mistakes/

Know what you should optimize

If you want to optimize a specific query, it is extremely useful to be able to get an in-depth look at the result of a query. Using the EXPLAIN statement, you will get lots of useful info on the result produced by a specific query, as shown in the example below:
EXPLAIN SELECT * FROM ref_table,other_table WHERE ref_table.key_column=other_table.column;

The fastest query… Is the one you don’t send

Each time you’re sending a query to the database, you’re using a bit of your server resources. This is why, on high traffic sites, the best thing you can do in order to speed up your database is to cache queries.
There’s lots of solutions to implement a query cache on your server. Here are a few:
  • AdoDB: AdoDB is a database abstraction library for PHP. It allows you to use the database system of your choice (MySQL, PostGreSQL, Interbase, and way much more) and it is designed for speed. AdoDB provides a simple, yet powerful caching system. And last but not least, AdoDB is licenced under the BSD, which means that you can use freely on your projects. A LGPL licence is also available for commercial projects.
  • Memcached: Memcached is a distributed memory caching system which is often used to speed up dynamic database-driven websites by alleviating database load.
  • CSQL Cache: CSQL Cache is an open-source data caching infrastructure. Never tested it personally, but it seems to be a great tool.

Don’t select what you don’t need

A very common way to get the desired data is to use the * symbol, which will get all fields from the desired table:
SELECT * FROM wp_posts;
Instead, you should definitely select only the desired fields as shown in the example below. On a very small site with, let’s say, one visitor per minute, that wouldn’t make a difference. But on a site such as Cats Who Code, it saves a lot of work for the database.
SELECT title, excerpt, author FROM wp_posts;

Use LIMIT

It’s very common that you need to get only a specific number of records from your database. For example, a blog which is showing ten entries per page. In that case, you should definitely use the LIMIT parameter, which only selects the desired number of records.
Without LIMIT, if your table has 100,000 different records, you’ll extract them all, which is unnecessary work for your server.
SELECT title, excerpt, author FROM wp_posts LIMIT 10;

Avoid queries in loops

When using SQL along with a programming language such as PHP, it can be tempting to use SQL queries inside a loop. But doing so is like hammering your database with queries.
This example illustrates the whole “queries in loops” problem:
foreach ($display_order as $id => $ordinal) {
    $sql = "UPDATE categories SET display_order = $ordinal WHERE id = $id";
    mysql_query($sql);
}
Here is what you should do instead:
UPDATE categories
    SET display_order = CASE id
        WHEN 1 THEN 3
        WHEN 2 THEN 4
        WHEN 3 THEN 5
    END
WHERE id IN (1,2,3)

Use join instead of subqueries

As a programmer, subqueries are something that you can be tempted to use and abuse. Subqueries, as show below, can be very useful:
SELECT a.id,
    (SELECT MAX(created)
    FROM posts
    WHERE author_id = a.id)
AS latest_post FROM authors a
Although subqueries are useful, they often can be replaced by a join, which is definitely faster to execute.
SELECT a.id, MAX(p.created) AS latest_post
FROM authors a
INNER JOIN posts p
    ON (a.id = p.author_id)
GROUP BY a.id

Be careful when using wildcards

Wildcards are very useful because they can substitute for one or more characters when searching for data in a database. I’m not saying that you shouldn’t use them, but instead, you should use them with caution and not use the full wildcard when the prefix or postfix wildcard can do the same job.
In fact, doing a full wildcard search on a million records will certainly kill your database.
#Full wildcard
SELECT * FROM TABLE WHERE COLUMN LIKE '%hello%';
#Postfix wildcard
SELECT * FROM TABLE WHERE COLUMN LIKE  'hello%';
#Prefix wildcard
SELECT * FROM TABLE WHERE COLUMN LIKE  '%hello';

Use UNION instead of OR

The following example use the OR statement to get the result:
SELECT * FROM a, b WHERE a.p = b.q or a.x = b.y;
The UNION statement allows you to combine the result sets of 2 or more select queries. The following example will return the same result that the above query gets, but it will be faster:
SELECT * FROM a, b WHERE a.p = b.q
UNION
SELECT * FROM a, b WHERE a.x = b.y

Use indexes

Database indexes are similar to those you can find in libraries: They allow the database to find the requested information faster, just like a library index will allow a reader to find what they’re looking for without loosing time.
An Index can be created on a single column or a combination of columns in a database table. A table index is a database structure that arranges the values of one or more columns in a database table in specific order.
The following query will create an index on the Model column from the Product table. The index is calledidxModel:
CREATE INDEX idxModel ON Product (Model);
Monday, April 23, 2012

RGBa Css with transparent.

Read full article in here
Friday, April 20, 2012

Detect yahoo online status

Detect yahoo status
Monday, April 16, 2012

Solved redirect with zend router

Redirect is the function in zend framework. But i hard to redirect on zend router config.
I have some error when use redirect to my router config.
Below solved problem
Wednesday, April 11, 2012

Display Calendar Php Code

One of the website features my customers love to provider their web users is an online dynamic calendar. An online calendar can be used for events, upcoming product specials, memos, and anything else you can think of. I've taken some time to completely rewrite the PHP event calendar so that I may share it with you.
Sunday, April 8, 2012

List category and subcategory in magento

I found below code to list category and subcategory . I can put it everywhere in your website.
Tuesday, February 21, 2012

lavalamp , Plugin for jquery lover

lavalamp is plugin for enhacement effect your website, it's small and easy to use.
Full article at here
This is demo link.

Speed up load page by lazyload

Default, when your website is load, all image tag available in your site will be load all. It make your site load slowly and some picture that you don't show but it will be loaded. That's wasty.

Thursday, February 16, 2012

List files and folders in the folder

This is easy way to read all file and folder to array, this also check allow extestion file to read.

Friday, January 13, 2012

27 Best Photoshop Web Layout Design Tutorials to Design Decent Web Layouts


For beginner web designers – design tutorials really help to understand the basic knowledge about web design!, Here is a collection of 27 layout design tutorials that will help you with designing a decent looking website. Some of them are really good!,

Use seclection in css


Something cool that you can do using just CSS is change the selection color when you are range selecting content.

Thursday, January 12, 2012

Create custom hash.

I refer use crypt() instead md5 or sha256, because of crypt proviced many hash method and key to decode is automatic created -> hard to crack.

Wednesday, January 11, 2012

Make auto scroll when page scroll

Link demo 
Technique: auto scroll follow window scroll top and set margin-top for scroll element.