Skip to content

Instantly share code, notes, and snippets.

View tpai's full-sized avatar
🌴
On vacation in Spain

Tony Pai tpai

🌴
On vacation in Spain
View GitHub Profile
@tpai
tpai / index.html
Created May 10, 2017 13:44
Center middle image and maintain aspect ratio // source http://jsbin.com/yefeju
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Center middle image and maintain aspect ratio</title>
<style id="jsbin-css">
html, body {
height: 100%;
}
@tpai
tpai / predicting_test.md
Last active July 20, 2017 06:33
模擬試題

模擬試題

重點:針對履歷客製化試題、函式庫工具原理解析。

前端函式庫

React.js

原理

@tpai
tpai / jsbin.gabugay.js
Last active July 11, 2017 04:13
URL String Replacement// source http://jsbin.com/gabugay
'use strict';
function resize(str, size) {
if (typeof size === 'undefined') return str;
return str.replace(/(https?):\/\/picture-original.cdn.com\/([^.]*).(jpe?g|png|gif)/ig, function (match, protocol, key, ext) {
return protocol + '://picture-thumb.cdn.com/' + key + '-' + size + '.' + ext;
});
}
console.assert(resize('https://picture-original.cdn.com/page-localhost-2017710.jpg', 300) === 'https://picture-thumb.cdn.com/page-localhost-2017710-300.jpg', { msg: 'test1 failed' });
@tpai
tpai / live_stream.md
Created July 13, 2017 10:53
live stream related collection

音視頻技術參考

https://github.com/gwuhaolin/blog/issues/5
https://read01.com/zD2OdO.html
https://github.com/ossrs/srs
https://imququ.com/post/html5-live-player-1.html
http://blog.ucloud.cn/?p=694
@tpai
tpai / _jwt.md
Last active November 13, 2017 04:18
Where to store JWT token, Cookies or HTML5 WebStorage?

Where to store JWT token, cookies or HTML5 WebStorage?

Before reading this article I have no idea about JWT authetication and think there's no difference bewteen them, after that I was wrong, really needs to pay more attention on security issue.

Cookies

  • HttpOnly flag: make sure cookies not be manipulated by javascript (immune to XSS)
  • Secure flag: guarantee the cookies is only sent over HTTPS
  • Prevent CSRF: check Referer and Origin from API
@tpai
tpai / multi-trackers.md
Created August 22, 2017 08:29
Trackers related

Working with multiple trackers

GA

ga('create', 'UA-XXXXX-Y', 'auto');
ga('create', 'UA-XXXXX-Z', 'auto', 'clientTracker');
@tpai
tpai / addArecord.sh
Last active December 10, 2018 05:08
AWS cheatsheet
HOST_ZONE_ID=
ACTION=
DNS_NAME=
# Add A record for s3 website hosting using custom domain
# Ref: http://docs.aws.amazon.com/AmazonS3/latest/dev/website-hosting-custom-domain-walkthrough.html
aws route53 change-resource-record-sets --hosted-zone-id $HOST_ZONE_ID --change-batch "{
\"Changes\": [{
\"Action\": \"$ACTION\",
\"ResourceRecordSet\": {
@tpai
tpai / og.md
Last active September 6, 2017 09:17
og protocol

Scenario

Sometimes, facebook url debugger can not crawl exact meta data from the code like below and LINE neither.

<head>
  <meta httpEquiv="Content-Type" content="text/html; charset=utf-8" />
  <title>Page Title</title>
  <!-- massive inline CSS style -->
  <style>...</style>
@tpai
tpai / solution.md
Last active February 24, 2023 06:03
facebook plugin init error: init not called with valid version

Solution

js.src = "//connect.facebook.net/zh_TW/all.js";

instead of

js.src = "//connect.facebook.net/zh_TW/sdk.js";

Causing

@tpai
tpai / formula.js
Last active September 14, 2017 03:56
Common formula
function factorial(m) {
return m <= 1 ? m : m * factorial(m - 1);
}
function fibonacci(n) {
return n < 2 ? n : fibonacci(n - 1) + fibonacci(n - 2);
}
function prime(p) {
return p >= 1 ? isPrime(p) ? prime(--p).concat([p + 1]) : prime(--p) : [];