Skip to content

Instantly share code, notes, and snippets.

View iporsut's full-sized avatar
🏠
Working from home

Weerasak Chongnguluam iporsut

🏠
Working from home
View GitHub Profile
@iporsut
iporsut / jstimer.html
Created September 10, 2014 03:31
JS Time Counter
<!doctype html>
<html>
<head>
<meta charset="utf-8"/>
</head>
<body>
<p>Minute : <span id="minute">0</span></p>
<p>Second : <span id="second">0</span></p>
<script type="text/javascript">
var second = 0;
interface Authorizer {
public Boolean authorize(String username, String password);
}
type Authorizer interface {
Authorize(username, password string) (bool, error)
}
@iporsut
iporsut / gist:9ca2b89eb83f7c555441
Created October 21, 2014 15:07
DummyAuthorizer Java
public class DummyAuthorizer implements Authorizer {
public Boolean authorize(String username, String password) {
return null;
}
}
@iporsut
iporsut / gist:a9d5c98c3240a89507f6
Created October 21, 2014 15:08
DummyAuthorizer Go
type DummyAuthorizer struct {
}
func (dummy *DummyAuthorizer) Authorize(username, password string) (bool, error) {
return false, errors.New("Don't used Dummy")
}
@iporsut
iporsut / gist:b3e95478733c1f28fabd
Created October 21, 2014 15:10
System Test Java
public class System {
public System(Authorizer authorizer) {
this.authorizer = authorizer;
}
public int loginCount() {
//returns number of logged in users.
}
}
@iporsut
iporsut / gist:41bfe0a2c43e0a2ae884
Created October 21, 2014 15:11
System Test Go
type System struct {
Authorizer authorizer.Authorizer
}
func (system *System) LoginCount() int {
return 0
}
func TestNewlyCreatedSystemHasNoLoggedInUsers(t *testing.T) {
system := &System { &authorizer.DummyAuthorizer{} }
@iporsut
iporsut / gist:d2fd845322e811d753ff
Created October 21, 2014 15:11
AcceptingAuthorizerStub Java
public class AcceptingAuthorizerStub implements Authorizer {
public Boolean authorize(String username, String password) {
return true;
}
}
@iporsut
iporsut / gist:2e495d4be456cdc66af1
Created October 21, 2014 15:12
AcceptingAuthorizerStub Go
type AcceptingAuthorizerStub struct {
}
func (stub *AcceptingAuthorizerStub) Authorize(username, password string) (bool, error) {
return true, nil
}
@iporsut
iporsut / gist:1929201c6e70e9e7b917
Created October 21, 2014 15:13
AcceptingAuthorizerSpy Java
public class AcceptingAuthorizerSpy implements Authorizer {
public boolean authorizeWasCalled = false;
public Boolean authorize(String username, String password) {
authorizeWasCalled = true;
return true;
}
}