router#show ver
Cisco IOS Software, C1700 Software (C1700-ADVENTERPRISEK9-M), Version 12.4(7), RELEASE SOFTWARE (fc6)...
router(config)# ntp server 1.gr.pool.ntp.org
router(config)#clock timezone PST -7 //Los Angeles :)
router#show clock
18:21:43.570 PST Sat Oct 12 2013
router# show ntp associations
router# show ntp status
[ view entry ] ( 2179 views ) | print article
function resize_image($file, $w, $h, $crop=FALSE) {
list($width, $height) = getimagesize($file);
$r = $width / $height;
if ($crop) {
if ($width > $height) {
$width = ceil($width-($width*abs($r-$w/$h)));
} else {
$height = ceil($height-($height*abs($r-$w/$h)));
}
$newwidth = $w;
$newheight = $h;
} else {
if ($w/$h > $r) {
$newwidth = $h*$r;
$newheight = $h;
} else {
$newheight = $w/$r;
$newwidth = $w;
}
}
$src = imagecreatefromjpeg($file);
$dst = imagecreatetruecolor($newwidth, $newheight);
imagecopyresampled($dst, $src, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
return $dst;
}
header('Content-Type: image/jpeg');
$memcache = new Memcache;
$memcache->connect('127.0.0.1', 11211) or die ("Could not connect to Memcached.");
$key = md5('Snake_River_(5mb).jpg');
$get_result = $memcache->get($key);
if ($get_result) {
echo $get_result;
}
else {
$img = resize_image('Snake_River_(5mb).jpg', 300, 300);
ob_start();
imagejpeg($img);
$memcache->set($key, ob_get_contents(), 0, 10); // Cache thumbnail for 10 secs.
}
imagedestroy($img);
[ view entry ] ( 2535 views ) | print article
Using PHP memcache client:
public function doFetchRecords(){
$memcache = new Memcache;
$memcache->connect('127.0.0.1', 11211) or die ("Could not connect to Memcached.");
$SQL="SELECT * FROM statistics";
$key = md5($SQL);
$get_result = $memcache->get($key);
if ($get_result) {
echo '<!--Memcache Data-->';
return $get_result;
}
else {
$this->db->setQuery($SQL);
$data=$this->db->executeQuery(true);
$memcache->set($key, $data, 0, 30); // Store the result of the query for 30 seconds
return $data;
}
}
[ view entry ] ( 3082 views ) | print article
MySQL database has a handy and simple string function REPLACE() that allows table data with the matching string (from_string) to be replaced by new string (to_string). This is useful if there is need to search and replace a text string which affects many records or rows, such as change of company name, postcode, URL or spelling mistake.
The syntax of REPLACE is REPLACE(text_string, from_string, to_string)
MySQL reference describes REPLACE as function that returns the string text_string with all occurrences of the string from_string replaced by the string to_string, where matching is case-sensitive when searching for from_string. text_string can be retrieved from the a field in the database table too. Most SQL command can be REPLACE() function, especially SELECT and UPDATE manipulation statement.
For example:
update TABLE_NAME set FIELD_NAME = replace(FIELD_NAME, ‘find this string’, ‘replace found string with this string’);
update client_table set company_name = replace(company_name, ‘Old Company’, ‘New Company’)
The above statement will replace all instances of ‘Old Company’ to ‘New Company’ in the field of company_name of client_table table.
Another example:
SELECT REPLACE(‘www.mysql.com’, ‘w’, ‘Ww’);
Above statement will return ‘WwWwWw.mysql.com’ as result.
http://www.mydigitallife.info/how-to-fi ... using-sql/
[ view entry ] ( 1965 views ) | print article
// output headers so that the file is downloaded rather than displayed
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=data.csv');
// create a file pointer connected to the output stream
$output = fopen('php://output', 'w');
// output the column headings
fputcsv($output, array('Column 1', 'Column 2', 'Column 3'));
// fetch the data
mysql_connect('localhost', 'username', 'password');
mysql_select_db('database');
$rows = mysql_query('SELECT field1,field2,field3 FROM table');
// loop over the rows, outputting them
while ($row = mysql_fetch_assoc($rows)) fputcsv($output, $row);
//NEEDS TESTING.
[ view entry ] ( 2107 views ) | print article
Suppose you want to drop an existing column i from above MySQL table then you will use DROP clause along with ALTER command as follows:
mysql> ALTER TABLE testalter_tbl DROP i;
A DROP will not work if the column is the only one left in the table.
To add a column, use ADD and specify the column definition. The following statement restores the i column to testalter_tbl:
mysql> ALTER TABLE testalter_tbl ADD i INT;
After issuing this statement, testalter will contain the same two columns that it had when you first created the table, but will not have quite the same structure. That's because new columns are added to the end of the table by default. So even though i originally was the first column in mytbl, now it is the last one.
mysql> SHOW COLUMNS FROM testalter_tbl; +-------+---------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+---------+------+-----+---------+-------+ | c | char(1) | YES | | NULL | | | i | int(11) | YES | | NULL | | +-------+---------+------+-----+---------+-------+ 2 rows in set (0.00 sec)
To indicate that you want a column at a specific position within the table, either use FIRST to make it the first column or AFTER col_name to indicate that the new column should be placed after col_name. Try the following ALTER TABLE statements, using SHOW COLUMNS after each one to see what effect each one has:
ALTER TABLE testalter_tbl DROP i; ALTER TABLE testalter_tbl ADD i INT FIRST; ALTER TABLE testalter_tbl DROP i; ALTER TABLE testalter_tbl ADD i INT AFTER c;
The FIRST and AFTER specifiers work only with the ADD clause. This means that if you want to reposition an existing column within a table, you first must DROP it and then ADD it at the new position.
:)
http://www.tutorialspoint.com/mysql/mys ... ommand.htm
[ view entry ] ( 7132 views ) | print article
SELECT
CAST(CASE eoy
WHEN 0 THEN 'No Voted'
ELSE category/* Keep Original Value*/
END as CHAR) AS Result
FROM `vote_email`
//see all
SELECT eoy FROM vote_email
[ view entry ] ( 1799 views ) | print article
The CASE expression evaluates to a value, i.e. it is used to evaluate to one of a set of results, based on some condition.
Example:
SELECT CASE
WHEN type = 1 THEN 'foo'
WHEN type = 2 THEN 'bar'
ELSE 'baz'
END AS name_for_numeric_type
FROM sometable`
The CASE statement executes one of a set of statements, based on some condition.
Example:
CASE
WHEN action = 'update' THEN
UPDATE sometable SET column = value WHERE condition;
WHEN action = 'create' THEN
INSERT INTO sometable (column) VALUES (value);
END CASE
You see how they are similar, but the statement does not evaluate to a value and can be used on its own, while the expression needs to be a part of an expression, e.g. a query or an assignment. You cannot use the statement in a query, since a query cannot contain statements, only expressions that need to evaluate to something (the query itself is a statement, in a way), e.g. SELECT CASE WHEN condition THEN UPDATE table SET something; END CASE makes no sense.
http://stackoverflow.com/questions/1243 ... -statement
[ view entry ] ( 1579 views ) | print article
// view all users
SELECT user,host FROM mysql.user;
//drop a user
DROP USER 'dev-webuser'@'localhost';
//create a user and assign password
GRANT ALL PRIVILEGES ON db_name.* TO 'webuser'@'localhost' IDENTIFIED BY 'secret123'
// disply logged in grants
SHOW GRANTS;
//
CREATE USER 'jeffrey'@'localhost' IDENTIFIED BY 'mypass';
//
GRANT SELECT,INSERT,UPDATE,DELETE ON my_db.* TO 'michael'@'localhost';
//
GRANT ALL ON my_db.* TO 'michael'@'localhost';
//
GRANT ALL ON my_db.* TO 'my_user'@localhost IDENTIFIED BY 'my_pass';
//update user's password:
SET PASSWORD FOR 'webuser'@'localhost' = PASSWORD('dev123');
// MySQL 8 :
root@5f288b2166ba:/# mysql -p
...
mysql>
mysql> CREATE USER 'coolUser'@'%' IDENTIFIED WITH mysql_native_password BY 'YYYYYY';
Query OK, 0 rows affected (0.01 sec)
mysql>
mysql> grant all on *.* to 'coolUser'@'%';
Query OK, 0 rows affected (0.01 sec)
#Starting with MySQL 8 you no longer can (implicitly) create a user using the GRANT command. Use CREATE USER instead, followed by the GRANT statement:
mysql> CREATE USER 'root'@'%' IDENTIFIED BY 'PASSWORD';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
mysql> FLUSH PRIVILEGES;
[ view entry ] ( 1900 views ) | print article
//package info
rpm -qi "package"
//Listing all installed packages
rpm -qa
//remove a package
rpm -e "package"
rpm -e "package" "package" //dependencies
// install a package
rpm -Uvh package_file.rpm
[ view entry ] ( 1988 views ) | print article
<<First <Back | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | Next> Last>>