Skip to content

Instantly share code, notes, and snippets.

@n5i
n5i / gist:3963608
Created October 27, 2012 08:51
PHP display all errors
error_reporting(E_ALL);
ini_set('display_errors', '1');
@n5i
n5i / gist:3963621
Created October 27, 2012 08:53
php.ini path in ubuntu
/etc/php5/apache2/php.ini
@n5i
n5i / gist:3963651
Created October 27, 2012 08:56
Apache restart ubuntu
sudo /etc/init.d/apache2 restart
@n5i
n5i / gist:3988905
Created October 31, 2012 18:28
yii get records count
$sql = "SELECT COUNT(*) FROM table WHERE 1";
$records_count = Yii::app()->db->createCommand( $sql )->queryScalar();
@n5i
n5i / gist:4051148
Created November 10, 2012 13:52
Checking if xml is valid
// The function checks if xml is valid
function is_valid_xml ( $xml ) {
if( empty( $xml ) ){
return null;
}
libxml_clear_errors();
@n5i
n5i / encoding.php
Created November 12, 2012 11:51
Encoding detection class
<?php
class Encoding {
protected static $win1252ToUtf8 = array(
128 => "\xe2\x82\xac",
130 => "\xe2\x80\x9a",
131 => "\xc6\x92",
132 => "\xe2\x80\x9e",
@n5i
n5i / gist:4103935
Created November 18, 2012 07:02
Get domain url from link
// function extract a domain url from the link
// !Note: the domain name case is transformed to lowercase
function get_domain( $url ){
$url = strtolower( $url );
$base = str_ireplace( 'http://', '', $url );
$base = str_ireplace( 'https://', '', $base );
if( preg_match( '/^www\./i', $base ) ){
@n5i
n5i / gist:4261747
Created December 11, 2012 20:13
Mysqli bind param
<?php
$mysqli = new mysqli('localhost', 'my_user', 'my_password', 'world');
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$stmt = $mysqli->prepare("INSERT INTO CountryLanguage VALUES (?, ?, ?, ?)");
@n5i
n5i / gist:4274973
Created December 13, 2012 08:19
YII log
Yii::log('Log test',CLogger::LEVEL_ERROR);
@n5i
n5i / gist:4283665
Created December 14, 2012 08:36
unix. Send running process to background
Using the Job Control of bash to send the process into the background:
ctrl+z to stop (pause) the program and get back to the shell
bg to run it in the background
disown -h so that the process isn't killed when the terminal closes
Suppose for some reason Ctrl+Z is also not working, go to another terminal, find the process id (using ps) and run
kill -20 PID
kill -18 PID