Skip to content

Instantly share code, notes, and snippets.

View whiteinge's full-sized avatar

Seth House whiteinge

View GitHub Profile
@whiteinge
whiteinge / myapp.sls
Last active August 12, 2017 00:22
Prereq example for optionally draining Apache before updating a web app
include:
- git
apache:
pkg.installed:
- name: httpd
service.running:
- name: httpd
- enable: True
@whiteinge
whiteinge / flux-with-vanilla-rx.js
Last active July 27, 2023 10:36
An example of canonical Flux using vanilla RxJS
var Actions = new Rx.Subject();
Actions.onCompleted = () => {}; // never complete
var act = (tag, data = {}) => ({tag, data});
var send = tag => data => Actions.onNext(act(tag, data));
var Dispatcher = Actions.asObservable();
// ----------------------------------------------------------------------------
var C = constants = {
GET_USER: 'get_user',
@whiteinge
whiteinge / rxjs-flux-utils.js
Last active March 22, 2016 03:33
Misc collection of shorthand helper functions for Flux implemented with Rx
/**
Misc collection of shorthand helper functions for Flux implemented with Rx
**/
import Rx from 'rx';
import _ from 'lodash';
import formSerialize from 'form-serialize';
Rx.Observable.prototype.byTag = byTag;
@whiteinge
whiteinge / rxjs-spinner-poc.js
Created March 2, 2016 05:56
Render a spinner while waiting for an ajax response using RxJS
// Central xhr progress tracker. Used for both a global
// activity indicator as well as granular spinners within in a page.
var Progress$ = new Rx.Subject();
// Make an xhr call and make a tag to track the progress ticks.
var users$ = Rx.DOM.ajax({
method: 'GET',
url: 'https://api.github.com/users',
responseType: 'json',
progressObserver: Rx.Observer.create(
@whiteinge
whiteinge / index.js
Last active September 19, 2017 03:50
POC Node HTTP server for server-sent-events using RxJS
/**
Proof-of-concept server-sent events HTTP server using Node.js and RxJS
Open http://localhost:8000 in a browser and view the console.
**/
var http = require('http'),
https = require('https');
var Rx = require('rx');
@whiteinge
whiteinge / requirements.txt
Last active October 18, 2016 02:22
Tornado worker threads plus SSE streams plus reading/writing to sqlite; this is a benchmarking POC and not useful in production!
# Only required on Python 2
futures==3.0.3
tornado==4.3
@whiteinge
whiteinge / fromCallbackAll.js
Last active October 17, 2015 20:09
Alternative to Observable.fromCallback that does not complete itself
/**
Alternative to Observable.fromCallback that does not complete itself
In the example below `fnThatTakesCallback` is a function that takes a callback
as the final parameter. The function will be invoked with `arg1` and `arg2` and
when the callback is called the values will show up in the observable stream.
If `fnThatTakesCallback` requires a particular context use the call method
e.g., `fromCallbackAll.call(context, fnThatTakesCallback, [...], ...)`.
@whiteinge
whiteinge / h.js
Last active February 26, 2019 16:46
A convenience wrapper around React.createElement() to allow succinctly using React without using JSX
/* eslint no-param-reassign:0 */
import React from 'react';
import _ from 'lodash';
module.exports = h;
var classIdSplit = /([\.#]?[a-zA-Z0-9_:-]+)/;
var notClassId = /^\.|#/;
@whiteinge
whiteinge / process_status_updates.sls
Last active October 3, 2021 21:49
POC for writing status updates to a sqlite db. Updates are written using an Orchestrate file. The Orchestrate file can be called via the Reactor.
{# Place this file in /srv/reactor/process_status_updates.sls
Call via sending a custom event on a minion as:
salt-call event.send myco/external_task/status_update task=foo status='Update number one!'
Requires reactor config such as:
reactor:
- 'myco/external_task/status_update':
- /srv/reactor/process_status_updates.sls
@whiteinge
whiteinge / streamreader.py
Created February 5, 2015 01:06
An example of using the asyncio library to watch multiple salt-api SSE HTTP streams
#!/usr/bin/env python3
'''
./streamreader.py 'http://localhost:8000/events?salt_token=078c5f808b077f1e9f8dbc7408420cef' 'http://localhost:8000/events?salt_token=103ba8c5c54c46817a7153038638a9f1' 'http://localhost:8000/events?salt_token=4b12844a06b25411daf5aa0dfdcc7628'
'''
import asyncio
import json
import sys
import urllib.parse