Skip to content

Instantly share code, notes, and snippets.

View islandjoe's full-sized avatar

Arthur Kho islandjoe

  • Helsinki, Finland
View GitHub Profile
@islandjoe
islandjoe / meme-machine-02-01.txt
Created June 25, 2018 08:24
Meme Machine: routes.swift - root route
router.get { (req)-> Future<View> in
let fileMgr = FileManager()
guard let files = try? fileMgr.contentsOfDirectory(at: origDir, includingPropertiesForKeys: nil) else {
throw Abort(.internalServerError)
}
let allFiles = files.map { $0.lastPathComponent }
let visibleFiles = allFiles.filter { !$0.hasPrefix(".") }
let context = ["files": visibleFiles]
@islandjoe
islandjoe / meme-machine-02-00.txt
Created June 25, 2018 08:20
Meme Machine: routes.swift - Paths for the 3 folders
let rootDir = DirectoryConfig.detect().workDir
let uploadDir = URL(fileURLWithPath: "\(rootDir)Public/uploads")
let origDir = uploadDir.appendingPathComponent("originals")
let thumbsDir = uploadDir.appendingPathComponent("thumbs")
@islandjoe
islandjoe / meme-machine-01-00.txt
Last active June 25, 2018 08:16
Meme Machine: Package.swift
.package(url: "https://github.com/vapor/leaf.git", from: "3.0.0-rc"),
.package(url: "https://github.com/twostraws/SwiftGD.git", .upToNextMinor(from: "2.0.0")),
@islandjoe
islandjoe / cocoapod-install-usage in.md
Created June 24, 2018 12:09
Installing and using Cocoapods for Swift projects

Installing Cocoapods for the first time

$ sudo gem install cocoapods
$ pod setup --verbose

Using Cocoapods in projects

@islandjoe
islandjoe / create-new-vapor-project.md
Created June 24, 2018 07:20
The steps to creating a new Vapor project.
$ cd <projX>
$ vapor new <proj-name> _template=twostraws/vapor-clean
$ cd <proj-name>
$ vapor xcode

After configuring the Package.swift:

@islandjoe
islandjoe / swift--wikipedia-rest-api.md
Created June 15, 2018 07:30
Wikipedia REST API for Alamofire (Swift)
let flowerName = "Morning Glory 
let wikipedia = "https://en.wikipedia.org/w/api.php"
let parameters = [
  "format": "json",
  "action":   "query",
  "prop":       "extracts",
  "exintro":  "",
  "explaintext": "",
 "titles": flowerName,
@islandjoe
islandjoe / swift--performant-fibonacci.md
Created June 10, 2018 17:17
A performant Fibonacci function. Much preferable than the recursive version.
func fibn(n: UInt) -> UInt {
  if n == 0 {
    return n
  }
  
  var last: UInt = 0, 
      next: UInt = 1
  
 for _ in 1..
@islandjoe
islandjoe / python--read-text-file.md
Created June 4, 2018 17:40
Reading from a text file in Python.
theFile = open("messages.txt", "r")
messages = theFile.read().splitlines()
theFile.close()
@islandjoe
islandjoe / ml-scene-classification.md
Created June 4, 2018 17:13
The minimum amount of code needed to perform a scene classification in CoreML.
let sceneModel = SceneClassifier()
if let prediction = try? sceneModel.prediction(sceneImage: image) {
	return prediction.sceneType
}
We can't make this file beautiful and searchable because it's too large.
index,name,sex
0,Mary,F
1,Anna,F
2,Emma,F
3,Elizabeth,F
4,Minnie,F
5,Margaret,F
6,Ida,F
7,Alice,F
8,Bertha,F