Skip to content

Instantly share code, notes, and snippets.

@shuliu
shuliu / README.md
Last active April 7, 2016 06:22
PSR-2 Build System using Sublime Text

PSR-2 Build System using Sublime Text

Installation

Open a new terminal and install Composer:

curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer

Once that has finished installing and moved, install the PHP-CS-Fixer Composer package globally:

@shuliu
shuliu / curl_get_json_and_remove_html_tag.php
Last active May 27, 2016 05:54
curl get json and remove html tag, \r\n
<?php
$url = 'http://scare.senao.com.tw/api/post/list/?category=latest';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json', 'Accept: application/json']);
$output = curl_exec($ch);
curl_close($ch);
$json = json_decode($output, true);
@shuliu
shuliu / print_r.js
Created September 2, 2016 10:50
js console style
/**
* pr
* 比較寬的console.log,
* 若代入兩個個參數則第二個參數會變成title並換行顯示第一個參數
* @param desc
* @param title
* @return boolean
*/
function pr(desc, title) {
if (!debug) return false;
@shuliu
shuliu / proxy.sh
Last active December 9, 2016 04:00
OSX change location trigger to change proxy
# =================================
# [設定] 修改"位置"時調整 proxy (start)
# 來源文章 http://qiita.com/uetchy/items/b9991d1f86b23f4a184d
# 寫在 .bash_profile 或是 .zshrc
# 觸發時間點為切換後開啟終端機或是 iTerm 這類工具讓他讀取到這段 code
# =================================
proxy=這邊放proxy名稱
switch_trigger=這邊放位置的名稱
@shuliu
shuliu / filter.js
Created May 19, 2017 10:09
json filter
collection = [
{ "Id": 1, "color": "blue" },
{ "Id": 2, "color": "green" },
{ "Id": 3, "color": "yellow" },
{ "Id": 4, "color": "green" },
{ "Id": 5, "color": "blue" },
{ "Id": 6, "color": "yellow" }
]
@shuliu
shuliu / html
Created June 8, 2017 06:02
pulldownChangeSelector
<div class="pulldownChange-group triggerStoreZipCode">
<input type="hidden" class="pulldownChange-zip" id="cartZip3" name="cartZip3">
<select class="pulldownChange-city" data-val="<?php echo $cartMaster['cart_receipt_city'] ?>" ></select>
<select class="pulldownChange-town" data-val="<?php echo $cartMaster['cart_receipt_district'] ?>" ></select>
</div>
@shuliu
shuliu / credit-card-format.js
Created June 8, 2017 08:30
信用卡 input 欄位格式化
$('#credit card').on('keyup keypress change', function () {
var start = this.selectionStart;
var end = this.selectionEnd;
var oldleft = this.value.substr(0,start).replace(/[^ ]/g, '').length;
this.value = this.value.replace(/\W/gi, '').replace(/(.{4})/g, '$1 ').substr(0, 19);
var newleft = this.value.substr(0,start).replace(/[^ ]/g, '').length;
start += newleft - oldleft;
end += newleft - oldleft;
this.setSelectionRange(start, end);
});
@shuliu
shuliu / defineProperty.demo.js
Created June 15, 2017 03:56
defineProperty
Object.defineProperty(HTMLSelectElement.prototype, 'emptyOptions', {get: function () {
// empty options
this.options.length = 0;
}});
@shuliu
shuliu / XMLHttpRequest.js
Created July 7, 2017 10:57
XMLHttpRequest post data and callback
(function(){
// https://www.googleapis.com/urlshortener/v1/url?shortUrl=https://goo.gl/tzn9Hx&key=AIzaSyCRIa3jCZ1C25iOaCqg7KnU8T2dlK5HPeo
// https://developer.mozilla.org/zh-TW/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest
var getLongUrl = function() {
var ajax = new XMLHttpRequest();
ajax.addEventListener("progress", updateProgress, false);
ajax.addEventListener("load", transferComplete, false);
ajax.addEventListener("error", transferFailed, false);
ajax.addEventListener("abort", transferCanceled, false);
ajax.open('get', 'http://my.sample.path.com/');
@shuliu
shuliu / textarea-rows.html
Created November 17, 2017 05:21
check textarea rows overline
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>textarea rows</title>
</head>
<body>
<textarea name="" id="ta" cols="30" rows="5"></textarea>
<br>
<button id="submit">submit</button>