Skip to content

Instantly share code, notes, and snippets.

View standinga's full-sized avatar

standinga

View GitHub Profile
@standinga
standinga / extensions.swift
Created February 17, 2019 10:42
NSImage to CIImage and NSImage from CIImage OSX IOS Swift 4
import Cocoa
extension NSImage {
var ciimage: CIImage? {
guard let tiffData = self.tiffRepresentation,
let bitmap = NSBitmapImageRep(data: tiffData) else {
return nil
}
return CIImage(bitmapImageRep: bitmap)
}
@standinga
standinga / heap.swift
Created April 1, 2019 12:38
Heap swift
struct Heap {
var a = [Int]()
init(_ array: [Int]) {
a = array
for i in stride(from: a.count / 2 - 1, to: 0, by: -1) {
bubbleDown(i)
}
}
@standinga
standinga / Package.swift
Created April 12, 2019 15:18
Vapor Package.swift with FluentMySQL
// swift-tools-version:4.2
import PackageDescription
let package = Package(
name: "server",
products: [
.library(name: "server", targets: ["App"]),
],
dependencies: [
.package(url: "https://github.com/vapor/vapor.git", from: "3.0.0"),
@standinga
standinga / Todo.swift
Created April 12, 2019 15:24
Vapor template update Todo.swift to use MySQL instead of SQLite
import FluentMySQL
import Vapor
final class Todo: Codable {
var id: Int?
var title: String
init(id: Int? = nil, title: String) {
self.id = id
self.title = title
@standinga
standinga / configure.swift
Created April 12, 2019 15:29
configure.swift from Vapor template updated with FluentMySQL instead of MySQLite
import FluentMySQL
import Vapor
/// Called before your application initializes.
public func configure(_ config: inout Config, _ env: inout Environment, _ services: inout Services) throws {
// Register providers first
try services.register(FluentMySQLProvider())
// Register routes to the router
let router = EngineRouter.default()
@standinga
standinga / docker-compose.yml
Created April 12, 2019 15:34
Docker compose for medium article
version: "3.7"
services:
db:
image: mysql:5
env_file:
- .env
networks:
- todonet
ports:
- "3306:3306"
@standinga
standinga / .env
Created April 12, 2019 15:35
.env file for medium article about vapor and docker-compose
DATABASE_HOST=db
MYSQL_ROOT_PASSWORD=root
MYSQL_USER=test
MYSQL_PASSWORD=test
MYSQL_DATABASE=todos
@standinga
standinga / web.Dockerfile
Created April 12, 2019 15:47
web.Dockerfile from Vapor template modified to be able to read .env from docker-compose
# You can set the Swift version to what you need for your app. Versions can be found here: https://hub.docker.com/_/swift
FROM swift:4.2 as builder
ARG env
RUN apt-get -qq update && apt-get -q -y install \
tzdata \
&& rm -r /var/lib/apt/lists/*
WORKDIR /app
COPY . .
@standinga
standinga / docker-compose.yml
Created April 12, 2019 15:50
update docker-compose.yml for medium article with both api and database
version: "3.7"
services:
api:
build:
context: .
dockerfile: web.Dockerfile
image: api
networks:
- todonet
depends_on:
@standinga
standinga / docker-compose.yml
Last active April 13, 2019 22:19
Docker compose server for medium article
version: "3.7"
services:
api:
image: borama.info/todos:latest
networks:
- boramanet
depends_on:
- "db"
env_file:
- .env