Skip to content

Instantly share code, notes, and snippets.

View dbolella's full-sized avatar

Daniel Bolella dbolella

View GitHub Profile
@dbolella
dbolella / ListNavigation.swift
Created March 17, 2020 18:30
SwiftUI: Lists, Navigation, and Detail Views
import SwiftUI
struct ContentView: View {
var profile: Profile = Profile(name: "Danny", subtitle: "Awesome iOS Developer", description: "Danny loves SwiftUI and thinks it's the future of iOS Development!", profilePic: "profilepic")
var profile2: Profile = Profile(name: "George", subtitle: "An OK iOS Developer", description: "George should love SwiftUI and think that it's the future of iOS Development!", profilePic: "profilepic2")
var profile3: Profile = Profile(name: "Patrick", subtitle: "Android Developer", description: "Patrick is in love with SwiftUI and wants to switch to iOS Development!", profilePic: "profilepic2")
var body: some View {
NavigationView {
List([profile, profile2, profile3]){ curProfile in
@dbolella
dbolella / Intro.swift
Created March 16, 2020 20:51
SwiftUI: A New Starting Point into iOS Development
import SwiftUI
struct ContentView: View {
var body: some View {
VStack {
Image("profilepic")
.resizable()
.aspectRatio(contentMode: .fit)
Text("Danny Bolella")
}
@dbolella
dbolella / CreatingCustomViews.swift
Created March 16, 2020 20:49
SwiftUI: Creating Custom Views and Manipulating Others
import SwiftUI
struct ContentView: View {
var body: some View {
ProfilePage()
}
}
struct ProfileInformation: View {
var body: some View {
@dbolella
dbolella / ReusableView.swift
Last active March 16, 2020 20:48
SwiftUI: Making Our Views More Dynamic and Reusable
import SwiftUI
struct ContentView: View {
var profile: Profile = Profile(name: "Danny", subtitle: "Awesome iOS Developer", description: "Danny loves SwiftUI and thinks it's the future of iOS Development!", profilePic: "profilepic")
var profile2: Profile = Profile(name: "George", subtitle: "An OK iOS Developer", description: "George should love SwiftUI and think that it's the future of iOS Development!", profilePic: "profilepic")
var body: some View {
VStack {
ProfilePage(profile: profile)
ProfilePage(profile: profile2)
@dbolella
dbolella / DatasetCompilation.txt
Created November 20, 2019 14:55
Error received pulling in Datasets package
Installing packages:
.package(url: "https://github.com/tensorflow/swift-models.git", .branch("master"))
Datasets
With SwiftPM flags: []
Working in: /tmp/tmpcfyrcapb/swift-install
Fetching https://github.com/tensorflow/swift-models.git
Cloning https://github.com/tensorflow/swift-models.git
Resolving https://github.com/tensorflow/swift-models.git at master
[1/6] Compiling Datasets CIFAR10.swift
/tmp/tmpcfyrcapb/swift-install/package/.build/checkouts/swift-models/Datasets/CIFAR10/CIFAR10.swift:117:54: error: incorrect argument label in call (have 'permutation:', expected 'withPermutations:')
@dbolella
dbolella / TrainingLoop.swift
Last active November 11, 2019 17:25
Training Loop for LesNet-5 MNIST Model in S4TF
// The training loop.
for epoch in 1...epochCount {
var trainStats = Statistics()
var testStats = Statistics()
Context.local.learningPhase = .training
for i in 0 ..< dataset.trainingSize / batchSize {
let images = dataset.trainingImages.minibatch(at: i, batchSize: batchSize)
let labels = dataset.trainingLabels.minibatch(at: i, batchSize: batchSize)
// Compute the gradient with respect to the model.
let (loss, gradients) = valueWithGradient(at: model) { model -> Tensor<Float> in
@dbolella
dbolella / LinkPreviewWin.swift
Created October 29, 2019 18:57
Working LinkPreview in SwiftUI
struct ContentView: View {
@State var togglePreview = false
var body: some View {
VStack {
URLPreview(previewURL: URL(string: "https://medium.com")!, togglePreview: $togglePreview)
.aspectRatio(contentMode: .fit)
.padding()
}
@dbolella
dbolella / LinkPreviewFail.swift
Created October 29, 2019 18:53
Lacking implementation of LinkPreview in SwiftUI
struct ContentView: View {
var body: some View {
VStack {
URLPreview(previewURL: URL(string: "https://medium.com")!)
.aspectRatio(contentMode: .fit)
.padding()
}
}
}
@dbolella
dbolella / input.leaf
Created October 10, 2019 20:31
Leafs for SwiftKotlinOnline
#set("title") { Translate Kotlin }
#set("body") {
<textarea id="constantsText" rows="4" cols="50">
Please put swift code here...
</textarea>
<button onclick="post()">Click me</button>
<script>
function post() {
@dbolella
dbolella / TranslateKotlinController.swift
Created October 10, 2019 20:06
The Translation Controller for SwiftKotlinOnline
import Vapor
import Transform
import SwiftKotlinFramework
import Cocoa
/// Here we have a controller that helps facilitate
/// creating typical REST patterns
final class TranslateKotlinController {
/// POST /translate
func store(_ req: Request) throws -> Future<View> {