View new.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# https://superuser.com/a/1251013/57284 | |
# https://gist.github.com/theScottyJam/ae19299c8d71a21c75f2abd96daea9f8 | |
from pathlib import Path | |
import tkinter as tk | |
from tkinter import ttk | |
import os | |
import shutil |
View exceptions.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict' | |
// This module provides a light version of the explicit-exceptions API. | |
// You can find the original package this module was modeled after | |
// at this URL: https://www.npmjs.com/package/explicit-exceptions | |
/** | |
* An exception that can be thrown (or rethrown) within a function decorated with wrap(). | |
*/ | |
class Exception extends Error { |
View publicHelpers.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Public helpers | |
export const monsterBehaviors = { | |
kill(monster) { | |
userInventory.add(monster.dropLoot()) | |
removeFromUi(this) | |
} | |
} | |
// private helpers | |
const monsterHelpers = { |
View runtimeHierarchyCheck.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const monsterSentinel = {} | |
export const isMonster = obj => obj.typeSentinel === monsterSentinel | |
export class Slime { | |
typeSentinel = monsterSentinel | |
... | |
} | |
export class Skeleton { |
View originalInheritanceExample.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class Monster { | |
constructor() { | |
if (this.constructor === Monster) { | |
throw new Error('This is an abstract class. Do not instantiate it directly.'); | |
} | |
} | |
attack() { | |
playHurtAnimation() | |
} |
View classicComposition.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MonsterBehaviors { | |
#dropLoot | |
constructor({ dropLoot }) { | |
this.#dropLoot = dropLoot | |
} | |
attack() { | |
playHurtAnimation() | |
} |
View restrictedInheritance.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const monsterHelpers = { | |
attack() { | |
playHurtAnimation() | |
} | |
} | |
class MonsterBehaviors { | |
#id = Math.random() | |
#dropLoot |
View strategyPattern.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Monster { | |
#onAttack | |
constructor({ dropLoot, onAttack, customBehaviors = {} }) { | |
this.dropLoot = dropLoot | |
this.#onAttack = onAttack ?? (() => {}) | |
this.behaviors = customBehaviors | |
} | |
attack() { | |
playHurtAnimation() |
View helperFunctions.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const monsterBehaviors = { | |
attack() { | |
playHurtAnimation() | |
}, | |
die({ monsterId, dropLoot }) { | |
userInventory.add(dropLoot()) | |
removeFromUi(monsterId) | |
}, | |
} |
View exampleData.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import type { User } from './userManager'; | |
export const users: Map<string, User> = new Map(Object.entries({ | |
'1': { | |
id: '1', | |
username: 'admin', | |
permissions: ['VIEW', 'UPDATE'], | |
}, | |
'2': { | |
id: '2', |
OlderNewer