Skip to content

Instantly share code, notes, and snippets.

View phedkvist's full-sized avatar

Pierre Hedkvist phedkvist

View GitHub Profile
@phedkvist
phedkvist / crdt_woot.ts
Created February 27, 2021 13:09
crdt-woot
export interface Site {
siteId: string; // unique id for each site
clock: number;
sequence: Char[];
operationPool: Char[];
}
export interface Char {
id: string;
charId: CharId;
payload set A
initial ∅
update add(element e)
A := A ∪ {e}
query lookup(element e) : boolean b
let b = (e ∈ A)
compare (S, T) : boolean b
let b = (S.A ⊆ T.A)
merge (S, T) : payload U
let U.A = S.A ∪ T.A
@phedkvist
phedkvist / g-counter
Last active February 27, 2021 12:47
G-counter
payload integer[n] P
initial [0,0,...,0]
update increment()
let g = myId()
P[g] := P[g] + 1
query value() : integer v
let v = Σi P[i]
compare (X, Y) : boolean b
let b = (∀i ∈ [0, n - 1] : X.P[i] ≤ Y.P[i])
merge (X, Y) : payload Z
// WARNING: DO NOT EDIT. This file is automatically generated by AWS Amplify.
// It will be overwritten.
const awsmobile = {
aws_project_region: 'eu-central-1',
aws_cognito_identity_pool_id: 'eu-central-1:XXXX-XXXX-XXXX-XXXX-XXXX',
aws_cognito_region: 'eu-central-1',
aws_user_pools_id: 'eu-central-1_XXXXXXX',
aws_user_pools_web_client_id: 'XXXXXXXXXXXXXXXXX',
oauth: {},
const PrivateRoute: React.ComponentType<any> = ({
component: Component,
...rest
}) => {
return (
<Route
{...rest}
render={props =>
fakeAuth.isAuthenticated ? (
<Component {...props} />
interface Props extends RouteComponentProps {}
interface State {
redirectToReferrer: boolean;
}
class Login extends React.Component<Props, State> {
constructor(props: Props) {
super(props);
this.state = {
redirectToReferrer: false
@phedkvist
phedkvist / renderless_component.js
Last active March 20, 2019 10:09
Renderless component in React
import React from 'react';
import PropTypes from 'prop-types';
export default class MouseMovement extends React.Component {
constructor(props) {
super(props);
this.state = {
timer: undefined,
};
this.timeout = this.timeout.bind(this);
@phedkvist
phedkvist / draw.html
Last active August 10, 2022 16:22
HTML5 Canvas Drawing Touch or Mouse
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>HTML5 Canvas Drawing</title>
</head>
<body>
@phedkvist
phedkvist / environmentvarinmac.txt
Last active December 21, 2016 16:23
How to create environment variable on mac
Step 1: Open ./bash_profile:
open ~/.bash_profile
Step 2: Add your variable and save file
export MYVARIABLE='valueHere'
Step 3: Restart your terminal and check if you env variable exists