Skip to content

Instantly share code, notes, and snippets.

View jamesward's full-sized avatar

James Ward jamesward

View GitHub Profile
  implicit class TryWithForNot[T](t: Try[T]) {
    def fornot[A](f: Throwable => A): Unit = ???
  }

  implicit class SuccessWithForNot[T](success: Success[T]) {
    def fornot[A](f: Throwable => A): Unit = ()
  }

 implicit class FailureWithForNot[T](failure: Failure[T]) {
IMAGE=gcr.io/multiregion-atamel/where-am-i
wget https://github.com/stedolan/jq/releases/download/jq-1.6/jq-linux64
chmod +x jq-linux64
sudo mount -o remount,exec /home
CID=$(docker ps | grep $IMAGE | awk '{ print $1 }')
TOKEN=$(curl "http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/token" -H "Metadata-Flavor: Google" | ./jq-linux64 -r ".access_token")
docker login -u oauth2accesstoken -p "$TOKEN" https://gcr.io
docker pull $IMAGE
@jamesward
jamesward / cnb-sample.yaml
Created March 6, 2019 21:37
CNCF Buildpacks Demo
apiVersion: build.knative.dev/v1alpha1
kind: Build
metadata:
name: hello-springboot-mvn-build
spec:
source:
git:
url: https://github.com/jamesward/hello-springboot-mvn.git
revision: master
template:
@jamesward
jamesward / kmonad.kts
Last active September 11, 2019 07:22
sealed class Bag<out THING> {
object Empty: Bag<Nothing>()
data class NonEmpty<out THING>(val thing: THING): Bag<THING>()
// Make a Bag with a THUNG in it
companion object {
fun <THUNG> make(thung: THUNG): Bag<THUNG> = NonEmpty(thung)
}
// Do stuff to the THING in the Bag by providing a thingToBagOfThang
trigger OpportunityCreatedWebhookTrigger on Opportunity (after insert) {
String url = 'https://echo-webhook.herokuapp.com/test1234';
String content = Webhook.jsonContent(Trigger.new, Trigger.old);
Webhook.callout(url, content);
}
case class WSRequest(url: String, headers: Map[String, String] = Map.empty) {
def withHeaders(_headers: (String, String)*): WSRequest = {
copy(headers = Map.from(_headers))
}
}
val r0 = WSRequest("asdf", Map("foo" -> "bar"))
val r1 = WSRequest("asdf")
val r2 = r1.withHeaders("foo" -> "bar") // syntactic sugar for r1.copy(headers = ...)
@jamesward
jamesward / README.md
Created January 14, 2021 18:13
Postgres Docker
docker run --rm -ePOSTGRES_PASSWORD=password -p5432:5432 --name my-postgres postgres:13.1

docker exec -it my-postgres psql -U postgres

cat foo.sql | docker exec -i my-postgres psql -U postgres
@jamesward
jamesward / run-gcloud.sh
Created April 14, 2021 20:07
run gcloud container
export GOOGLE_APPLICATION_CREDENTIALS=your.json
docker run -it \
-eCLOUDSDK_AUTH_CREDENTIAL_FILE_OVERRIDE=/certs/svc_account.json \
-v$GOOGLE_APPLICATION_CREDENTIALS:/certs/svc_account.json \
gcr.io/google.com/cloudsdktool/cloud-sdk
@jamesward
jamesward / run-cs.sh
Last active April 14, 2021 20:08
Run Cloud Shell via Docker
export GOOGLE_APPLICATION_CREDENTIALS=your.json
docker run -it \
-eTRUSTED_ENVIRONMENT=true \
-eCLOUDSDK_AUTH_CREDENTIAL_FILE_OVERRIDE=/certs/svc_account.json \
-v$GOOGLE_APPLICATION_CREDENTIALS:/certs/svc_account.json \
-v/var/run/docker.sock:/var/run/docker.sock \
--entrypoint=/bin/bash \
gcr.io/cloudshell-images/cloudshell \
--login
@jamesward
jamesward / boot-mvn.sh
Created May 4, 2021 18:09
Spring Boot Cloud Run Deploy
mkdir tmp
cd tmp
curl -sL https://start.spring.io/starter.zip -d bootVersion=2.4.5 -d dependencies=web -o demo.zip; unzip demo.zip; rm demo.zip
echo "hello, world" > src/main/resources/static/index.html
./mvnw spring-boot:build-image -Dspring-boot.build-image.imageName=gcr.io/jw-demo/springboot-demo -Dspring-boot.build-image.builder=gcr.io/buildpacks/builder:v1
docker push gcr.io/jw-demo/springboot-demo