Skip to content

Instantly share code, notes, and snippets.

View Josscii's full-sized avatar
💭
??

Josscii Josscii

💭
??
View GitHub Profile
import UIKit
enum LayoutableButtonVerticalAlignment: String {
case center
case top
case bottom
case unset
}
enum LayoutableButtonHorizontalAlignment: String {
@kishikawakatsumi
kishikawakatsumi / ReorderingRealmResultsInTableView.swift
Created July 27, 2016 04:51
Reorder Realm Results in UITableView
import UIKit
import RealmSwift
class Data: Object {
dynamic var name = ""
...
dynamic var order = 0 // 並べ替えのためのカラムが必要
}
@hotpaw2
hotpaw2 / RecordAudio.swift
Last active April 3, 2024 03:10
Swift Audio Recording class. Reads buffers of input samples from the microphone using the iOS RemoteIO Audio Unit API
//
// RecordAudio.swift
//
// This is a Swift class (updated for Swift 5)
// that uses the iOS RemoteIO Audio Unit
// to record audio input samples,
// (should be instantiated as a singleton object.)
//
// Created by Ronald Nicholson on 10/21/16.
// Copyright © 2017,2019 HotPaw Productions. All rights reserved.
@robnadin
robnadin / NSDate+ISO8601.swift
Created March 8, 2016 16:44
Fast C-based ISO8601 date parser written in Swift
import Foundation
extension NSDate {
class func dateFromISO8601String(string: String?) -> NSDate? {
guard let string = string else {
return nil
}
var tm = Darwin.tm()
@preble
preble / NSTextStorageSubclass.swift
Created February 9, 2016 04:45
Base subclass of NSTextStorage in Swift
import Cocoa
@objc
class SomeTextStorage: NSTextStorage {
private var storage: NSMutableAttributedString
override init() {
storage = NSMutableAttributedString(string: "", attributes: nil)
super.init()
@jkosoy
jkosoy / CGSize+AspectFunctions.swift
Last active June 3, 2023 18:11
Aspect Fill and Aspect Fit calculations in Swift
// port of http://stackoverflow.com/a/17948778/3071224
import UIKit
import Foundation
extension CGSize {
static func aspectFit(aspectRatio : CGSize, var boundingSize: CGSize) -> CGSize {
let mW = boundingSize.width / aspectRatio.width;
let mH = boundingSize.height / aspectRatio.height;
@n00neimp0rtant
n00neimp0rtant / gist:27829d87118d984232a4
Last active May 24, 2019 15:10
UIVisualEffectView blur radius manipulation (new for iOS 9)
// iOS 9 allows you to animate between visual effects, which gives you the
// ability to manipulate the blur radius. this can be useful for animating
// a backdrop for a custom modal, and with a few tricks, can even be set
// indirectly, allowing you to "scrub" between them back and forth with
// a gesture, just like when you pull down Spotlight.
// these are the two effects you want to transition between
UIVisualEffect *startEffect = nil; // "nil" means no blur/tint/vibrancy (plain, fully-transparent view)
UIVisualEffect *endEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
@ypresto
ypresto / YPLayoutGuideHelper.m
Last active April 20, 2020 15:07
Apply automaticallyAdjustsScrollViewInsets in child view controller like Container View or UIPageViewController
//
// YPLayoutGuideHelper.m
//
// Created by Yuya Tanaka, 2015
//
// This is free and unencumbered software released into the public domain.
// Refer: http://unlicense.org/
//
// automaticallyAdjustsScrollViewInsets doesn't work for child view controllers
// hosted by something like Container View or UIPageViewController.
@paulirish
paulirish / what-forces-layout.md
Last active April 30, 2024 17:56
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Generally, all APIs that synchronously provide layout metrics will trigger forced reflow / layout. Read on for additional cases and details.

Element APIs

Getting box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
@Kametrixom
Kametrixom / emoji.swift
Created August 3, 2015 20:46
Gets all Emoji Unicode code points from the latest Unicode source and prints them out (as Emoji). Also: Prints out all country flag emojis from "AA" to "ZZ"
import Foundation
import XCPlayground
XCPSetExecutionShouldContinueIndefinitely()
func getAllEmojis(completion: String? -> ()) {
let url = NSURL(string: "http://www.unicode.org/Public/UCD/latest/ucd/EmojiSources.txt")!
NSURLSession.sharedSession().dataTaskWithURL(url) { data, response, error in
guard let data = data where error == nil else {
completion(nil)