Skip to content

Instantly share code, notes, and snippets.

View nathanborror's full-sized avatar

Nathan Borror nathanborror

View GitHub Profile
@nathanborror
nathanborror / sm-2.swift
Last active February 11, 2018 00:13
SM-2 Algorithm
// Based on the SuperMemo 2 Algorithm:
// https://www.supermemo.com/english/ol/sm2.htm
import UIKit
struct Item {
let id: UUID
let prompt: String
let explaination: String
var score: Score
@nathanborror
nathanborror / delay.swift
Created January 30, 2018 18:42
Simulate Slow Connection
let task = URLSession.shared.dataTask(with: req) { (data, response, error) in
...
}
DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(4)) {
task.resume()
}
@nathanborror
nathanborror / instructions.txt
Last active May 17, 2023 00:55
Example Kubernetes setup with Postgres and two Services for serving an API and a static site using Ingress. Also have a CronJob example for kicks.
*** Cluster Setup for Google Container Engine ***
0/ Install and configure local gcloud and kubectl: https://cloud.google.com/sdk/docs/
> gcloud components install kubectl
1/ Configure Google Cloud account:
> gcloud config set account YOUR_EMAIL_ADDRESS
> gcloud config set project YOUR_PROJECT_ID
> gcloud config set compute/zone us-west1-a
> gcloud config set container/cluster example
var jwt = require("jsonwebtoken")
var http2 = require("http2")
const ALGORITHM = "ES256"
const APNS_KEY_ID = "YOUR_APNS_KEY_ID"
const TEAM_ID = "YOUR_TEAM_ID"
const BUNDLE_ID = "YOUR_BUNDLE_ID"
const REGISTRATION_ID = "YOUR_DEVICE_PUSH_TOKEN"
const CERT =
@nathanborror
nathanborror / index.js
Last active November 27, 2018 21:01
Slack webhook Cloud Functions for Google Cloud Container Builder
const IncomingWebhook = require("@slack/client").IncomingWebhook
const SLACK_WEBHOOK_URL = "SLACK_WEBHOOK_URL"
const webhook = new IncomingWebhook(SLACK_WEBHOOK_URL)
// subscribe is the main function called by Cloud Functions.
module.exports.slackSubscribe = (event, callback) => {
const build = eventToBuild(event.data.data)
// Skip if the current status is not in the status list.
package ledger
import (
"encoding/json"
"time"
"github.com/jmoiron/sqlx"
"github.com/jmoiron/sqlx/types"
uuid "github.com/satori/go.uuid"
)
/*
Package entity implements functions to store and manipulate entity records
in a schema-less database. The current implementation supports Postgres only.
Inspired by: https://backchannel.org/blog/friendfeed-schemaless-mysql
Example implementation:
type Account struct {
ID string
Name string
package main
//go:generate esc -o static.go -prefix "/" static
import (
"flag"
"fmt"
"os"
"text/template"
)
class TextViewCell: UITableViewCell {
var onTap: ((URL) -> Void)?
lazy var textView: UITextView = {
let view = UITextView()
view.translatesAutoresizingMaskIntoConstraints = false
view.backgroundColor = UIColor(red: 1.0, green: 0, blue: 0, alpha: 0.1)
view.textContainer.lineFragmentPadding = 0
view.textContainerInset = .zero
#!/bin/bash
#
# Generate RSA certificate and key
#
# The 'host' is the host on which the server is listening and 'prefix' is just
# used to prefix the output files.
#
# $ gen.sh <host> <prefix>
#