Skip to content

Instantly share code, notes, and snippets.

View wolivera's full-sized avatar

Will wolivera

View GitHub Profile
@wolivera
wolivera / profile.move
Last active June 13, 2024 14:27
A SUI Blockchain demo implementation for a profile in Move
module zircon::profile {
// === Imports ===
use std::string::String;
use zircon::profile_cap::{Self, ProfileCap};
// === Structs ===
/// The user's Profile.
@wolivera
wolivera / Visitor.js
Created July 12, 2022 17:47
GoF Visitor
class Player {
constructor (name, points, gems) {
this.name = name;
this.points = points;
this.gems = gems;
}
accept (visitor) {
visitor.visit(this);
}
getName () {
@wolivera
wolivera / Template.js
Last active July 12, 2022 14:15
GoF Template
const datastore = {
process: function () {
this.connect();
this.select();
this.disconnect();
return true;
}
};
function inherit(proto) {
@wolivera
wolivera / Memento.js
Created July 12, 2022 13:55
GoF Memento
class Person {
constructor (name, street, city, state) {
this.name = name;
this.street = street;
this.city = city;
this.state = state;
}
hydrate () {
const memento = JSON.stringify(this);
return memento;
@wolivera
wolivera / Mediator.js
Created July 12, 2022 13:12
GoF Mediator
class Bidder {
constructor (name) {
this.name = name;
this.auction = null;
}
bid (amount, to) {
this.auction.send(amount, this, to);
}
offer (amount, from) {
console.log(from.name + " offered " + amount);
@wolivera
wolivera / Interpreter.js
Created July 8, 2022 20:33
GoF Interpreter
class Context {
constructor (input) {
this.input = input;
this.output = 0;
}
startsWith (str) {
return this.input.substr(0, str.length) === str;
}
}
@wolivera
wolivera / Command.js
Created July 8, 2022 14:30
GoF Command
function copy(x) { return x; }
function cut(x) { return x; }
function paste(x) { return x; }
class Command {
constructor (execute, value) {
this.execute = execute;
this.value = value;
}
@wolivera
wolivera / ChainOfResp.js
Last active July 7, 2022 00:23
GoF Chain of Resp
class ATM {
constructor(amount) {
this.amount = amount;
console.log("Requested: $" + amount + "\n");
}
get (bill) {
const count = Math.floor(this.amount / bill);
this.amount -= count * bill;
console.log("Dispense " + count + " $" + bill + " bills");
@wolivera
wolivera / Strategy.js
Created July 6, 2022 21:00
GoF Strategy
class Shipping {
constructor() {
this.method = "";
}
setStrategy (method) {
this.method = method;
}
calculate (box) {
return this.method.calculate(box);
}
@wolivera
wolivera / State.js
Created July 6, 2022 20:49
GoF State
class TrafficLight {
constructor() {
this.count = 0;
this.currentState = new Red(this);
}
change (state) {
// limits number of changes
if (this.count++ >= 10) return;
this.currentState = state;
this.currentState.go();