Skip to content

Instantly share code, notes, and snippets.

View MilesChou's full-sized avatar
😂
Learning

MilesChou MilesChou

😂
Learning
View GitHub Profile
<?php
// See https://github.com/web-token/jwt-framework/tree/v1.3.9 for about JWT
function createAppleIDSecret()
{
$privateKey = file_get_contents('/path/to/your/key');
$keyId = 'key_id';
$teamId = 'team_id';
$clientId = 'client_id';
@MilesChou
MilesChou / .dockerignore
Last active March 20, 2019 03:36
The basic Dockerfile for Laravel Framework
# Docker files
.dockerignore
Dockerfile
# Git files
.git
# Node files
node_modules
<?php
$totalScore = 0;
foreach ($exam as $value) {
foreach ($value->mocks as $mock) {
foreach ($mock->items as $item) {
$totalScore += (int)$item->ext->score;
}
}
@MilesChou
MilesChou / adapter.php
Last active January 29, 2021 14:31
Adapter function example for mysql to mysqli
<?php
if (!function_exists('mysql_connect')) {
function mysql_connect($host, $username, $password) {
mysqli_connect($host, $username, $password);
}
}
mysql_connect('127.0.0.1', 'root', 'password');
@MilesChou
MilesChou / greeting.php
Last active December 2, 2016 05:19
greeting
<?php
class Client
{
public $greetingRules = [];
public function __construct()
{
$this->greetingRules[] = new MorningGreeting();
$this->greetingRules[] = new AfternoonGreeting();

Code review

程式碼審查

類型

  • Pair Programming (直接的做法 - 時間短 - feedback 慢 - 高密度)
  • 可使用在新人加入時
@MilesChou
MilesChou / Makefile
Last active May 25, 2019 10:34
Dockerfile 懶人用
#!/usr/bin/make -f
IMAGE := $(shell basename $(shell pwd))
VERSION := latest
.PHONY: all build rebuild shell run
# ------------------------------------------------------------------------------
all: build
@MilesChou
MilesChou / TestFragment.java
Created April 2, 2014 07:46
摩天輪動畫
// ignore import
public class TestFragment extends Fragment
{
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
return inflater.inflate(R.layout.fragment, container, false);
}
<?php
/**
* class 教學
*
* class 全域需注意的重點:
* 1.全域:跟function一樣,一經宣告後,任何地方皆可使用。
* 2.不可重載:跟function一樣,一經宣告後,不可再宣告同名的class
*
* 建立class的重點:
<?php
/**
* php function的重點:
* 1.全域:一經宣告後,程式的任何位置都能直接使用,包括class中。
* 2.不可重載:一經宣告後,不能宣告第二次。
* 3.傳值:使用傳值後,外部和內部的參數會毫不相千。
* 4.傳址:使用傳址後,內部對參數的修改,外部的變數也會跟著變動。
* 5.預設值:沒傳參數時,會使用預設值當參數,通常放在參數的最後面(右邊)
* 6.回傳值:只能回傳一個值,但可以是任何一種資料型態。
* 7.可變函數:當變數後有"()"時,php會試著找該變數是否有定義為函數。