Skip to content

Instantly share code, notes, and snippets.

@sfarthin
sfarthin / machine.js
Last active October 15, 2021 13:29
Generated by XState Viz: https://xstate.js.org/viz
const payAdvanceService = {
orchInitiatePayout: async () => null,
orchInitiateRepayment: async () => (send) => {
// send({ type: 'initiatedFullAchRepayment' });
},
};
const machine = Machine({
type: 'parallel',
@sfarthin
sfarthin / machine.js
Created October 14, 2021 20:37
Generated by XState Viz: https://xstate.js.org/viz
const fetchCuteAnimals = () => {
return fetch('https://www.reddit.com/r/aww.json')
.then(res => res.json())
.then(data => data.data.children.map(child => child.data))
}
const cuteAnimalMachine = Machine({
id: 'cuteAnimals',
initial: 'idle',
context: {
@sfarthin
sfarthin / machine.js
Last active October 7, 2021 19:51
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@sfarthin
sfarthin / machine.js
Created February 23, 2021 18:10
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
// Borrowed from https://github.com/adriancooney/console.snapshot/blob/master/console.snapshot.js
/* eslint-disable no-console, no-param-reassign */
/**
* Since the console.log doesn't respond to the `display` style,
* setting a width and height has no effect. In fact, the only styles
* I've found it responds to is font-size, background-image and color.
* To combat the image repeating, we have to get a create a font bounding
* box so to speak with the unicode box characters.
@sfarthin
sfarthin / childFrame.html
Last active August 29, 2015 13:56
Child/Parent frame communication
<button onclick="parent.postMessage('close', '*');">Hide</button>
// See http://stackoverflow.com/questions/21934831/nodejs-express-stream-stdout-instantly-to-the-client
var cp = require("child_process"),
express = require("express"),
app = express();
app.get('/', function(req, res){
res.writeHead(200, { "Content-Type": "text/event-stream" });
# Learning Angular.js Dependency Injection with examples
The hardest part for me to grasp with Angular.js was Dependency Injection and distinctions between services/factories/providers. I have provided some simple examples that made these concepts more clear.
## Modules
Create a new module like this (second argument is for dependencies).
angular.module('myModule', []);
@sfarthin
sfarthin / syncData.js
Last active August 29, 2015 13:56
AMD Angular Service for Firebase.com service
/**
* Lets make a service rather than refering to firebase directly
*
* Copied and tweeked from angularFire-seed.
* https://github.com/firebase/angularFire-seed/blob/master/app/js/service.firebase.js
*
* For use with bower.
* bower install https://gist.github.com/8834003.git --save
**/
define(["angularfire"], function() {