Skip to content

Instantly share code, notes, and snippets.

View asika32764's full-sized avatar

Simon Asika asika32764

View GitHub Profile
@asika32764
asika32764 / dbExport.java
Created December 3, 2023 10:32 — forked from frontrangerider2004/dbExport.java
Export all SQLite database files from your Android Application's private data directory to the SD Card
public static void exportAllDatabases(final Context context) {
Log.d(LOG_TAG, "exportAllDatabases: ");
File sd = Environment.getExternalStorageDirectory();
if (sd.canWrite()) {
final File[] databases = new File(context.getFilesDir().getParentFile().getPath() + "/databases").listFiles();
for (File databaseFile: databases) {
final String backupFilename = databaseFile.getName() + "-" + Build.SERIAL +
"-" + System.currentTimeMillis() + ".db";
File backupFile = new File(sd, backupFilename);
FileChannel inputChannel = null;
@asika32764
asika32764 / arc-places.json
Created June 13, 2023 20:25 — forked from jthomassie/arc-places.json
d3 globe arcs
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@asika32764
asika32764 / check-vat.php
Created February 24, 2023 10:03
(PHP) 台灣公司統編驗證函式
<?php
/**
* 依照 2023 年最新規則進行驗證
*
* @see https://www.fia.gov.tw/singlehtml/3?cntId=c4d9cff38c8642ef8872774ee9987283
*
* @param string $vat
*
* @return bool
@asika32764
asika32764 / tinymce-fetch-remote-img.js
Last active October 25, 2022 17:31
TinyMCE fetch remote images to local
editor.on('PastePostProcess', (e) => {
setTimeout(async () => {
const doc = new DOMParser().parseFromString(editor.getContent(), `text/html`);
const promises = [];
for (const img of doc.querySelectorAll('img')) {
const src = img.src;
const p = new Promise((resolve) => {
fetch(src)
@asika32764
asika32764 / 0-register-ssh-protocol.md
Last active September 9, 2022 18:24
Register ssh URL link protocol (ssh://) in Windows

Register ssh URL link (protocol) in Windows

Download register-ssh-protocol.reg and double click to install it.

You can change the position of open-ssh-protocol.js before install.

Then, download the open-ssh-protocol.js file to C:\bin\.

You can also change the terminal app path as you want.

@asika32764
asika32764 / preg_replace_test.php
Created June 29, 2022 19:00 — forked from eduardomello/preg_replace_test.php
use of PHP preg_replace() to add basepath to src and href
<?php
/*
* Script that shows how to insert a basepath on HTML tags
* It looks for link, script and img tags that do not contain the
* determined basepath or a external URL
*/
// BasePath to insert in string when necessarry
$basePath = "/project/site/";
$escapedBasePath = str_replace("/", "\/", $basePath);
@asika32764
asika32764 / mini_google_authenticator.php
Created April 22, 2022 10:30 — forked from Cojad/mini_google_authenticator.php
Very small implementation of Google's OTP Authenticator
<?php
// copied from python code at https://stackoverflow.com/a/23221582/3103058
function base32_decode($key) {
// https://www.php.net/manual/en/function.base-convert.php#122221
$key = strtoupper($key);
list($t, $b, $r) = array("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567", "", "");
foreach(str_split($key) as $c)
$b = $b . sprintf("%05b", strpos($t, $c));
foreach(str_split($b, 8) as $c)
$r = $r . chr(bindec($c));
@asika32764
asika32764 / php-class-to-read-psd-files
Created March 11, 2022 16:17 — forked from devluis/php-class-to-read-psd-files
PHP class to read PSD files
<?
/* This file is released under the GPL, any version you like
*
* PHP PSD reader class, v1.3
*
* By Tim de Koning
*
* Kingsquare Information Services, 22 jan 2007
*
* example use:
@asika32764
asika32764 / sql-splitter.md
Last active January 9, 2020 17:22
PHP - BIG SQL File Splitter as Iterator

SQL Splitter as Iterator

This is a class that can split BIG SQL file or string as iterator so that can help us save memory when importing SQL to database.

Composer version see here: https://github.com/asika32764/sql-splitter

Usage

$it = SqlSplitter::splitFromFile(__DIR__ . '/path/to/db.sql');
@asika32764
asika32764 / php-base-path.php
Created June 1, 2019 04:59
Very simple way to get PHP URL path with subfolder.
<?php
define('APP_ROOT', __DIR__); // Change this to root dir.
define('HTTP_TYPE', (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') || $_SERVER['SERVER_PORT'] === 443 ? 'https' : 'http');
define('HTTP_ROOT', $_SERVER['HTTP_HOST']);
define('BASE_URL', HTTP_TYPE . '://' . HTTP_ROOT . substr(APP_ROOT, strlen($_SERVER[ 'DOCUMENT_ROOT' ])) . '/');