Skip to content

Instantly share code, notes, and snippets.

View ebta's full-sized avatar

Ebta Setiawan ebta

View GitHub Profile
@ebta
ebta / indexedDB_info.js
Last active July 18, 2018 07:53
Check indexedDB usage size
// First method
navigator.storage.estimate().then((data)=>console.log(data))
// OR second method
navigator.webkitTemporaryStorage.queryUsageAndQuota (
function(usedBytes, grantedBytes) {
console.log('we are using ', usedBytes, ' of ', grantedBytes, 'bytes');
},
function(e) {
console.log('Error', e);
@ebta
ebta / redirect.sh
Last active July 19, 2018 04:49
Enable redirect (port forwarding) on Apache
# Before, install mod proxy and proxy_http
# a2enmod proxy proxy_http
<VirtualHost *:80>
ServerName sub.yourdomain.com
ProxyPreserveHost On
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# Redirect/forward subdomain to local port
@ebta
ebta / backupdb.sh
Created July 21, 2018 14:22
Backup MySQL /MariaDB Database using bash script
#! /bin/bash
# Buat user 'USERDB' dengan privileges :
# SELECT, RELOAD, SHOW DATABASES, LOCK TABLES, TRIGGER, SHOW VIEW
NOW=$(date +"%F_%H%M%S")
BACKUP_DIR="/data/backup/databases"
BACKUP_LOG="$BACKUP_DIR/backup.log"
MYSQL_USER="USERDB"
MYSQL_PSWD="YOUR_PASSWORD"
MYSQL=/usr/bin/mysql
@ebta
ebta / full_join.sql
Created July 27, 2018 08:57
How to do FULL [OUTER] JOIN in MySQL (MariaDB)
-- First method
SELECT * FROM t1
LEFT JOIN t2 ON t1.id = t2.id
UNION
SELECT * FROM t1
RIGHT JOIN t2 ON t1.id = t2.id
-- Second Method
-- The query above works for special cases where a FULL OUTER JOIN operation would not produce any duplicate rows.
-- The query above depends on the UNION set operator to remove duplicate rows introduced by the query pattern.
@ebta
ebta / allow_remote.sql
Last active September 27, 2018 07:19
Allow Remote MySQL (MariaDB) CentOS
-- Edit dulu file my.cnf ( biasanya di sini /etc/my.cnf )
-- [mysqld]
-- # bind sesuai dengan IP yg diijinkan 0.0.0.0 = allow all IP4
-- bind-address=0.0.0.0
-- # Disabling symbolic-links is recommended to prevent assorted security risks
-- symbolic-links=0
-- port=3306
-- Kemudian restart mysql: sudo systemctl restart mysql
-- Login ke mysql melalui terminal (ssh): mysql -uroot -p
@ebta
ebta / allow remote mysql.md
Last active September 14, 2020 05:13
Allow Remote MySQL (MariaDB) in Ubuntu 18.04

Check Firewall

Firstly, if ufw firewall is enabled, ensure you have a rule for MySQL sudo ufw allow mysql

Restart the service
sudo service ufw restart

Check MySQL config

@ebta
ebta / iframe-full-window.html
Created April 22, 2019 09:12
Load web app in iFrame with Full Window (no-border/margin)
<!DOCTYPE html>
<html>
<head>
<title>Your App Tittle</title>
</head>
<body>
<iframe src="https://yourapp.com/appdir" style="position:fixed; top:0px; left:0px; bottom:0px; right:0px; width:100%; height:100%; border:none; margin:0; padding:0; overflow:hidden; z-index:999999;">
Browser anda tidak mendukung iframe.
</iframe>
</body>
@ebta
ebta / async_sample.js
Last active December 13, 2019 07:07
Example using async library for paralel or series
// Doc Async : https://caolan.github.io/async/v3/index.html
// Download : http://www.jsdelivr.com/projects/async
function task(item, callback) {
setTimeout(function() {
console.info(item + ' selesai');
// null menandakan fungsi berhasil
callback(null, item * 3);
// jika gagal atau error, return dengan selain null
// misal : callback('error','keterangan error');
@ebta
ebta / mysql_balance.sql
Last active June 25, 2022 09:43
Query menghitung balance (saldo) di MySQL
SET @saldo = 3000000;
SELECT id_sample, uraian, debet, kredit, (@saldo := @saldo + (debet - kredit)) as Saldo
FROM sample;
-- Alternatif as one query statements
SELECT s.id_sample, s.uraian, s.debet, s.kredit, (@saldo := @saldo + (s.debet - s.kredit)) as Saldo
FROM (SELECT @saldo := 3000000) AS dummy
CROSS JOIN sample s;
@ebta
ebta / index.html
Created September 10, 2019 09:33
PHP - Flushing While Loop Data with Ajax
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>