Skip to content

Instantly share code, notes, and snippets.

View jdrew1303's full-sized avatar
probably drinking coffee

James Drew jdrew1303

probably drinking coffee
View GitHub Profile
@jdrew1303
jdrew1303 / scxml-builder.js
Created April 13, 2018 01:23 — forked from pmuellr/scxml-builder.js
scxml as a JavaScript builder
//------------------------------------------------------------------------------
// examples from:
// State Chart XML (SCXML): State Machine Notation for Control Abstraction
// http://www.w3.org/TR/scxml/
// http://www.w3.org/TR/2014/WD-scxml-20140529/ (latest version)
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// <state id=s">
// <transition event="e" cond="x==1" target="s1"/>
@jdrew1303
jdrew1303 / GameState.elm
Created April 13, 2018 01:22 — forked from rupertlssmith/GameState.elm
Exploring State Machines with phantom types in Elm
module GameState
exposing
( Game(..)
, GameDefinition
, PlayState
, loading
, updateGameDefinition
, updatePlayState
, updateScore
, toReady
@jdrew1303
jdrew1303 / 1_Laravel_state-machine.md
Created April 13, 2018 01:20 — forked from iben12/1_Laravel_state-machine.md
Laravel: State-machine on Eloquent Model

Implementing State Machine On Eloquent Model*

* Update (12.09.2017): I have improved the trait so that it can be used with objects other than Eloquent Models.

Some days ago I came across a task where I needed to implement managable state for an Eloquent model. This is a common task, actually there is a mathematical model called "Finite-state Machine". The concept is that the state machine (SM) "can be in exactly one of the finite number of states at any given time". Also changing from one state to another (called transition) depends on fulfilling the conditions defined by its configuration.

Practically this means you define each state that the SM can be in and the possible transitions. To define a transition you set the states on which the transition can be applied (initial conditions) and the only state in which the SM should be after the transition.

That's the theory, let's get to the work.

@jdrew1303
jdrew1303 / 01.FiniteAuditTrail.README.md
Created April 13, 2018 01:19 — forked from tortuetorche/01.FiniteAuditTrail.README.md
FiniteAuditTrail Trait For Laravel 4 with Example. Support for keeping an audit trail for any state machine, borrowed from the Ruby StateMachine audit trail gem.

FiniteAuditTrail Trait

Support for keeping an audit trail for any state machine, borrowed from the Ruby StateMachine audit trail gem. Having an audit trail gives you a complete history of the state changes in your model. This history allows you to investigate incidents or perform analytics, like: “How long does it take on average to go from state a to state b?”, or “What percentage of cases goes from state a to b via state c?”

Requirements

  1. PHP >= 5.4
  2. Laravel 4 framework
@jdrew1303
jdrew1303 / gist:8f2ba3d23ed7583b40672d28e24e26cd
Created April 13, 2018 01:18 — forked from smurphy8/gist:b0c8040284d3b874e6c5
Using IxMonad to create an IO StateMachine
@jdrew1303
jdrew1303 / tmux-cheatsheet.markdown
Created April 13, 2018 01:02 — forked from MohamedAlaa/tmux-cheatsheet.markdown
tmux shortcuts & cheatsheet

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
@jdrew1303
jdrew1303 / hcr.js
Created April 12, 2018 12:32 — forked from thure/hcr.js
Heliocentric coordinates from Kepler orbit and time
var moment = require('moment');
module.exports = function(/* orbit, [Date, time String], [format String], [etc] */){
// Takes an orbit definition of the kind used in GEOF stellar-objects and
// remaining arguments as moment arguments, returning heliocentric
// rectangular coordinates in α's unit (probably AU).
// TODO: Does not yet take into account changes in orbit over time.
// TODO: Converts between degrees and radians too often, I think.
// fizzbuzz normally has two possible solutions:
// - the default action is only executed if some previous actions were not executed
// - duplicate checks
// the below solution avoids both of these issues [see Maciej Pirog: FizzBuzz in Haskell by Embedding a Domain-Specific Language](https://themonadreader.files.wordpress.com/2014/04/fizzbuzz.pdf)
const fizzbuzz = (x) => {
const check = (number, string) => (f) => (x % number) == 0 ? () => `${string}${f('')}` : f;
//const fizz = (f) => (x % 3) == 0 ? () => `fizz${f('')}` : f;
//const buzz = (f) => (x % 5) == 0 ? () => `buzz${f('')}` : f;
const fizz = check(3, 'fizz');
const buzz = check(5, 'buzz')
@jdrew1303
jdrew1303 / Expecations in PEG.js error
Created November 26, 2017 04:07 — forked from mstefaniuk/Expecations in PEG.js error
Prividing expectations in PEG.js generated parser (last lines)
/*
* The parser is now in one of the following three states:
*
* 1. The parser successfully parsed the whole input.
*
* - |result !== null|
* - |pos === input.length|
* - |rightmostMatchFailuresExpected| may or may not contain something
*
* 2. The parser successfully parsed only a part of the input.
@jdrew1303
jdrew1303 / grammar.pegjs
Created November 26, 2017 04:00 — forked from nerevar/grammar.pegjs
PEG.js filters grammar
/*
* PEG.js грамматика парсера фильтра результатов сравнения метрик
* Как обновлять грамматику:
* 1. Скопипастить исходник в http://pegjs.org/online
* 2. Указать Parser variable: window.filter_parser
* 3. Download parser
* 4. Минифицировать скачанный js код через: http://jscompress.com
* 5. Обновить файл filter_parser.pegjs.min.js
* 6. Запустить js unit-тесты: mocha filter_parser.pegjs.test.js
* 7. Обновить исходник в этом файле filter_parser.pegjs