Skip to content

Instantly share code, notes, and snippets.

View ecowden's full-sized avatar

Evan Cowden ecowden

View GitHub Profile
Tools environment: GOPATH=C:\Go;C:\tinygo
Installing 18 tools at C:\Go\bin;C:\tinygo\bin in module mode.
gocode
gopkgs
go-outline
go-symbols
guru
gorename
gotests
gomodifytags
// F5PoolSyncer is responsible for ensuring state on the F5 BigIP LTM. It is the glue
// that hides and abstracts the LTM from the rest of the code.
type F5PoolSyncer interface {
EnsurePoolPresent(k8sPool *bigipv1beta1.Pool) (*SyncResult, *bigip.Pool, error)
EnsurePoolAbsent(k8sPool *bigipv1beta1.Pool) (*SyncResult, error)
EnsureMembersPresent(k8sPool *bigipv1beta1.Pool, endpoints *corev1.Endpoints) (result *SyncResult, err error)
}
// realPoolSyncer is a concrete implementation of the PoolSyncer interface
// TODO this naming is awful; change it
import (
// We used an import alias when Logrus replaced
// the standard logging library a while back
log "github.com/sirupsen/logrus"
// Two scheme packages
"k8s.io/client-go/kubernetes/scheme"
myscheme "github.mycompany.com/product-engineering/my-project/pkg/client/clientset/versioned/scheme"
// So many v1 packages!
@ecowden
ecowden / cylon-sparkfun-edison-9dof.js
Last active January 24, 2016 20:17
Attempt at reading the Sparkfun Edison 9DOF board via Cylon.js
var util = require('util')
var async = require('async')
var Cylon = require('cylon')
Cylon.robot({
connections: {
edison: {
adaptor: 'intel-iot',
i2cPort: 1
}
@ecowden
ecowden / handle-promises.js
Created January 18, 2016 21:15
It's easy to imagine a function that can just iterate through a bunch of promises, resolve them, pass the values on to the next and handle errors.
let promises = [getDataAsync(), getDataAsync(), getDataAsync()]
resolveAndHandleChainOfPromises(promises)
@ecowden
ecowden / async-await.js
Created January 18, 2016 18:22
Simple ES2016 async / await demo
async function (t) {
// getDataAsync could be any function that returns a Promise
let aPromise = getDataAsync()
let a = await aPromise
// We usually don't assign the promise to a variable before we
// `await` it, so this process usually looks like,
@ecowden
ecowden / simple-co.js
Last active January 18, 2016 21:33
Super simple example using `co`
const assert = require('assert')
const co = require('co')
return co(function* () {
let a = yield getDataAsync()
let b = yield getDataAsync()
let c = yield getDataAsync()
let actual = yield averageAsync([a, b, c])
let expected = (a + b + c) / 3
const assert = require('assert')
function* createIncrementingSequence(increment) {
let nextValue = 0
for (let i = 0; i < maxIterations; i++) {
// ↙ 'yield' each value in the iteration.
yield nextValue
nextValue += increment
}
}
@ecowden
ecowden / array-iterable.js
Last active January 18, 2016 17:22
Use of a JavaScript Array as an `iterable` in a `for-of` loop
const assert = require('assert')
const numbers = [0, 2, 4, 6, 8]
let sum = 0
// We can loop through “iterables” with the new “for-of” loop:
for (let n of numbers) {
sum += n
}
@ecowden
ecowden / manual-iterable.js
Last active January 18, 2016 17:22
Create a JavaScript `iterable` object without the use of generator functions
// Gah!
// Don’t try to understand all of this.
class IncrementingSequence {
constructor(increment) {
this.increment = increment
}
// ↙ Iteration function specially named with a “Symbol” defined by the language
[Symbol.iterator]() {