Skip to content

Instantly share code, notes, and snippets.

View yudaprawira's full-sized avatar

Yuda Prawira yudaprawira

View GitHub Profile
<!DOCTYPE html>
<html>
<head>
<title>Responsive Table</title>
<link rel="stylesheet" href="style.css" />
<meta name="description" content="responsive table headers column" />
<meta name="keywords" content="responsive, table, headers, column" />
</head>
<body>
<h1>Responsive Table</h1>
@yudaprawira
yudaprawira / index.php
Created September 1, 2016 03:23
PHP Time Ago
<?php
/**
* Build Time Ago PHP
* @param $dateTime format Y-m-d H:i;s
* @return $string
**/
function timeAgo($dateTime)
{
$etime = time() - strtotime($dateTime);
@yudaprawira
yudaprawira / .htaccess
Created September 1, 2016 03:37
redirect www to mobile site using htaccess
# Check if mobile=1 is set and set cookie 'mobile' equal to 1
RewriteCond %{QUERY_STRING} (^|&)mobile=1(&|$)
RewriteRule ^ - [CO=mobile:1:%{HTTP_HOST}]
# Check if mobile=0 is set and set cookie 'mobile' equal to 0
RewriteCond %{QUERY_STRING} (^|&)mobile=0(&|$)
RewriteRule ^ - [CO=mobile:0:%{HTTP_HOST}]
# cookie can't be set and read in the same request so check
RewriteCond %{QUERY_STRING} (^|&)mobile=0(&|$)
@yudaprawira
yudaprawira / .htaccess
Created September 1, 2016 03:39
redirect mobile to www site using htaccess
RewriteEngine On
RewriteCond %{HTTP_HOST} ^m\. [NC]
#RewriteCond %{REQUEST_URI} !^/(media/) [NC]
RewriteCond %{HTTP_USER_AGENT} !(android|blackberry|googlebot-mobile|iemobile|iphone|ipod|opera\smobile|palmos|webos) [NC]
RewriteRule ^ http://www.juara.in%{REQUEST_URI} [L,R=302]
@yudaprawira
yudaprawira / .htaccess
Created September 1, 2016 03:47
Compress HTML, CSS, JavaScript, Text, XML and fonts
<IfModule mod_deflate.c>
# Compress HTML, CSS, JavaScript, Text, XML and fonts
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
AddOutputFilterByType DEFLATE application/x-font
AddOutputFilterByType DEFLATE application/x-font-opentype
AddOutputFilterByType DEFLATE application/x-font-otf
AddOutputFilterByType DEFLATE application/x-font-truetype
AddOutputFilterByType DEFLATE application/x-font-ttf
@yudaprawira
yudaprawira / .htaccess
Created September 1, 2016 03:47
CACHING
## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType text/css "access plus 1 month"
ExpiresByType application/font-woff "access plus 1 year"
ExpiresByType application/font-woff2 "access plus 1 year"
<ifModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file .(html?|txt|css|js|php|pl|woff2)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>
@yudaprawira
yudaprawira / .htaccess
Created September 1, 2016 03:56
add triling slash url
#Add Trailing slash
RewriteCond %{REQUEST_URI} !(/$|\.)
RewriteRule (.*) %{REQUEST_URI}/ [R=301,L]
@yudaprawira
yudaprawira / .htaccess
Created September 1, 2016 04:03
htaccess protect pretty url with password
# Do the regex check against the URI here, if match, set the "require_auth" var
SetEnvIf Request_URI ^/admin require_auth=true
# Auth stuff
AuthUserFile /home/juarain/.htpasswds/admin/.htpasswd
AuthName "Password Protected"
AuthType Basic
# Setup a deny/allow
Order Deny,Allow
@yudaprawira
yudaprawira / .htaccess
Created September 1, 2016 04:13
protect directory
AuthName "Secure Area"
AuthType Basic
AuthUserFile /path/to/your/directory/.htpasswd
require valid-user