Skip to content

Instantly share code, notes, and snippets.

View ethaizone's full-sized avatar
💭
It's same on Gitlab.

Nimit Suwannagate ethaizone

💭
It's same on Gitlab.
View GitHub Profile
@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 / server_time_sync.js
Last active December 21, 2024 11:43
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;
<?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 / 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)
{
@ethaizone
ethaizone / redirect_mobile_to_app_store.php
Last active May 24, 2022 17:56
[PHP] Auto redirect to app store. (Android/IOS)
<?php
// android store
if (preg_match('#android#i', $_SERVER ['HTTP_USER_AGENT'])) {
header('Location: market://details?id=com.google.android.apps.maps');
exit;
}
// ios
if (preg_match('#(iPad|iPhone|iPod)#i', $_SERVER ['HTTP_USER_AGENT'])) {
@ethaizone
ethaizone / fake_code_typer.ahk
Last active November 11, 2024 21:33
Auto typer from file - Execute by autohotkey.com
; Auto typer from file
; Write by EThaiZone @ 2016
; For fake code typing. lol
; Press Ctrl+F11 to start/stop
; Press F11 to pause/resume
#MaxThreads 2
#MaxThreadsPerHotkey 2
PressKey := true
@ethaizone
ethaizone / duck_punching.js
Created June 24, 2016 07:07
Example Duck punching in JS
/**
* Example Duck punching in Javascript
* @author Nimit Suwannagate <[email protected]>
*/
// create class calculator
function Calculator() {
}
// add method
@ethaizone
ethaizone / fungdham.php
Last active June 27, 2016 03:51
ไฟล์คำสั่ง PHP สำหรับโหลด mp3 จากเว็บ fungdham.com - ต้องการ PHP Simple HTML DOM Parser - สร้างโฟลเดอร์แยกตามลำดับชั้นให้
<?php
set_time_limit(0);
// โหลด simple_html_dom.php มาจาก http://simplehtmldom.sourceforge.net/
include 'simple_html_dom.php';
function saveFile($url, $file) {
if(file_exists($file)) {
@ethaizone
ethaizone / short_note.js
Created September 12, 2016 11:27
Short note
// Create class
function Cart(){
// constructur
// protected variable
var myProtected = 'secret';
// protected method
var protectedFunction = function() {
@ethaizone
ethaizone / chmod_number.php
Last active September 16, 2016 07:43
Create chmod number notation
<?php
/**
* Copyright @ 2016 by Nimit Suwannagate <[email protected]>. All rights reserved.
*/
// Run this file in cli mode for best view.
// Try to edit this one.
$maxNumber = 500000000000;