Skip to content

Instantly share code, notes, and snippets.

View jkereako's full-sized avatar

Jeff Kereakoglow jkereako

View GitHub Profile
import Foundation
import XCTest
final class STDOUTListener {
/// Consume messages sent to STDOUT
let input = Pipe()
/// Sends messages back to STDOUT
let output = Pipe()
import Foundation
/// Synchronously wait for an asynchronous task.
///
/// Use this is if you need to execute an asynchronous task in a synchronous
/// context _and_ the result from the asynchronous task is needed before
/// execution can proceed.
func synchronouslyWait(for closure: @escaping @Sendable () async -> Void, timeout: TimeInterval = 2) {
let group = DispatchGroup()
@jkereako
jkereako / oauth-rfc.md
Last active April 19, 2024 13:21
OAuth RFCs

I couldn't keep track of all the RFCs related to OAuth. So here they are.

OAuth 2.0 RFCs

  1. [The OAuth 2.0 Authorization Framework][1]
  2. [Proof Key for Code Exchange by OAuth Public Clients][2]
  3. [OAuth 2.0 for Native Apps][3]
  4. [OAuth 2.0 Device Authorization Grant][4]

These RFCs underly the OAuth.

  1. [JSON Web Token (JWT)][5]
@jkereako
jkereako / Hash.swift
Last active January 12, 2024 17:25
Hashing in Swift
import CryptoKit
/// Hashes a string and returns it as a string.
func hash(_ string: String) -> String {
guard let data = string.data(using: .utf8) else { return "null" }
return SHA256
.hash(data: data)
.map { String(format: "%02x", $0) }
@jkereako
jkereako / ip.sh
Last active October 18, 2023 13:58
Prints the current SSID name and the local and public IP addresses
#!/usr/bin/env bash
#
# ip
#
# Shows the local and public IP addresses
set -Eeuo pipefail
# Print out error messages to STDERR.
function err() {
@jkereako
jkereako / resetxc.sh
Last active November 8, 2023 15:09
Reset Xcode
#!/usr/bin/env bash
#
# resetxc
#
# Kills Xcode, deletes all caches and build artifacts and re-opens Xcode
set -Eeuo pipefail
# Print out error messages to STDERR.
function err() {
@jkereako
jkereako / NetworkClient.swift
Last active October 18, 2023 13:21
Networking
import Foundation
public enum HTTPMethod: String {
case get = "GET"
case post = "POST"
case put = "PUT"
case delete = "DELETE"
}
public enum NetworkError: Error {
@jkereako
jkereako / replace-links.js
Last active June 17, 2022 21:35
Replace tokenized links with query string arguments.
@jkereako
jkereako / ReCAPTCHAViewController.swift
Created September 8, 2020 13:15
ReCAPTCHA v2 in Swift
import UIKit
import WebKit
final class ReCAPTCHAViewController: UIViewController {
private var webView: WKWebView!
private let viewModel: ReCAPTCHAViewModel
init(viewModel: ReCAPTCHAViewModel) {
self.viewModel = viewModel
@jkereako
jkereako / Font.swift
Created September 7, 2020 16:30
Example of using an Swift enum as a factory.
enum Font {
enum Style: String {
case bold = "Bold"
case regular = "Regular"
}
case fontAwesome(size: CGFloat)
case roboto(size: CGFloat, style: Style)
case robotoCondensed(size: CGFloat, style: Style)