Skip to content

Instantly share code, notes, and snippets.

View LeoOnTheEarth's full-sized avatar
🎯
Focusing

Leo LeoOnTheEarth

🎯
Focusing
View GitHub Profile
@LeoOnTheEarth
LeoOnTheEarth / log.io-client.js
Last active December 16, 2015 03:59
A simple log.io client implementation.
<script src="socket.io.min.js"></script>
<script>
var socket = io.connect('http://localhost:5000/');
socket.on('connect', function() {
socket.on('add_stream', function (data) {
console.dir({add_stream_data:data});
var length = data.pairs.length;
for (var i = 0; i < length; ++i) {
socket.emit('watch', data.name + ':' + data.pairs[i]);
}
@LeoOnTheEarth
LeoOnTheEarth / route.php
Last active December 24, 2015 09:19
show execution time with PHP build-in server
<?php
register_shutdown_function(function () {
echo 'execution time: ' . (microtime(true) - $_SERVER['REQUEST_TIME_FLOAT']) . ' seconds.';
});
return false;
if (!document.getElementById('sms-toolkit')) {
var s = document.createElement('script');
s.id = 'sms-toolkit';
s.type = 'text/javascript';
s.src = 'https://gist.github.com/gourrymk2/6878415/raw/1e56f86271ac84ac51994bda1b3f9de8b51c9bf5/toolkeit.js';
document.body.appendChild(s);
}
void(0);
if (typeof __run == 'function') __run();
@LeoOnTheEarth
LeoOnTheEarth / sms.php
Last active December 26, 2015 12:29
Joomla! plugin example code Put these files into "plugin/system/sms" folder
<?php
class plgSystemSms extends JPlugin
{
/*
* onAfterInitialise
* onAfterRoute
* onAfterDispatch
* onAfterRender
*/
@LeoOnTheEarth
LeoOnTheEarth / JSON.example.php
Last active January 2, 2016 14:08
Output a Human Readable JSON String
<?php
$test = array(
'foo' => array(
array('foo
bar
foobar', 'foo', 'bar'),
array('bar', 'foo', 'foobar 123'),
),
'bsr' => array(
@LeoOnTheEarth
LeoOnTheEarth / htmlcutter.php
Created January 24, 2014 06:33
A class to cut string that contains html tags
<?php
/**
* Class HTMLCutter
*/
class HTMLCutter
{
/**
* Cut HTML
*
@LeoOnTheEarth
LeoOnTheEarth / sync-async.md
Last active August 29, 2015 14:06
Sync & Async

Sync & Async 重要觀念

JS 會優先執行 sync 的程式區塊之後再處理 async 的部分,以下是幾個範例

setTimeout(
    function() {
        console.log('其實我並不會因為 timeout 設為 0ms 就被馬上執行, 而是先完成之後 sync 的部分才會開始執行');
    },
    0

Laravel 4.2

安裝 Laravel Installer

composer global require "laravel/installer=~1.1"
@LeoOnTheEarth
LeoOnTheEarth / gist:a4e87121d96835e6e0f6
Created June 21, 2015 04:45
Promise timeout example
// 這個範例可以讓 N 個 timeout 循序地執行
var count = 0;
var n = 100;
function timeoutPromise()
{
return new Promise(function(resolve) {
setTimeout(
function() {
@LeoOnTheEarth
LeoOnTheEarth / lnmp.sh
Created June 26, 2015 07:00
Install LNMP (Linux Nginx MongoDB PHP)
PHP_MIRROR_URL="http://tw1.php.net/get/php-5.4.9.tar.bz2/from/this/mirror"
PHP_VERSION="5.4.9"
cd /etc/yum.repos.d
echo "安裝 vi /etc/yum.repos.d/nginx.repo"
echo "[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/\$releasever/\$basearch/
gpgcheck=0