Skip to content

Instantly share code, notes, and snippets.

View fakhrinf's full-sized avatar
💻
Coding in progress

Fakhri Nurfauzan fakhrinf

💻
Coding in progress
View GitHub Profile
@fakhrinf
fakhrinf / fisheryates.php
Last active January 29, 2020 05:43
Fisher yates test with one mil data
This file has been truncated, but you can view the full file.
<?php
function mdfisheryates(&$arr)
{
$x = [];
$hasil = [];
$j=0;
for($i = count($arr)-1; $i > 0; --$i) {
$r = rand(0, $i);
@fakhrinf
fakhrinf / htmltodoc.js
Created May 27, 2019 07:23
convert html to .doc
function downloaddoc() {
var header = "<html xmlns:o='urn:schemas-microsoft-com:office:office' "+
"xmlns:w='urn:schemas-microsoft-com:office:word' "+
"xmlns='http://www.w3.org/TR/REC-html40'>"+
"<head><meta charset='utf-8'><title></title></head><body>";
var footer = "</body></html>";
var sourceHTML = header+document.getElementById("printarea").innerHTML+footer;
var source = 'data:application/vnd.ms-word;charset=utf-8,' + encodeURIComponent(sourceHTML);
var fileDownload = document.createElement("a");
@fakhrinf
fakhrinf / jstoexcel
Last active May 17, 2019 02:10
convert html to excel.
<script>
function exportexcel() {
var htmls = "";
var uri = 'data:application/vnd.ms-excel;base64,';
var template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body><table>{table}</table></body></html>';
var base64 = function(s) {
return window.btoa(unescape(encodeURIComponent(s)))
};
var format = function(s, c) {
@fakhrinf
fakhrinf / selenium-install
Created May 8, 2019 01:17 — forked from kaze/selenium-install
How to install Chrome, ChromeDriver and Selenium on CentOS. Plus a sample scraping script.
#!/usr/bin/env bash
# https://developers.supportbee.com/blog/setting-up-cucumber-to-run-with-Chrome-on-Linux/
# https://gist.github.com/curtismcmullan/7be1a8c1c841a9d8db2c
# http://stackoverflow.com/questions/10792403/how-do-i-get-chrome-working-with-selenium-using-php-webdriver
# http://stackoverflow.com/questions/26133486/how-to-specify-binary-path-for-remote-chromedriver-in-codeception
# http://stackoverflow.com/questions/40262682/how-to-run-selenium-3-x-with-chrome-driver-through-terminal
# http://askubuntu.com/questions/760085/how-do-you-install-google-chrome-on-ubuntu-16-04
# Versions
CHROME_DRIVER_VERSION=`curl -sS chromedriver.storage.googleapis.com/LATEST_RELEASE`
@fakhrinf
fakhrinf / extracttext.php
Last active April 23, 2019 01:57
Sample extract numeric from text. In this example we get pulsa balance from a message so, we can do some operation with the balance.
<?php
$a = "-";
$b = "-";
$e = "-";
$a = (is_null(getbalance($a))) ? 0 : getbalance($a);
$b = (is_null(getbalance($b))) ? 0 : getbalance($b);
$e = (is_null(getbalance($e))) ? 0 : getbalance($e);
echo "{$a} - {$b} = {$e} | ";
if($e == (intVal($a) - intVal($b)) && (intVal($a) != 0 && intVal($b) != 0 && intVal($e) != 0)){
echo "OK";
@fakhrinf
fakhrinf / firemessage.php
Last active August 6, 2019 17:45
Firebase send push notification with php
<?php
function sendFCM($title, $message, $firebasedevicetoken)
{
$curl = curl_init();
$notification = [
'title' => $title,
'body' => $message,
'image' => $image,
];
@fakhrinf
fakhrinf / fisheryates.php
Created December 20, 2018 01:57
PHP implementation of fisher yates shuffle algorithm
ffle($data, $count)
{
$retVal = array();
$ind = array();
$index = 0;
for ($i = 0; $i < $count; ++$i)
$ind[$i] = 0;
for ($i = 0; $i < $count; ++$i)
<?php
/**
* It's an algorithm for generating a random permutation of a finit sequence - in plain terms, the algorithm shuffles the sequence.
*
* Reference: https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle
*/
function MyShuffle(&$arr) {
@fakhrinf
fakhrinf / gist:93b3caf73af59036135646ec2659311a
Created November 28, 2017 07:55 — forked from guylaor/gist:3eb9e7ff2ac91b7559625262b8a6dd5f
Installing Selenium with Python 3 on mac
Install python 3
create a virtualenv and then
pip install selenium
then install chrome driver:
brew install chromedriver
to test, run this script - notice the location of the chrome driver
@fakhrinf
fakhrinf / ci3.htaccess
Created June 11, 2017 16:12
remove index.php on ci3
Steps To Remove index.php using .htaccess:-
Step:-1 Open the file config.php located in application/config path. Find and Replace the below code in config.php file.
// Find the below code
$config['index_page'] = "index.php"
// Remove index.php