Skip to content

Instantly share code, notes, and snippets.

View Sean-Bradley's full-sized avatar
📰
https://sbcode.net

SBCODE Sean-Bradley

📰
https://sbcode.net
View GitHub Profile
@Sean-Bradley
Sean-Bradley / gist:b7b223c33fd0b57b14178c19cc5d257a
Created September 25, 2021 11:34
The client.js from the Three.js Boilerplate
import * as THREE from 'three'
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls'
import Stats from 'three/examples/jsm/libs/stats.module'
import { GUI } from 'three/examples/jsm/libs/dat.gui.module'
const scene = new THREE.Scene()
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 100)
camera.position.z = 2
@Sean-Bradley
Sean-Bradley / gist:1ad4184edca352e643d7a269f878a571
Created September 25, 2021 11:26
HTML for a basic Three.js boilerplate that uses import maps.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Three.js Tutorials by Sean Bradley : https://sbcode.net/threejs/</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body {
overflow: hidden;
"""Chain of Responsibility Pattern
Chain of responsibility pattern is a behavioural pattern used to achieve loose coupling
in software design.
In this example, a request from a client is passed to a chain of objects to process them.
The objects in the chain will decide how to process them and/or pas them to the next in the chain.
The objects can also modify the next in the chain if for example you wanted to run objects in a recursive manner.
"""
from abc import ABCMeta, abstractstaticmethod
"""The Command Design Pattern in Python
The command pattern is a behavioural design pattern, in which an abstraction
exists between an object that invokes a command, and the object that performs it.
This is part 2 of the Command Design Pattern tutorial,
where I create a slider, instead of the switch from part 1.
The slider also accepts a variable percentage, rather than an ON/OFF
The history also records the variable settingg
And I also add UNDO/REDO to the Invoker so that you can go backawards and forwards through time
"""
Prototype design pattern
"""
from abc import ABCMeta, abstractstaticmethod
import copy
class IProtoType(metaclass=ABCMeta):
"""interface with clone method"""
from abc import ABCMeta, abstractmethod
import datetime
class IComponent(metaclass=ABCMeta):
@staticmethod
@abstractmethod
def method(self):
"""A method to implement"""
from abc import ABCMeta, abstractmethod
class IGraphic(metaclass=ABCMeta):
@staticmethod
@abstractmethod
def print():
"""print information"""
class Ellipse(IGraphic):
def print(self):
class SubSystemClassA:
@staticmethod
def method():
return "A"
class SubSystemClassB:
@staticmethod
def method():
return "B"
class UndecoratedObject:
@staticmethod
def get():
return "UndecoratedObject"
class Decorate:
def __init__(self, undecorated):
self.undecorated = undecorated
from abc import ABCMeta, abstractmethod
class IA(metaclass=ABCMeta):
@staticmethod
@abstractmethod
def method_a():
"""An abstract method A"""