Skip to content

Instantly share code, notes, and snippets.

@jepers
jepers / RandomSentenceGenerator.swift
Created June 2, 2017 22:57
A simple way to generate random sentences using NSSpellChecker.
import AppKit
let filteredWords = Set<String>(["app", "apps"])
let questionPrefixes = Set<String>([
"Which", "What", "Who", "Whom", "Whose", "Where", "When", "How", "Why", "Can",
"May", "Will", "Is", "Do", "Shall", "Has", "Must", "Would", "Could", "Should"
])
extension String {
@jepers
jepers / RandomGenerator.swift
Created June 3, 2017 06:51
A Swift 3.1 implementation of the Xoroshiro128+ generator
//
// RandomGenerator.swift
//
// Created by Jens Persson on 2017-05-22.
//
import Security // Only needed for SecRandomCopyBytes, used for random seed generation in the init() of RandomGenerator
// MARK: - RandomGenerator Protocol
@jepers
jepers / hexdump.swift
Last active April 14, 2019 11:15
Like hexdump -C but in Swift 4.1
import Foundation
/// Writes a canonical hex+ASCII representation of `bytes` into `output`.
func hexdump<Target>(_ bytes: UnsafeRawBufferPointer, to output: inout Target)
where Target: TextOutputStream
{
guard bytes.count > 0 else { return }
var asciiString = ""
@jepers
jepers / float8.swift
Last active March 24, 2020 11:27
A Float8 type
// ============================================================================
// This is an attempt at implementing a Float8 type by Jens Persson.
// It seems to work.
// This file is in the form of a command line program which will
// do some basic checks and print all Float8 values.
// ---------------------------------------------------------------------------
// Use it in any way you like, please let me know of any issues or
// improvements here: https://forums.swift.org/t/33337/38
// ===========================================================================