Skip to content

Instantly share code, notes, and snippets.

View ecowden's full-sized avatar

Evan Cowden ecowden

View GitHub Profile
@ecowden
ecowden / angular-partial-cache-busting
Created January 25, 2013 21:01
Cache busting for AngularJS partials is easy
/*
* Decide on your cache-busting strategy. In this example, we use the current timestamp, which will
* force a change every time the app is visited, but not every time the partial is loaded within a
* visit. Even better would be to use a hash of the file's contents to ensure that the file is always
* reloaded when the file changes and never reloaded when it isn't.
*/
var cacheBustSuffix = Date.now();
// Optionally, expose the cache busting value as a constant so other parts of your app can use it.
ngModule.constant("cacheBustSuffix", cacheBustSuffix);
@ecowden
ecowden / jasmine-spy-mostRecentCall
Last active November 23, 2022 02:05
Use the Jasmine spy's mostRecentCall element to get the arguments of a test invocation
/*
* Let's say we have a collaborater with a 'show' function. The instance under test is going to invoke
* this function and pass two arguments: 'parameters' and a callback function. We often want to either
* do some inspection on the 'parameters' to make sure they're right, or invoke the callback to verify
* behavior after the callback, such as after an XHR returns.
*/
describe("someFunctionThatInvokesOurCollaborator", function () {
var instance,
TemplateResource;
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 / atom-keymap.cson
Created May 29, 2015 02:48
My Atom Keymap
# Your keymap
#
# Atom keymaps work similarly to stylesheets. Just as stylesheets use selectors
# to apply styles to elements, Atom keymaps use selectors to associate
# keystrokes with events in specific contexts.
#
# You can create a new keybinding in this file by typing "key" and then hitting
# tab.
#
# Here's an example taken from Atom's built-in keymap:
@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
}
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 / 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
@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)