Skip to content

Instantly share code, notes, and snippets.

View ethaizone's full-sized avatar
💭
I love AI.

Nimit Suwannagate ethaizone

💭
I love AI.
View GitHub Profile
@ethaizone
ethaizone / custom_base_converter.php
Created May 17, 2016 11:05
Custom base number converter.
<?php
/**
* Code demo for convert base number with custom base character map.
* Not support negative number.
*/
// base from toHex on http://hashids.org/
function intToChar($input)
{
<?php
use Redis;
use Exception;
/**
* Redis cache - Port from Phalcon Cache
* Cut intergate from backend and front cache
* I don't test or try run it. This pass on php linter.
* When I want to use it, I will check later.
@ethaizone
ethaizone / server_time_sync.js
Last active November 17, 2025 18:25
Sync server time to client browser with JS. Implement follow Network Time Protocol.
// Original from http://stackoverflow.com/questions/1638337/the-best-way-to-synchronize-client-side-javascript-clock-with-server-date
// Improved by community and @jskowron
// Synchronize client-side clock with server time using an approximation of NTP
let serverTimeOffset = null;
function getServerTime(callback) {
if (serverTimeOffset === null) {
const scripts = document.getElementsByTagName("script");
const currentScriptURL = scripts[scripts.length - 1].src;
@ethaizone
ethaizone / test_math_random_possible.js
Created March 8, 2016 09:03
Test Math.random() result.
var res = {0:0,1:0};
var r;
for(var i = 0; i < 100; i++) {
r = Math.floor((Math.random() * 2) + 0);
res[r]++;
}
console.log(res);
@ethaizone
ethaizone / mb_str_split.php
Created January 23, 2016 16:52
mb_str_split function. multibyte version of str_split.
<?php
if (!function_exists('mb_str_split')) {
/**
* Convert a multibyte string to an array
*
* @param string $string The input string.
* @param integer $split_length Maximum length of the chunk.
* @param string $encoding The encoding parameter is the character encoding.
* @return array
@ethaizone
ethaizone / ProductControllerTest.php
Last active November 24, 2015 17:08
Laravel 5.1 - Run testcase with real model in memory.
<?php
use Illuminate\Foundation\Testing\DatabaseMigrations;
class ProductControllerTest extends TestCase
{
use DatabaseMigrations;
protected $testSubject = null;
@ethaizone
ethaizone / date_thai_helper.php
Last active October 1, 2015 11:08
Date in Thai
<?php
/**
* Date function for Thai
* Lazy code version.
*
* Don't remove copyright.
*
* @author Nimit Suwannagate <[email protected]>
*/
@ethaizone
ethaizone / array.php
Created June 11, 2015 04:05
Array collection helpers. Ported from Laravel4.
<?php
/**
* Array collection helpers
*
* Ported from Laravel4.
* By EThaiZone
*/
if ( ! function_exists('array_add'))
{
@ethaizone
ethaizone / dq.php
Created March 24, 2015 07:36
Simple laravel helper - Dump Query
<?php
// write by me.
if ( ! function_exists('dq'))
{
function dq($offset = 0, $length = null, $echoOnly = false)
{
s(array_slice(DB::getQueryLog(), $offset, $length));
if ($echoOnly == false)
@ethaizone
ethaizone / helper-web-path.php
Created January 26, 2015 14:35
Lazy method but work - Helper for get baseUrl and basePath for website/webapp development
<?php
if ( ! function_exists('basePath'))
{
/**
* Get the path to the base of the install.
*
* @param string $path
* @return string
*/