Skip to content

Instantly share code, notes, and snippets.

View mkj-is's full-sized avatar
📱
Building iOS apps

Matěj Kašpar Jirásek mkj-is

📱
Building iOS apps
View GitHub Profile
@mkj-is
mkj-is / AppleLogoBezier.swift
Last active February 9, 2024 04:47
Apple logo bezier path
let path = UIBezierPath()
// Apple
path.move(to: CGPoint(x: 110.89, y: 99.2))
path.addCurve(to: CGPoint(x: 105.97, y: 108.09), controlPoint1: CGPoint(x: 109.5, y: 102.41), controlPoint2: CGPoint(x: 107.87, y: 105.37))
path.addCurve(to: CGPoint(x: 99.64, y: 115.79), controlPoint1: CGPoint(x: 103.39, y: 111.8), controlPoint2: CGPoint(x: 101.27, y: 114.37))
path.addCurve(to: CGPoint(x: 91.5, y: 119.4), controlPoint1: CGPoint(x: 97.11, y: 118.13), controlPoint2: CGPoint(x: 94.4, y: 119.33))
path.addCurve(to: CGPoint(x: 83.99, y: 117.59), controlPoint1: CGPoint(x: 89.42, y: 119.4), controlPoint2: CGPoint(x: 86.91, y: 118.8))
path.addCurve(to: CGPoint(x: 75.9, y: 115.79), controlPoint1: CGPoint(x: 81.06, y: 116.39), controlPoint2: CGPoint(x: 78.36, y: 115.79))
path.addCurve(to: CGPoint(x: 67.58, y: 117.59), controlPoint1: CGPoint(x: 73.31, y: 115.79), controlPoint2: CGPoint(x: 70.54, y: 116.39))
@mkj-is
mkj-is / XCTestCase+ScreenshotAssert.swift
Last active September 16, 2023 04:08
Swift to xcpretty screenshot saving
import XCTest
extension XCTestCase {
func assertFailScreenshot(_ closure: @autoclosure () -> Bool, message: String? = nil, file: String = #file, line: UInt = #line, function: String = #function) {
if !closure() {
takeScreenshot(description: message, file: file, line: line, function: function)
if let message = message {
XCTFail(message)
} else {
XCTFail()
@mkj-is
mkj-is / ImageClassificationService.swift
Created August 7, 2017 15:16
Example use of image classification using Vision framework
import Foundation
import FuntastyKit
import PromiseKit
import Photos
import Vision
import QuartzCore
protocol ImageClassificationService: Service {
func classify(asset: PHAsset) -> Promise<String>
@mkj-is
mkj-is / Discogs-scriptable-widget.js
Created October 8, 2020 18:32
Discogs collection widget
// This widgets show approximate value of your music collection on discogs.com
// and the last addition to the collection in the background.
// Configuration:
// Your Discogs personal token generated here: https://www.discogs.com/settings/developers
let token = "..."
// Your Discogs username
let username = "..."
// Widget:
@mkj-is
mkj-is / Nibable.swift
Last active October 13, 2020 10:20
Simple Nibable protocol for simple initialization of views from nib
//
// Nibable.swift
//
// Created by Matěj Kašpar Jirásek on 12/08/16.
// Copyright © 2016 Matěj Kašpar Jirásek. All rights reserved.
//
import UIKit
protocol Nibable {
@mkj-is
mkj-is / gpxs-to-geojson.sh
Last active June 5, 2020 14:53
Combine GPX files to one GeoJSON
#!/bin/bash
# Decompress all files (only some are compressed, primarily the newer ones)
for filename in *.gz
do
gzip -d $filename
done
# Convert all from GPX to GeoJSON
for filename in *.gpx
do
togeojson $filename > geojsons/$filename.geojson
@mkj-is
mkj-is / paper-stacks.html
Created January 21, 2013 23:34
Different CSS3 box-shadow paper-stacks (3rd is from here: http://cssdeck.com/labs/stacked-papers-using-box-shadow)
<!DOCTYPE html>
<html>
<head>
<title>Shadow test</title>
<style type="text/css">
#paper-stack1{
position: absolute;
top:100px;
left:100px;
width: 100px;
@mkj-is
mkj-is / ResultCodes.swift
Created April 7, 2019 08:53
Sqlite result codes enum for Swift
/// https://sqlite.org/rescode.html
enum ResultCode: Int {
/// The SQLITE_OK result code means that the operation was successful and that there were no errors. Most other result codes indicate an error.
case ok = 0
/// The SQLITE_ERROR result code is a generic error code that is used when no other more specific error code is available.
case error = 1
/// The SQLITE_INTERNAL result code indicates an internal malfunction. In a working version of SQLite, an application should never see this result code. If application does encounter this result code, it shows that there is a bug in the database engine.
///
@mkj-is
mkj-is / LiftOperator.swift
Last active March 28, 2019 16:21
Lift/const operator in Swift
/// Lift operator (instance to function, function to function with one more parameter, key-path to function)
/// This operator is similar to `const` function from Haskell.
prefix operator ^
/// Lift instance to function returning constant result.
@inline(__always)
prefix func ^ <T>(instance: @autoclosure @escaping () -> T) -> () -> T {
return instance
}
@mkj-is
mkj-is / LayerAnimations.swift
Last active March 3, 2019 10:22
Stroke animations on shape layers
// Set duration for single animation
let duration: TimeInterval = 2
// Enumerate all the layers
layers.enumerated().forEach { offset, layer in
// Create animation for each layer
let animation = CABasicAnimation(keyPath: "strokeEnd")
// Begin each animation after the one before
animation.beginTime = duration * CFTimeInterval(offset) + delay
animation.toValue = 1
animation.duration = duration