Skip to content

Instantly share code, notes, and snippets.

View t301000's full-sized avatar

林士立 t301000

  • 育林國中
  • New Taipei City
View GitHub Profile
@t301000
t301000 / infinite_sum_api.js
Last active July 16, 2017 15:03
請完成以下 API 設計,讓你的程式可以執行以下程式碼,並且得到預期的結果。
/*
請完成以下 API 設計,讓你的程式可以執行以下程式碼,並且得到預期的結果。串接 add 的次數沒有上限,最後一個 API 是 result() 才會回傳結果。
$(1).add(2).add(3).add(99).result() === 105
$(1).add(2).add(3).result() === 6
etc...
...etc...
*/
function $(start) {
var sum = start;
@t301000
t301000 / closure_getter_setter.js
Created July 16, 2017 14:10
請利用 JS 閉包 (Closure) 特性實作私有變數的 get 與 set 存取子
/*
請依據以下範本撰寫一個 MyFunc 函式:
function MyFunc() {
// YOUR CODE HERE
}
撰寫完成後,必須可以正常執行以下程式碼:
var o = MyFunc();
o.get_a() // 回傳 undefined
(function(){
var a;
a = b = 3;
})();
/*
a => 為 function 的區域變數,IIFE 執行完回收,ReferenceError: a is not define
b => 未用 var 宣告,所以會在 window 添加 b 屬性,其值為 3,IIFE 執行完依然存在
*/
@t301000
t301000 / app.component.css
Last active June 4, 2017 03:00
20170531 作業實做參考
.main {
width: 100%;
height: 200px;
border: 1px solid gray;
margin-bottom: 20px;
}
@t301000
t301000 / color-plate.component.html
Created June 3, 2017 08:42
20170531 作業實做參考
<div class="color"
[ngStyle]="{'background-color': myStyle}"
(click)="picked.emit(myStyle)"></div>
<div *ngIf="show; else edit" class="tweak">
<input type="range" min="0" max="255" [(ngModel)]="r">
<span style="color: red">{{ r }}</span><br />
<input type="range" min="0" max="255" [(ngModel)]="g">
<span style="color: green">{{ g }}</span><br />
<input type="range" min="0" max="255" [(ngModel)]="b">
@t301000
t301000 / app.component.html
Last active May 31, 2017 09:45
簡易計數器範例
<app-counter-button [step]="-2" (changed)="change($event)"></app-counter-button>
{{ counter }}
<app-counter-button [step]="5" (changed)="change($event)"></app-counter-button>
@t301000
t301000 / 0_reuse_code.js
Created November 26, 2015 15:56
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@t301000
t301000 / PjaxMiddleware.php
Created October 12, 2015 03:49 — forked from JeffreyWay/PjaxMiddleware.php
Laravel middleware for working with pjax.
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Symfony\Component\DomCrawler\Crawler;
class PjaxMiddleware
@t301000
t301000 / Category.php
Last active August 29, 2015 14:25
無窮分類列表 ver 2
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Category extends Model
{
// 定義 self relation,用來處理子分類
@t301000
t301000 / CategoriesTableSeeder.php
Last active August 29, 2015 14:25
無窮分類列表範例
<?php
use Illuminate\Database\Seeder;
class CategoriesTableSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void