2015/04/24

How to zip unzip directory in Linux ?

Pack:
tar -zcvf archive.tar.gz directory/

c - create an archive from files in directory (recursive by default)
z - compress above archive with gzip
f - store the output as a file
v - list all the files

Unpack:
tar -zxvf archive.tar.gz

2015/04/11

How to send mail from PHP using swiftmailer library ?

Download swiftmailer library from here
require_once "swiftmailer/swiftmailer/lib/swift_required.php";
private function send_mail($total_google_num){
$subject = 'Subject';
$from = array('example_1@gmail.com' =>'Your Name');
$to = array('example_2@gmail.com' => 'Recipient1 Name');
$text = "text message";
$html = "html message";
$transport = \Swift_SmtpTransport::newInstance("smtp.gmail.com")
->setPort(465)
->setEncryption('ssl')
->setUsername(your_gmail_username)
->setPassword(your_gmail_password);
$swift = \Swift_Mailer::newInstance($transport);
$message = (new \Swift_Message($subject))
->setFrom($from)
->setBody($html, 'text/html')
->setTo($to)
->addPart($text, 'text/plain');
$failures = null;
if ($recipients = $swift->send($message, $failures))
{
echo 'Message successfully sent!';
} else {
echo "There was an error:\n";
print_r($failures);
}
}
view raw gistfile1.php hosted with ❤ by GitHub

2015/04/10

How to select records that has unix_timestamp and differs in minutes in MySql ?

SELECT *
FROM proxy
WHERE status = 'active'
AND TIMESTAMPDIFF(MINUTE, FROM_UNIXTIME(blocking_date), CURRENT_TIMESTAMP) > 60 * 4))
ORDER BY total_ping_counter
view raw gistfile1.sql hosted with ❤ by GitHub