Skip to content

Instantly share code, notes, and snippets.

@sukov
sukov / CodableExtension.swift
Last active November 25, 2022 17:27 — forked from mikebuss/decode-json-swift.swift
Codable (Encode & Decode) [Any] and [String: Any] Swift 5
// Original: https://gist.github.com/loudmouth/332e8d89d8de2c1eaf81875cfcd22e24
import Foundation
private struct JSONCodingKeys: CodingKey {
var stringValue: String
init(stringValue: String) {
self.stringValue = stringValue
}
@Akhu
Akhu / InvertMask+Layer.swift
Created May 12, 2017 12:53
Simple way to invert a mask on a layer with swift / quartzcore / ios
func mask(withRect rect: CGRect, inverse: Bool = false) {
let path = UIBezierPath(rect: rect)
let maskLayer = CAShapeLayer()
if inverse {
path.appendPath(UIBezierPath(rect: self.bounds))
maskLayer.fillRule = kCAFillRuleEvenOdd
}
maskLayer.path = path.CGPath
@feighter09
feighter09 / Fonts.swift
Last active June 25, 2021 19:24
Set global font for iOS app in one place
// MARK: - Swizzling
extension UIFont {
class var defaultFontFamily: String { return "Georgia" }
override public class func initialize()
{
if self == UIFont.self {
swizzleSystemFont()
}
}
@StefanJager
StefanJager / UIColor+Components.swift
Last active June 16, 2022 08:52
A more SWIFT-friendly approach to getting components from an UIColor
//
// UIColor+Components.swift
//
// Copyright (c) 2015 Stefan Jager
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
@b4oshany
b4oshany / sql_import.php
Created January 9, 2015 05:27
PHP PDO sql file import.
<?php
namespace libs\mysql;
class PDODbImporter{
private static $keywords = array(
'ALTER', 'CREATE', 'DELETE', 'DROP', 'INSERT',
'REPLACE', 'SELECT', 'SET', 'TRUNCATE', 'UPDATE', 'USE',
'DELIMITER', 'END'
);
@adamawolf
adamawolf / Apple_mobile_device_types.txt
Last active May 3, 2024 17:56
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
@aslakhellesoy
aslakhellesoy / rounding.java
Created August 9, 2011 16:18
Rounding up and down to nearest multiple
/** round n down to nearest multiple of m */
long roundDown(long n, long m) {
return n >= 0 ? (n / m) * m : ((n - m + 1) / m) * m;
}
/** round n up to nearest multiple of m */
long roundUp(long n, long m) {
return n >= 0 ? ((n + m - 1) / m) * m : (n / m) * m;
}