Skip to content

Instantly share code, notes, and snippets.

@possen
possen / DiffableDataSource.swift
Last active June 21, 2020 23:32
Minimal UITableViewDiffableDataSource Playground
//
// Minimal code to get Diffable Data Sources working in a Playground.
// Easier to understand than the WWDC examples.
//
// Paul Ossenbruggen
//
import UIKit
import PlaygroundSupport
let list = [
@possen
possen / export-fat-swift-dynamic-framework.sh
Last active August 23, 2019 11:19 — forked from eladnava/export-fat-swift-dynamic-framework.sh
Updated for Xcode 11, outputs to the xcarchive so it can be exported from organizer.
#set -x
exec > /tmp/${PROJECT_NAME}_archive.log 2>&1
#export XCODE_DEVELOPER_DIR_PATH=${DEVELOPER_DIR}
unset XCODE_DEVELOPER_DIR_PATH
#env
UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal
if [ "true" == ${ALREADYINVOKED:-false} ]
then
import Foundation
let confirmedJsonString = """
{
"title": "Confirmed",
"status": "confirmed",
"confirmedUsers": [
{"id": "abc", "name": "Rachel"},
{"id": "def", "name": "John"}
]
@possen
possen / SudokuValidator2.swift
Last active June 29, 2020 07:39
Functional Sudoku Validator
//
// main.swift
// SudokuValidator
//
// Created by Paul Ossenbruggen on 8/5/18.
// Copyright © 2018 Paul Ossenbruggen. All rights reserved.
//
import Foundation
import Foundation
func convertToEnglish(number: Int) -> (Int, String) {
let unitsMap = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"]
let tensMap = ["zero", "ten", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"]
let denom = [ "", " hundred", " thousand", "", " hundred", " million", "", " hundred", " billion"]
if number == 0 {
@possen
possen / ff
Last active April 17, 2018 18:03
find for zsh
function ff() {
if [ -n "$1" ]
then
find . -name "$1" $@[2,-1]
else
echo "usage: ff name"
fi
}
function ffi() {
@possen
possen / Idiomatic_Swift.md
Last active October 24, 2017 01:05
Adapted to Swift from Raymond Hettinger's talk at pycon US 2013

Transforming Code into Beautiful, Idiomatic Swift

Adapted to Swift 4 from Raymond Hettinger's talk at pycon US 2013 by Paul Ossenbruggen github video, slides. Many of the nice idioms of Python are here in Swift and some are even nicer. Python idioms apply well to Swift in most cases. Although, the types can add more verbosity. Even if you don't know Python, these approches should be easy to understand both becuase Python is sometimes thought of a runnable psuedocode and because the same approachs are encouraged in most modern languages.

The code examples and direct quotes are all from Raymond's talk where appropriate. If something does not make sense in Swift I deleted that section. I tried to stay close to the original examples, but in some cases added more where Swift has more alternatives.

@possen
possen / beautiful_idiomatic_python.md
Created October 19, 2017 05:23 — forked from JeffPaine/beautiful_idiomatic_python.md
Transforming Code into Beautiful, Idiomatic Python: notes from Raymond Hettinger's talk at pycon US 2013. The code examples and direct quotes are all from Raymond's talk. I've reproduced them here for my own edification and the hopes that others will find them as handy as I have!

Transforming Code into Beautiful, Idiomatic Python

Notes from Raymond Hettinger's talk at pycon US 2013 video, slides.

The code examples and direct quotes are all from Raymond's talk. I've reproduced them here for my own edification and the hopes that others will find them as handy as I have!

Looping over a range of numbers

for i in [0, 1, 2, 3, 4, 5]:
@possen
possen / sierra-hackintosh-z270-ar.md
Last active May 11, 2019 18:35 — forked from unsalted/sierra-hackintosh-z170-a.md
Sierra 10.12.6 Hackintosh | Asus z270-AR, Intel i5 7600, MSI 1080 Gaming X 8GB, EVGA 1080 8GB Kaby Lake

Sierra 10.12.6 Hackintosh

Based upon this GIST which was great!

This is my build documentation for an ASUS PRIME Z270-AR setup with an MSI 1080 Gaming X 8GB, EVGA 1080 8GB and the Intel i5 7600, most of this came from the person I forked this guide from. This build also doesn't have NVRAM. Nearest I can tell everything is running as expected, including all USB and audio ports. Make sure you get MacOS 10.12.6 as it has native support for Kaby Lake processors, and you won't need to fake the CPUID.

Build

  • Asus Z270-AR
  • Intel Core i5-7600 (Intel(R) Core(TM) i5-7600 CPU @ 3.50GHz)*
@possen
possen / SudokuValidator.swift
Last active April 14, 2017 04:56
Validates a sudoku puzzle.
import Foundation
func validateSudoku(array : [Int]) -> Bool {
let width = 9
func valueAtPos(x: Int, y: Int, array: [Int]) -> Int {
return array[y * width + x]
}