Skip to content

Instantly share code, notes, and snippets.

@Winwardo
Winwardo / machine.js
Last active December 29, 2020 11:31
Generated by XState Viz: https://xstate.js.org/viz
function fail(makeErrorData = (c, e) => ({ ...e })) {
return {
target: "#payment.failed",
actions: assign({
error_code: (c, e) => e.type,
error_data: makeErrorData,
}),
};
}
@Winwardo
Winwardo / machine.js
Last active March 7, 2020 16:32
Generated by XState Viz: https://xstate.js.org/viz
const orderPage = Machine({
id: "order",
initial: "base",
context: {
refund: null,
},
states: {
base: {
on:{
REFUND: 'refund',
@Winwardo
Winwardo / machine.js
Last active March 4, 2020 21:32
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
struct MyStruct {
value: u8
}
impl MyStruct {
pub fn Create() -> MyStruct {
MyStruct {
value: 7u8
}
}
class MyClass {
public:
MyClass() {
value = 7;
}
int value;
};
const exampleFunction1 = (n) => {
if (!predicate1) {
return 7
}
if (predicate2) {
sideEffect1(n)
return transformer2(transformer1(arg1, arg2, n), arg1)
} else {
return transformer2(transformer5(n), arg2)
const exampleFunction1 = (n) => {
if (predicate1) {
if (predicate2) {
sideEffect1(n)
const value1 = transformer1(arg1, arg2, n)
return transformer2(value1, arg1)
} else {
let value2 = 0
while (somePredicate()) {
@Winwardo
Winwardo / angles.csv
Last active April 4, 2018 12:47
Angles and colours produced by incrementing by 137 degrees
Count Generated angle Angle modulo 360 (hue) Output colour
0 0 0 red
1 137 137 green
2 274 274 purple
3 411 51 yellow
4 548 188 cyan
var StudentClass = function(){
this.name = "Some default name";
this.age = undefined;
this.address = {};
};
var StudentClassBuilder = new BuilderDecorator(StudentClass);
var student = new StudentClassBuilder()
.name("John")
.age(17)
// Telescoping constructor
var employee = Immutable(new Employee("John", "01234 56432", "07922344500", "53 Oakland Road", "Devon", "UK"));
// With builder
var employee = new EmployeeBuilder()
.name("John")
.phone("01234 56432")
.mobile("07922344500")
.addresslineone("53 Oakland Road")
.county("Devon")