Skip to content

Instantly share code, notes, and snippets.

@armstrongnate
armstrongnate / svg-from-data.swift
Created January 12, 2023 22:19
Render SVG from data in swift
private func imageFrom(url: URL?, data: Data, response: HTTPURLResponse? = nil) -> AnyPublisher<UIImage?, Error> {
let type = response?.mimeType
if type?.hasPrefix("image/svg") == true || url?.pathExtension.lowercased() == "svg" {
return svgFrom(data: data)
}
return Just(UIImage(data: data)).setFailureType(to: Error.self).eraseToAnyPublisher()
}
private func svgFrom(data: Data) -> AnyPublisher<UIImage?, Error> {
@armstrongnate
armstrongnate / dateformats.swift
Created May 5, 2022 16:41
Default iOS Date Formats (to send to a designer)
import Foundation
import SwiftUI
import CoreLocation
let jan = Calendar.current.date(from: DateComponents(year: 2021, month: 1, day: 1, hour: 2, minute: 0))!
let styles: [DateFormatter.Style] = [
.none,
.short,
.medium,
<<<<<<< HEAD
if let titleView: UIView = titleViewFromNavBarImagePath(navBarImagePath: navBarImagePath) {
titleView.contentMode = .scaleAspectFit
let container = UIView(frame: CGRect(x: 0, y: 0, width: 32, height: 32))
titleView.frame = CGRect(x: 0, y: 0, width: 32, height: 32)
container.addSubview(titleView)
self.navigationItem.titleView = container
}
else {
self.navigationItem.titleView = nil
func testDeleteFolder() {
attempt {
let session = Session.nas
var response: JSONObject?
stub(session, "delete-folder") { expectation in
try! Folder.deleteFolder(session, folderID: "10396915")
.startWithCompletedExpectation(expectation) { value in
response = value
}
@armstrongnate
armstrongnate / dequeue_default_table_view_cell.swift
Created December 11, 2015 23:22
tableView:cellForRowAtIndexPath using UITableViewCell class with preset style
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell: UITableViewCell?
cell = tableView.dequeueReusableCellWithIdentifier(UITableViewCell.wta_reuseableIdentifier())
if cell == nil {
cell = UITableViewCell(style: .Value1, reuseIdentifier: UITableViewCell.wta_reuseableIdentifier())
}
if let result = viewModel?.results.value[indexPath.row] {
ai::Agent::Action * Chan::Program(const ai::Agent::Percept * percept)
{
ai::CCheckers::Action *action = new ai::CCheckers::Action;
ai::CCheckers::MoveData move;
std::string board_str = percept->GetAtom("BASIC_BOARD").GetValue();
ai::CCheckers::BasicBoard board(board_str);
int player = atoi(percept->GetAtom("PLAYER_NUMBER").GetValue().c_str());
//
// UIImage+Blurs.swift
//
// Created by Nate Armstrong on 12/2/15.
// Copyright © 2015 Nate Armstrong. All rights reserved.
//
//
// Compression uses RBResizer: https://gist.github.com/hcatlin/180e81cd961573e3c54d
import Foundation
@armstrongnate
armstrongnate / .docker.env
Created August 31, 2015 00:40
Docker setup for ai
DISPLAY=192.168.0.2:0 # replace `192.168.0.2` with the host machine's local ip
@armstrongnate
armstrongnate / fetched-results-controller.swift
Last active August 29, 2015 14:19
UITableViewController with NSFetchedResultsController boilerplate
//
// MyViewController.swift
//
// Created by Nate Armstrong on 4/15/15.
// Copyright (c) 2015 Nate Armstrong. All rights reserved.
//
import UIKit
import CoreData
@armstrongnate
armstrongnate / setup-tab-bar-item.swift
Last active August 29, 2015 14:18
UIViewController extension for setting tabBarItem
// usage
class MyViewController: UIViewController {
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
setupTabBarItem("entries")
}
}
// where "entries" is the name of the image.
// should have 2 images named tabbar-entries and tabbar-entries-selected