Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View Pyrolistical's full-sized avatar

Pyrolistical

View GitHub Profile
@Pyrolistical
Pyrolistical / pyluxcore.pyi
Created April 19, 2023 22:46
mypy stubgen output of pyluxcore.pyd 2.6
from typing import Any, ClassVar
import Boost.Python
class Camera(Boost.Python.instance):
@classmethod
def __init__(cls, *args, **kwargs) -> None: ...
@classmethod
def Rotate(cls, *args, **kwargs) -> Any: ...
@classmethod
@Pyrolistical
Pyrolistical / useMemo instead.js
Created October 2, 2021 06:12
https://blog.battlefy.com/how-to-escape-react-hooks-hell-a66c0d142c9e Unnecessary useEffect and useState for computed value based on prop
// BEFORE
const [costlyValue, setCostlyValue] = setState();
useEffect(() => {
setCostlyValue(computedCostlyValue(props.someParam));
}, [props.someParam]);
// AFTER
const costlyValue = useMemo(() => computedCostlyValue(props.someParam), [props.someParam]);
@Pyrolistical
Pyrolistical / repository.js
Created October 22, 2021 23:47
ecommerce-escalation v2 repo
export default (mongoClient, db) => {
return {
async checkoutTransaction(closure) {
const session = mongoClient.startSession({
causalConsistency: true
});
try {
const sessionRepository = {
async findInventoryByProuctSkus(productSkus) {
return db.collection('inventory').find({
@Pyrolistical
Pyrolistical / service.spec.js
Created October 22, 2021 23:46
ecommerce-escalation v2 test
import {jest} from '@jest/globals';
import Service, {InsufficientStock} from './service';
describe('checkout', () => {
test('fails when insufficient stock for desired product', async () => {
const session = {
findInventoryByProuctSkus: jest.fn()
.mockResolvedValueOnce([
{
@Pyrolistical
Pyrolistical / service.spec.js
Created October 22, 2021 23:03
ecommerce-escalation v1 test
import {jest} from '@jest/globals';
import Service, {InsufficientStock} from './service';
describe('checkout', () => {
test('fails when insufficient stock for desired product', async () => {
const repository = {
findInventoryByProductSku: jest.fn()
.mockResolvedValueOnce({
productSku: 'some product sku',
@Pyrolistical
Pyrolistical / service.js
Created October 22, 2021 07:43
ecommerce-escalation v2
import _ from 'lodash';
export class InsufficientStock extends Error {
constructor(message) {
super(message);
this.name = 'InsufficientStock';
}
}
export default (repository) => {
@Pyrolistical
Pyrolistical / service.js
Created October 22, 2021 07:42
ecommerce-escalation v1
import _ from 'lodash';
export class InsufficientStock extends Error {
constructor(message) {
super(message);
this.name = 'InsufficientStock';
}
}
export default (repository) => {
@Pyrolistical
Pyrolistical / repository.js
Created October 10, 2021 05:59
separate business layer from infrastructure layer after alternative checkInTeam
async checkInTeam(teamID) {
return db.collection('teams').updateOne({
_id: teamID
}, {
$set: {
checkedInAt: new Date()
}
});
}
@Pyrolistical
Pyrolistical / service.spec.js
Last active October 9, 2021 22:25
separate business layer from infrastructure layer after test
import {jest} from '@jest/globals'
import Service from './service';
test('teams with disqualified players cannot check-in', async () => {
const repository = {
findDisqualifiedPlayers: jest.fn()
.mockResolvedValueOnce([
{
teamID: 'some team id',
@Pyrolistical
Pyrolistical / repository.js
Last active October 9, 2021 22:17
separate business layer from infrastructure layer after
export default (db) => {
return {
async findDisqualifiedPlayers(teamID) {
return db.collection('playerDisqualifications').find({
teamID
})
.toArray();
},
async checkInTeam(teamID) {
return db.collection('checkIns').insert({