Skip to content

Instantly share code, notes, and snippets.

View asika32764's full-sized avatar

Simon Asika asika32764

View GitHub Profile
@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' ])) . '/');
@asika32764
asika32764 / .htaccess-prevent-php-access.conf
Created May 26, 2019 10:44
.htaccess to prevent php access except index.php
<Files *.php>
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
</Files>
<Files index.php>
Order Allow,Deny
Allow from all
</Files>
Vue.directive('calendar', {
inserted(el, binding) {
// :v-calendar="{ format: 'YYYY-MM-DD HH:mm:ss' }"
const options = Object.assign({
// Some default options
// Use FontAwesome icons
icons:{
time: 'fa fa-clock-o',
date: 'fa fa-calendar',
@asika32764
asika32764 / vue-select2-directive.js
Created February 20, 2019 14:02
Vue Select2 Directive
function updateFunction (el, binding) {
Vue.nextTick(function () {
// :v-select2="{ options... }"
let options = binding.value || {};
// set up select2
$(el).select2(Object.assign({}, {
// Default options
}, options))
.on("select2:select select2:unselect", (e) => {
@asika32764
asika32764 / url-parsing.js
Created December 6, 2018 16:37
Javascript URL parsing regex
const regex = /^((?<scheme>[^:\/?#]+):)?(\/\/(?<authority>(?<domain>[^\/?#:]*)(:(?<port>[0-9]*))?))?((?<path>[^?#]*)\\?)?((?<query>([^#]*)))?(#(?<fragment>(.*)))?/;
'foo://example.com:8042/over/there?name=ferret#nose'.match(regex);
/* Result:
authority: "example.com:8042"
domain: "example.com"
fragment: "nose"
path: "/over/there"
port: "8042"
@asika32764
asika32764 / polymer-slot-without-shadowdom.js
Created April 7, 2018 20:00
Polymer.Element without ShadowDOM but support slots
class LightDom extends Polymer.Element {
_attachDom(dom) {
const slots = dom.querySelectorAll('slot[name]');
slots.forEach((slot) => {
const name = slot.getAttribute('name');
const tmpl = this.querySelector(`[slot=${name}]`);
if (tmpl) {