Skip to content

Instantly share code, notes, and snippets.

View pivotaljohn's full-sized avatar
💭
🌤

John S. Ryan pivotaljohn

💭
🌤
View GitHub Profile
@pivotaljohn
pivotaljohn / LoadResource.java
Last active November 26, 2015 00:49
Idiom: Load a text file as a resource into a String.
String contentsOfFile = Resources.toString(Resources.getResource("path/to/resource"), Charsets.UTF_8);
@pivotaljohn
pivotaljohn / gist:ccd15700b1ce88ef30abcbe1abddc553
Created May 9, 2016 21:31
When you don't setup Espresso correctly
Getting this output
```
Testing started at 2:24 PM ...
05/09 14:24:43: Launching GreetingScreenTest
$ adb push /Users/pivotal/workspace/guards-android/modules/greeting/build/outputs/apk/greeting-debug-androidTest-unaligned.apk /data/local/tmp/com.reelsecurity.guardapp.greeting.test
$ adb shell pm install -r "/data/local/tmp/com.reelsecurity.guardapp.greeting.test"
pkg: /data/local/tmp/com.reelsecurity.guardapp.greeting.test
@pivotaljohn
pivotaljohn / MockitoConfiguration
Created May 19, 2016 17:47
Configure Mockito to, by default, throw an exception when un-mocked behavior is invoked.
package org.mockito.configuration;
import org.mockito.Mockito;
import org.mockito.stubbing.Answer;
public class MockitoConfiguration extends DefaultMockitoConfiguration {
@Override
public Answer<Object> getDefaultAnswer() {
return Mockito.RETURNS_SMART_NULLS;
}
package com.example.features;
import android.os.AsyncTask;
import android.support.annotation.VisibleForTesting;
/**
* @param <ARG> the type of arguments that can be passed in when executing this use case.
* @param <RESULT> the type of the outcome generated by this use case and passed its callback.
*/
public abstract class UseCase<ARG, RESULT> {

Keybase proof

I hereby claim:

  • I am pivotaljohn on github.
  • I am pivotaljohn (https://keybase.io/pivotaljohn) on keybase.
  • I have a public key ASDClwZrzqvKDcpV4URp9v1x9AhyTlBb3boViFT0-ht2Ywo

To claim this, I am signing this object:

@pivotaljohn
pivotaljohn / spring-security-oauth2.md
Last active December 6, 2017 23:17
Speedbumps I hit and covered in learning how to implement OAuth2 through Spring Security.
  • when generating the Authorization: Basic value, I did something like this:
    $ echo "client-id:client-secret" | base64
    
    ... forgetting that echo adds the new-line. Resulting value will fail to match:
    {
      "timestamp":1512600410517,
      "status":401,
      "error":"Unauthorized",
    
@pivotaljohn
pivotaljohn / git-duet-rebase.sh
Created May 4, 2016 23:02
Reset author information to be the duet pair after a rebase.
#!/usr/bin/env bash
function usage_and_quit() {
echo "Reset author for specified ref through to HEAD to the current duet pair."
echo ""
echo "Usage:"
echo " $0 (base ref)"
exit 1
}
@pivotaljohn
pivotaljohn / k8s-notes.md
Last active October 21, 2019 14:47
Kubernetes Notes

Architecture

Master

  • this is the control plane of the cluster
  • etcd is the default backing store; others can be configured (q: what are the other viable options for a cluster backing store?)

Uncategorized Notes

@pivotaljohn
pivotaljohn / _ytt-loading-json.md
Last active April 17, 2020 21:17
Referencing JSON data in a ytt template
$ ytt --data-value-file stable_config=stable_config.json -f cluster-template-paving.yaml -f values.yml

Note: the values.yml defines the stable_config data value. Without that declaration, the implied overlay from --data-value-file would fail. That is: values provided on the command-line overlay values from data value files.

@pivotaljohn
pivotaljohn / _ytt-json-is-valid-yaml.md
Last active April 17, 2020 21:20
Loading data values from a JSON file

JSON is valid YAML. That is, YAML syntax is a superset of JSON syntax.

So, YAML parsers naturally parse JSON.

$ ytt --data-value-yaml "stable_config=$( cat stable_config.json )" -f cluster-template-paving.yaml -f values.yml

Note: the values.yml needs to be present for ytt at the time of writing because data values specified on the command-line are each applied as an overlay with default matching (i.e. matches exactly one node).