View someany.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol Vegetable { | |
var crunchy:Bool { get } | |
var volume:Int { get } //in mL | |
} | |
struct Carrot:Vegetable { | |
var volume: Int = 300 | |
var crunchy = true | |
} |
View FixedWidthInteger+Data.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension FixedWidthInteger { | |
var dataBigEndian: Data { | |
var int = self.bigEndian | |
return Data(bytes: &int, count: MemoryLayout<Self>.size) | |
} | |
var dataLittleEndian: Data { | |
var int = self.littleEndian |
View URLSessionDelegateExample.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
import PlaygroundSupport | |
import Foundation | |
PlaygroundPage.current.needsIndefiniteExecution = true | |
//URLSessionTaskDelegate | |
//You use this protocol in one of two ways, depending on how you use a URLSession: | |
//If you create tasks with Swift’s async-await syntax, using methods like bytes(for:delegate:) and data(for:delegate:), you pass a delegate argument of this type. The delegate receives callbacks for things like task progress, while the call point awaits the completion of the task. A delegate that receives life cycle and authentication challenge callbacks as the transfer progresses. | |
//If you add tasks to the session with methods like dataTask(with:) and downloadTask(with:), then you implement this protocol’s methods in a delegate you set on the session. This session delegate may also implement other protocols as appropriate, like URLSessionDownloadDelegate and URLSessionDataDelegate. You can also assign a delegate of this type directly to the task to intercept callbacks before the task deliver |
View json_tests.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { readFile, writeFile } from 'fs/promises'; | |
import { readFileSync, writeFileSync } from 'fs'; | |
function writeToJson(path, data, rewrite = false) { | |
let old_data = readFileSync(path); | |
if (old_data.length == 0 || rewrite == true) { | |
writeFileSync(path, JSON.stringify(data, null, 4)); | |
return; | |
} | |
let json_obj = [JSON.parse(old_data)]; // without brackets it reverts an error | |
json_obj.push(data); |
View AOC2022_day15.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Day15.swift | |
// AdventOfCode2022 | |
// | |
// Created by carlynorama on 12/15/22. | |
import Foundation | |
let testData = "day15_testinput" |
View drawPoints.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func drawPoints(array:[P], width:Int, height:Int) -> String { | |
var outterArray:[[String]] = [] | |
for _ in (0..<width) { | |
outterArray.append((Array(repeating: ".", count:height))) | |
} | |
for point in array { | |
outterArray[point.y][point.x] = "#" | |
} | |
//[Y][X] |
View regex_indexParser.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
let stringA = " 1 2 3 4 5 6 7 8 9" | |
let stringB = "[F] [R] [C] [F] [L] [Q] [F] [D] [P]" | |
let matches = stringA.matches(of: /\b[0-9]+\b/) | |
for match in matches { |
View SoftlyFailingIncompleteJSON.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
struct Traveler: Codable, Identifiable { | |
let firstName: String | |
let middleName: String? | |
let familyName: String | |
var id:String { | |
"\(familyName), \(firstName)" |
View GHAction_MoveFolderToNewBranch.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Simple workflow for deploying static content to GitHub Pages | |
name: Deploy static content to Pages | |
on: | |
# Runs on pushes targeting the default branch | |
push: | |
branches: ["main"] | |
paths: | |
- 'Output/**' |
View GHAction_NPMDeploy.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Deploy Project | |
on: [push, workflow_dispatch] | |
jobs: | |
mytests: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Get code | |
uses: actions/checkout@v3 | |
- name: Install NodeJS | |
uses: actions/setup-node@v3 |
NewerOlder