Skip to content

Instantly share code, notes, and snippets.

View whiteinge's full-sized avatar

Nathaniel Whiteinge whiteinge

View GitHub Profile
@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
@whiteinge
whiteinge / eventlisten-events.py
Created September 12, 2014 23:15
This is roughly the same as how Salt's CLI works but without the periodic saltutil.find_job calls
#!/usr/bin/python
'''
Listen to Salt's event bus for job returns.
Usage::
./eventlisten.py 'G@os_family:RedHat' 'test.sleep' '30'
'''
from __future__ import print_function
@whiteinge
whiteinge / vcs_info-hook-optional-rev
Last active August 29, 2015 14:04
Example of a hook for vcs_info for optionally displaying the git revision
# Toggle this to test the hook
zstyle ':vcs_info:git:*' get-revision true
# basic 'formats' config: (git)[hash] branch
zstyle ':vcs_info:git*' formats "(%s)%i %b"
# Register new hook
zstyle ':vcs_info:git*+set-message:*' hooks git-optional-rev
# Define new hook
@whiteinge
whiteinge / eventlisten.sh
Last active August 30, 2017 18:37
A POSIX sh implementation of Salt's eventlisten.py script. Uses salt-api's event HTTP stream.
#!/bin/sh
URL="http://localhost:8000"
COOKIES="cookies.txt"
fnmatch () { case "$2" in $1) return 0 ;; *) return 1 ;; esac ; }
listen() {
# Watch Salt's events HTTP stream.
@whiteinge
whiteinge / keybase.md
Created April 10, 2014 23:23
keybase.md

Keybase proof

I hereby claim:

  • I am whiteinge on github.
  • I am whiteinge (https://keybase.io/whiteinge) on keybase.
  • I have a public key whose fingerprint is 22CA 731F 6E18 4DA6 A087 7EA5 981A 9910 15ED 347D

To claim this, I am signing this object:

@whiteinge
whiteinge / connected_ips.awk
Last active February 20, 2022 23:12
Output IP addresses for machines connected to the local machine using /proc/net/tcp for speed
#!/usr/bin/awk -f
# Output IP addresses for machines that are connected to the local machine.
#
# Usage:
# ./connected_ips.awk /proc/net/tcp
# ./connected_ips.awk -v port=4505 /proc/net/tcp
function fromhex(s){
# Amazing voodoo from William.
# http://compgroups.net/comp.lang.awk/reading-hexadecimal-numbers/33952
@whiteinge
whiteinge / sample_cherrypy.py
Last active October 30, 2021 00:22
A not-so-simple but minimal example of a CherryPy app.
#!/usr/bin/env python
# coding: utf-8
'''
A minimal but thorough example of a CherryPy app.
'''
import cherrypy
class Root(object):
@cherrypy.expose
def index(self):