Skip to content

Instantly share code, notes, and snippets.

View xaphod's full-sized avatar

Tim Carr xaphod

View GitHub Profile
@nicklockwood
nicklockwood / AnyFoo.swift
Last active March 17, 2021 17:57
POC for serializing heterogeneous array of structs using Codable in Swift
import Foundation
enum FooType: String, Codable {
case bar, baz
}
protocol Foo: Codable {
var type: FooType { get }
}
@vahidk
vahidk / colorTransform.js
Last active July 9, 2024 15:48
Convert RGB to HSL and vice versa in Javascript.
// This code is based on https://en.wikipedia.org/wiki/HSL_and_HSV
// Free to use for any purpose. No attribution needed.
function rgbToHsl(r, g, b) {
r /= 255; g /= 255; b /= 255;
let max = Math.max(r, g, b);
let min = Math.min(r, g, b);
let d = max - min;
let h;
if (d === 0) h = 0;
@tadija
tadija / README.md
Last active September 14, 2021 13:19
Sketch script for exporting artboards to separate .sketch files

sketch-artboards-to-documents

Sketch script for exporting artboards to separate .sketch files

Instructions

  1. Backup your .sketch file, it's going to be destroyed.
  2. Select all artboards you want to export to .sketch files.
  3. Run this script and find your new .sketch files on Desktop.
@insidegui
insidegui / WebCacheCleaner.swift
Created September 14, 2016 23:12
Clear WKWebView's cookies and website data storage, very useful during development.
import Foundation
import WebKit
final class WebCacheCleaner {
class func clean() {
HTTPCookieStorage.shared.removeCookies(since: Date.distantPast)
print("[WebCacheCleaner] All cookies deleted")
WKWebsiteDataStore.default().fetchDataRecords(ofTypes: WKWebsiteDataStore.allWebsiteDataTypes()) { records in
@simonkim
simonkim / CMBlockBufferHelper.swift
Created September 6, 2016 15:12
Sample code for creating NSData backed CMBlockBuffer using customBlockAllocator, in Swift.
//
// CMBlockBufferHelper.swift
//
// Created by Simon Kim on 2016. 9. 6..
// Copyright © 2016년 DZPub.com. All rights reserved.
//
import Foundation
import CoreMedia
/**
@couchdeveloper
couchdeveloper / RXTimer.h
Last active July 29, 2019 06:55
A timer based on dispatch_source_create() Objective-C
//
// RXTimer.h
//
// Copyright 2013 Andreas Grosam
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
@adamawolf
adamawolf / Apple_mobile_device_types.txt
Last active July 22, 2024 12:48
List of Apple's mobile device codes types a.k.a. machine ids (e.g. `iPhone1,1`, `Watch1,1`, etc.) and their matching product names
i386 : iPhone Simulator
x86_64 : iPhone Simulator
arm64 : iPhone Simulator
iPhone1,1 : iPhone
iPhone1,2 : iPhone 3G
iPhone2,1 : iPhone 3GS
iPhone3,1 : iPhone 4
iPhone3,2 : iPhone 4 GSM Rev A
iPhone3,3 : iPhone 4 CDMA
iPhone4,1 : iPhone 4S