Skip to content

Instantly share code, notes, and snippets.

View herdihakim's full-sized avatar
🏠
Working from home

Herdi Hakim herdihakim

🏠
Working from home
View GitHub Profile
<?php defined('BASEPATH') OR exit('No direct script access allowed');
function compressImage64($base64, $saveto, $quality = 60) {
$ret = false;
$img = preg_replace(array("~^data:image/[a-zA-Z]*;base64,~","/\s/"), array("","+"), $base64);
$data= base64_decode($img);
$img = imagecreatefromstring($data);
if (!file_exists( dirname($saveto) )) {
mkdir( dirname($saveto) , 0777, true);
}
if(imagejpeg($img, $saveto, $quality)) {
sudo visudo
# Add the following line below "pi ALL etc." and exit the visudo editor:
www-data ALL = NOPASSWD: /sbin/shutdown
sudo nano /var/www/index.html
# Absolute minimum contents of the index.html file:
<html><a href="shutdown.php">Shutdown NOW</a></html>
sudo nano /var/www/shutdown.php
# Absolute minimum contents of the shutdown.php file:
<?php system('sudo /sbin/shutdown -h now'); ?>
@herdihakim
herdihakim / romanic.php
Created May 23, 2017 06:14
PHP Roman Int Converter
<?php
function romanic_number($roman) { // V = 5
$table = array('M'=>1000, 'CM'=>900, 'D'=>500, 'CD'=>400, 'C'=>100, 'XC'=>90, 'L'=>50, 'XL'=>40, 'X'=>10, 'IX'=>9, 'V'=>5, 'IV'=>4, 'I'=>1);
$result = 0;
foreach ($table as $key => $value) {
while (strpos($roman, $key) === 0) {
$result += $value;
$roman = substr($roman, strlen($key));
}
}
@herdihakim
herdihakim / dateid.php
Created May 23, 2017 06:10
PHP Format Tanggal Indonesia
<?php
function dateid($format, $time = false) { // "Asia/Tokyo"
$day = array('Sen', 'Sel', 'Rab', 'Kam', 'Jum', 'Sab', 'Min');
$days = array('Senin', 'Selasa', 'Rabu', 'Kamis', 'Jumat', 'Sabtu', 'Minggu');
$month = array('', 'Jan', 'Feb', 'Mar', 'Apr', 'Mei', 'Jun', 'Jul', 'Agu', 'Sep', 'Okt', 'Nov' ,'Des');
$months= array('', 'Januari', 'Februari', 'Maret', 'April', 'Mei', 'Juni', 'Juli', 'Agustus', 'September', 'Oktober', 'November' ,'Desember');
if(!is_a($time, 'DateTime')) {
if(is_int($time)) {
$time = new DateTime(date('Y-m-d H:i:s.u',$time));