Skip to content

Instantly share code, notes, and snippets.

View littlebobert's full-sized avatar

Justin Garcia littlebobert

View GitHub Profile
@littlebobert
littlebobert / swiftui-token-view.swift
Last active February 15, 2021 23:05
the beginnings of a SwiftUI based token input view
import SwiftUI
extension String {
func width(using font: UIFont) -> CGFloat {
let fontAttributes = [NSAttributedString.Key.font: font]
let size = self.size(withAttributes: fontAttributes)
return size.width
}
@littlebobert
littlebobert / movie-import-migration.swift
Created May 24, 2020 18:18
migration that imports from a CSV
final class MovieImport: Migration {
typealias Database = SQLiteDatabase
static func prepare(on conn: SQLiteConnection) -> EventLoopFuture<Void> {
MovieDatabase.shared.populateFromCSV(connection: conn)
return conn.eventLoop.newPromise(of: Void.self).futureResult // Is this correct?
}
static func revert(on conn: SQLiteConnection) -> EventLoopFuture<Void> {
@littlebobert
littlebobert / add-records.swift
Created May 24, 2020 15:25
Adding records to my Movie table
// I have one table: Movie. To add records, after the Movie migration I’m doing:
let worker = MultiThreadedEventLoopGroup(numberOfThreads: 1)
let conn = sqliteDatabase.newConnection(on: worker)
let _ = conn.map { connection in
// Open the CSV file
for line in lines {
// Parse the line to get the title, etc.
let movie = Movie(id: id, title: title)
dispatchGroup.enter()
let future = movie.save(on: connection)
version: 2
jobs:
build:
macos:
xcode: "9.4.0"
# The rest of our build job
snapshots:
macos:
xcode: "9.4.0"
@littlebobert
littlebobert / search-bar.mm
Last active July 30, 2018 22:53
search bar inside a nav bar
UISearchController *searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
self.navigationItem.searchController = searchController;
self.definesPresentationContext = YES;
searchController.obscuresBackgroundDuringPresentation = NO;
self.navigationItem.searchController.searchBar.placeholder = NSLocalizedString(@"Search", @"search bar placeholder text. typing into this search field filters the content below");
self.navigationItem.searchController.searchResultsUpdater = self;
import Foundation
protocol MyProtocol {
func foo()
}
class Parent {
func foo() {
print("parent")
}
protocol MyProtocol {
func method() -> String
}
extension MyProtocol {
func method() -> String {
return "foo"
}
}
AMPSession *session = [AMPSession ampSessionWithSessionAndProfileInfo:sessionAndProfileInfo];
[[session podcastWithId:@(contentID)] done:^(AMPv3Podcast *ampPodcast) {
NSLog(@"session: %@", session);
} rejected:^(NSError *error) {
if (completionHandler) {
completionHandler(nil, error);
}
}];
AMPTalkService *talkService = [AMPTalkService new];
[talkService addTalkRadioWithCotentID:showID
contentType:AMPRadioServiceContentTypeShow
addToFavorites:NO
sessionAndProfileInfo:sessionAndProfileInfo
completionHandler:^(CustomTalkRadio *radio, NSError *error) {
if (error) {
[self handleDidFailWithError:error];
return;
}
// before the change
BAPromise *promise = [self methodThatReturnsAPromise];
[promise then:^id(id obj) {
NSLog(@"1st");
return [[self otherMethodThatReturnsAPromise] then:^id(id obj) {
NSLog(@"2nd");
return obj;
}];
}];