Skip to content

Instantly share code, notes, and snippets.

View martincalvert's full-sized avatar

Martin martincalvert

View GitHub Profile
@martincalvert
martincalvert / Xcode_Playground_URLSession.swift
Last active November 7, 2021 15:13
How to run URLSession requests in the playground in XCode 8.3
//: Playground - noun: a place where people can play
import Foundation
import PlaygroundSupport
PlaygroundPage.current.needsIndefiniteExecution = true
var request = URLRequest(url: URL(string: "https://api.github.com/")!)
request.httpMethod = "GET"
let task = URLSession.shared.dataTask(with: request) { data, response, error in
guard let data = data, error == nil else {
@martincalvert
martincalvert / days_between_dates.swift
Created August 22, 2017 18:26
Swift Difference Between Dates
//: Playground - noun: a place where people can play
import Foundation
let now = Date()
let future = Date(timeIntervalSinceNow: TimeInterval(1000000))
let currentCalendar = Calendar.current
let calendarScale: Set<Calendar.Component> = [.day, .hour, .minute]
let difference = currentCalendar.dateComponents(calendarScale, from: now, to: future)
print("Days: \(difference.day!) Hours: \(difference.hour!) Seconds: \(difference.minute!)")
@martincalvert
martincalvert / deployment.yml
Last active October 25, 2017 15:47
K8s: Deployments
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: {{ .Chart.Name }}
labels:
chart: {{ .Chart.Name }}-{{ .Chart.Version }}
spec:
replicas: {{ .Values.api.replicas }}
template:
metadata:
{{ define "affinity_notation" }}
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: {{ .Values.nodeAffinity.key }}
operator: In
values:
- {{ .Values.nodeAffinity.value }}
@martincalvert
martincalvert / deployment_template.yml
Created November 9, 2017 16:33
K8s: Deployment Template
{{ define "ruby_api_deployment" }}
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: {{ .Values.rubyApi.name }}-api
labels:
chart: {{ .Chart.Name }}-{{ .Chart.Version }}
annotations:
"helm/created": {{ .Release.Time.Seconds | quote }}
spec:
@martincalvert
martincalvert / values.yml
Created November 9, 2017 16:36
K8s: Template Values File Example
environment: integration
nodeAffinity:
key: cloud.google.com/gke-nodepool
value: default
rubyApi:
name: guest
replicas: 1
livenessProbe:
type: livenessProbe
path: /health.json
@martincalvert
martincalvert / affinity_notation.yml
Created November 9, 2017 16:41
K8s: Random Templates
{{ define "affinity_notation" }}
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: {{ .Values.nodeAffinity.key }}
operator: In
values:
- {{ .Values.nodeAffinity.value }}
@martincalvert
martincalvert / requirements.yml
Created November 9, 2017 16:44
K8s: Requirements
dependencies:
- name: shared-helm-templates
version: 1.0.0
#repository: https://github.com/raw/martincalvert/helms/master
repository: file://../shared-helm-templates
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Values.app.name }}-nginx-config
labels:
chart: {{ .Chart.Name }}-{{ .Chart.Version }}
app: matterhorn-{{ .Values.app.name }}
tier: nginx
data:
nginx.conf: |-
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: {{ .Values.ruby.app.name }}-api
labels:
chart: {{ .Chart.Name }}-{{ .Chart.Version }}
annotations:
"helm/created": {{ .Release.Time.Seconds | quote }}
spec:
replicas: {{ .Values.ruby.app.replicas }}