Skip to content

Instantly share code, notes, and snippets.

View vzsg's full-sized avatar

Zsolt Váradi vzsg

  • Budapest, Hungary
View GitHub Profile
@vzsg
vzsg / WhiteToTransparentProcessor.swift
Created October 18, 2016 19:28
Kingfisher processor that replaces #FFFFFF with transparent color
import Foundation
import Kingfisher
import CoreImage
private let colorCubeData: [Float] = [
0, 0, 0, 1,
1, 0, 0, 1,
0, 1, 0, 1,
1, 1, 0, 1,
0, 0, 1, 1,
for file in *.png
do
name=$(echo ${file%_*.png} | tr '[:upper:]' '[:lower:]' | tr ' ' '_')
tmp=${file##*_}
res=${tmp%.png}
mkdir -p drawable-$res
echo $file "->" drawable-$res/$name.png
mv "$file" "drawable-$res/$name.png"
done
@vzsg
vzsg / revert-github-header.user.js
Created February 10, 2017 22:36
Userscript to revert GitHub header to the light version
// ==UserScript==
// @name Revert GitHub theme
// @namespace https://github.com
// @version 0.1
// @description try to take over the world!
// @author vzsg
// @match https://*.github.com/*
// @grant none
// ==/UserScript==
@vzsg
vzsg / Config+Setup.swift
Created May 25, 2017 22:35
HTML5 Routing Compatibility Middleware for Vapor 2
extension Config {
public func setup() throws {
// ...
addConfigurable(middleware: Html5RoutingMiddleware.init, name: "html5")
}
// ...
}
@vzsg
vzsg / RSAKey+PEM.swift
Last active July 20, 2017 12:48
Vapor JWT extension for parsing RSA keys from PEM, e.g. for Firebase Authentication
extension RSAKey {
init?(pem: String) {
let bio = BIO_new(BIO_s_mem())
defer {
BIO_free(bio)
}
_ = pem.withCString { key in
BIO_puts(bio, key)
}
@vzsg
vzsg / RxAlamofire+Multipart.swift
Created July 26, 2017 09:28
Alamofire+RX multipart encoding
import Foundation
import Alamofire
import RxSwift
extension Reactive where Base: SessionManager {
func encodeMultipartUpload(to url: URLConvertible, method: HTTPMethod = .post, headers: HTTPHeaders = [:], data: @escaping (MultipartFormData) -> Void) -> Observable<UploadRequest> {
return Observable.create { observer in
self.base.upload(multipartFormData: data,
to: url,
method: method,
@vzsg
vzsg / RSAKey+PEM_2.swift
Last active July 31, 2017 11:29
Vapor JWT extension for parsing a PEM-encoded certificate
import CTLS
import JWT
extension RSAKey {
init?(cert: String) {
let bio = BIO_new(BIO_s_mem())
defer {
BIO_free(bio)
}
@vzsg
vzsg / Config+Setup.swift
Created August 2, 2017 08:22
Custom command for daily and weekly tasks for Vapor 2
import FluentProvider
extension Config {
public func setup() throws {
// ...
addConfigurable(command: DailyCommand.init, name: "daily")
}
// ...
}
@vzsg
vzsg / DemoModels.swift
Last active March 7, 2018 20:54
Simple extension to use Codable JSON with Vapor 2
import Foundation
struct MagicTestRequest: Codable {
let tokens: [String]
}
struct MagicTestResponse: Codable {
let count: Int
}
@vzsg
vzsg / 1_BreweryDatabase.swift
Last active December 27, 2017 20:31
Wrapping an external API for Vapor apps – service class approach
import Foundation
// A simple protocol that describes the services available on the external service
// FIXME: Beer is an immutable, Codable struct defined elsewhere, not important now
public protocol BreweryDatabase {
func search(_ query: String) throws -> [Beer]
func findBeer(id: String) throws -> Beer
}