Skip to content

Instantly share code, notes, and snippets.

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

M ABD AZIZ ALFIAN aalfiann

🏠
Working from home
View GitHub Profile
@aalfiann
aalfiann / minify_page.php
Created November 8, 2017 08:08
Function to minify your page on the fly using php
/** To use minify with ob_start just put at the top of your page
* Warning:
* - This function still not support to remove any comments in javascript
* - Minifying on buffering will take so much memory and it not recomended for high traffic
*/
function sanitize_output($buffer) {
$search = array(
// Minify HTML
'/\>[^\S ]+/s', // strip whitespaces after tags, except space [^1]
@aalfiann
aalfiann / proxy_curl.php
Created November 25, 2017 04:47 — forked from mlconnor/proxy_curl.php
PHP CURL Code to grab a file through a proxy
<?php
print get_file('http://www.google.com');
function get_file($url) {
$curl = curl_init();
$options = default_ops(array(CURLOPT_URL => $url));
curl_setopt_array($curl, $options);
$output = curl_exec($curl);
@aalfiann
aalfiann / url_check.php
Last active September 2, 2023 21:58
PHP Curl to check is url exist or not (support redirected url)
<?php
/**
* Determine that url is exists or not
*
* @param $url = The url to check
**/
function url_exists($url) {
$result = false;
$url = filter_var($url, FILTER_VALIDATE_URL);
<?php
/**
* Stream or Download big files using php (support multipart and remote url)
* @param $file is the path or remote url
* @param $size is the filesize of the file
*/
function streamDownload($file,$size,$mime='video/mp4') {
header('Content-type: ' . $mime);
header('Content-Disposition: attachment; filename="' . basename($file) . '"');
<?php
echo preg_replace('#<a.*?>([^>]*)</a>#i', '$1', $str);
?>
@aalfiann
aalfiann / sharing_memory.html
Created January 17, 2018 04:34
Sharing memoryStorage between tabs for secure multi-tab authentication
<!DOCTYPE html>
<html>
<head>
<title>Sharing memoryStorage between tabs for secure multi-tab authentication</title>
</head>
<body>
<h3><a href=''>memoryStorage</a></h3>
<h3 id="stData"></h3>
<button id="btnSet">Set memory storage</button>
@aalfiann
aalfiann / sharing_session.html
Created January 17, 2018 04:35
Sharing sessionStorage between tabs for secure multi-tab authentication
<!DOCTYPE html>
<html>
<head>
<title>Sharing sessionStorage between tabs for secure multi-tab authentication</title>
</head>
<body>
<h3><a href=''>sessionStorage</a></h3>
<h3 id="stData"></h3>
<button id="btnSet">Set session storage</button>
@aalfiann
aalfiann / gist:c0cbb90b8cbdd7845da0359245bdbdb1
Created February 1, 2018 12:13 — forked from yonjah/gist:5082855
Blocking DDOS bots with JavaScript for fun and profit! Or how easy it is to break the current protection methods and how to make it better.
TL;DR - jump to the challenge at the end
====ON BLOCKING EVIL BOTS=====
On a resent job interview I had for "Incapsula" a few days ago I was put to the challenge to break
their bot protection mechanism. Apparently node.js is not that common among bot writes and most bots
are not able to run javascript.
The challenge had two parts -
1. find what the code does.
2. implement a bot that will break the code without using js.
3. think how to make this code unbreakable
@aalfiann
aalfiann / simple_encrypt.js
Created February 10, 2018 16:18
JS Simple encryption
var key = "SXGWLZPDOKFIVUHJYTQBNMACERxswgzldpkoifuvjhtybqmncare";
// matches ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ
function encodeStr(uncoded) {
uncoded = uncoded.toUpperCase().replace(/^\s+|\s+$/g,"");
var coded = "";
var chr;
for (var i = uncoded.length - 1; i >= 0; i--) {
chr = uncoded.charCodeAt(i);
coded += (chr >= 65 && chr <= 90) ?
@aalfiann
aalfiann / .gitignore
Created February 13, 2018 08:42 — forked from SaltwaterC/.gitignore
php cache curl
/cache/