Skip to content

Instantly share code, notes, and snippets.

View ferdhie's full-sized avatar

herdian ferdianto ferdhie

View GitHub Profile
@ferdhie
ferdhie / setup_ffmpeg.sh
Created October 27, 2016 08:00
Setup FFMPEG on Ubuntu
sudo apt-get -y install autoconf automake build-essential libass-dev libfreetype6-dev libtheora-dev libtool libvorbis-dev pkg-config texinfo zlib1g-dev cmake mercurial nasm
mkdir ~/ffmpeg_sources
#yasm
cd ~/ffmpeg_sources
wget http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz
tar xzvf yasm-1.3.0.tar.gz
cd yasm-1.3.0
./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin"
make
@ferdhie
ferdhie / backup_s3.sh
Created August 29, 2016 17:11
Backup file to s3
#!/bin/bash
file="file-to-backup.gz"
contentType="application/x-gzip"
bucket="bucketname"
region="ap-southeast-1"
resource="/${bucket}/${file}"
dateValue=`date -R`
stringToSign="PUT\n\n${contentType}\n${dateValue}\n${resource}"
@ferdhie
ferdhie / phpmailer_gmail.php
Created August 29, 2016 14:40
PHPMailer usage example
<?php
//https://github.com/PHPMailer/PHPMailer
require 'class.phpmailer.php';
require 'class.smtp.php';
$mail = new PHPMailer();
$mail->CharSet = 'UTF-8';
$mail->IsSMTP();
$mail->SMTPDebug = 1;
@ferdhie
ferdhie / backup_ebs.php
Created August 29, 2016 14:34
Backup EBS, retain last 7 days
<?php
putenv('AWS_ACCESS_KEY=XXXXXXXXXXXXXXXXXX');
putenv('AWS_SECRET_KEY=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX');
putenv("JAVA_HOME=/usr/lib/jvm/jre");
$ec2_bin="/opt/aws/bin";
$my_cert="/home/ec2-user/cert-xxx.pem";
$my_key="/home/ec2-user/pk-xxx.pem";
$instance_id=file_get_contents('http://169.254.169.254/latest/meta-data/instance-id');
@ferdhie
ferdhie / aes-cbc-pkcs5.php
Created August 24, 2016 05:17
PHP MCRYPT AES CBC PKCS padding 5, interchangeable with Java Crypto
<?php
function aes_cbc_encrypt($data, $key)
{
$size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);
$iv = mcrypt_create_iv($size, MCRYPT_DEV_RANDOM);
$key = hash('SHA256', $key, true);
$strIn = pkcs5_pad($data);
$strCrypt = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $strIn, MCRYPT_MODE_CBC, $iv);
return base64_encode($iv.$strCrypt);
@ferdhie
ferdhie / queryiterator.php
Last active August 24, 2016 05:16
php mysql query iterator
<?php
class QueryIterator implements Iterator
{
private $position = 0;
private $rows=array();
private $result = NULL;
public function __construct($sql)
{
Had this one case, ping is correct, but telnet to server failed
Check with tcpdump from server if your checksum is invalid.
if lots of invalid checksump, just run this command
#turn off checksum
/sbin/ethtool --offload em2 rx off tx off
@ferdhie
ferdhie / ExifRotate.java
Created September 26, 2012 14:16
Auto rotate image using exif data
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import javax.microedition.io.Connector;
import javax.microedition.io.file.FileConnection;
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.EncodedImage;