Skip to content

Instantly share code, notes, and snippets.

View nathanborror's full-sized avatar

Nathan Borror nathanborror

View GitHub Profile
// https://stackoverflow.com/questions/56716311/how-to-show-complete-list-when-keyboard-is-showing-up-in-swiftui?noredirect=1&lq=1
import SwiftUI
import Combine
struct AdaptToKeyboard: ViewModifier {
@State var currentHeight: CGFloat = 0
func body(content: Content) -> some View {
@nathanborror
nathanborror / playground.swift
Last active January 3, 2023 22:16
Custom UIKit view with child SwiftUI views
import UIKit
import SwiftUI
import PlaygroundSupport
// CustomParentView is a custom UIKit view. Its Coordinator can be used
// to manage delegates if needed (e.g. UIContextMenuInteractionDelegate).
struct CustomParentView<Content: View>: UIViewRepresentable {
let content: UIView
@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"
)