Skip to content

Instantly share code, notes, and snippets.

@alanzeino
alanzeino / lldb-debugging.md
Last active April 28, 2024 10:21
LLDB debugging with examples

LLDB Debugging Cheat Sheet

Commands

LLDB Commands

LLDB comes with a great set of commands for powerful debugging.

help

Your starting point for anything. Type help to get a list of all commands, plus any user installed ones. Type 'help for more information on a command. Type help to get help for a specific option in a command too.

@jacks205
jacks205 / timeago.swift
Last active October 15, 2018 21:54 — forked from minorbug/timeago.swift
"Time ago" function for Swift (based on MatthewYork's DateTools for Objective-C) *Swift 2
func timeAgoSinceDate(date:NSDate, numericDates:Bool) -> String {
let calendar = NSCalendar.currentCalendar()
let now = NSDate()
let earliest = now.earlierDate(date)
let latest = (earliest == now) ? date : now
let components:NSDateComponents = calendar.components([NSCalendarUnit.Minute , NSCalendarUnit.Hour , NSCalendarUnit.Day , NSCalendarUnit.WeekOfYear , NSCalendarUnit.Month , NSCalendarUnit.Year , NSCalendarUnit.Second], fromDate: earliest, toDate: latest, options: NSCalendarOptions())
if (components.year >= 2) {
return "\(components.year) years ago"
} else if (components.year >= 1){
@vlondon
vlondon / ImageToGrayscale.swift
Last active October 22, 2021 12:15
Convert image to grayscale
func convertImageToGrayScale(image: UIImage) -> UIImage {
// Create image rectangle with current image width/height
let imageRect: CGRect = CGRectMake(0, 0, image.size.width, image.size.height)
// Grayscale color space
let colorSpace: CGColorSpaceRef = CGColorSpaceCreateDeviceGray()
// Create bitmap content with current image size and grayscale colorspace
let bitmapInfo = CGBitmapInfo(CGImageAlphaInfo.None.rawValue)
var context = CGBitmapContextCreate(nil, UInt(image.size.width), UInt(image.size.height), 8, 0, colorSpace, bitmapInfo)
@chriseidhof
chriseidhof / swift.tex
Created October 8, 2014 13:44
Listings Swift config
\lstdefinelanguage{swift}
{
morekeywords={
func,if,then,else,for,in,while,do,switch,case,default,where,break,continue,fallthrough,return,
typealias,struct,class,enum,protocol,var,func,let,get,set,willSet,didSet,inout,init,deinit,extension,
subscript,prefix,operator,infix,postfix,precedence,associativity,left,right,none,convenience,dynamic,
final,lazy,mutating,nonmutating,optional,override,required,static,unowned,safe,weak,internal,
private,public,is,as,self,unsafe,dynamicType,true,false,nil,Type,Protocol,
},
morecomment=[l]{//}, % l is for line comment
@yannickl
yannickl / YLColor.swift
Last active September 16, 2023 03:55
Hex string <=> UIColor conversion in Swift
import Foundation
import UIKit
extension UIColor {
convenience init(hexString:String) {
let hexString:NSString = hexString.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet())
let scanner = NSScanner(string: hexString)
if (hexString.hasPrefix("#")) {
scanner.scanLocation = 1
@calebd
calebd / AsynchronousOperation.swift
Last active April 29, 2023 13:12
Concurrent NSOperation in Swift
import Foundation
/// An abstract class that makes building simple asynchronous operations easy.
/// Subclasses must implement `execute()` to perform any work and call
/// `finish()` when they are done. All `NSOperation` work will be handled
/// automatically.
open class AsynchronousOperation: Operation {
// MARK: - Properties
@mmick66
mmick66 / UICollectionViewFlowLayoutCenterItem.m
Last active August 2, 2022 10:06
UICollectionViewFlowLayout with arbitrary sized Paging
#import "UICollectionViewFlowLayoutCenterItem.h"
@implementation UICollectionViewFlowLayoutCenterItem
- (CGPoint)targetContentOffsetForProposedContentOffset:(CGPoint)proposedContentOffset withScrollingVelocity:(CGPoint)velocity
{
CGSize collectionViewSize = self.collectionView.bounds.size;
CGFloat proposedContentOffsetCenterX = proposedContentOffset.x + self.collectionView.bounds.size.width * 0.5f;
CGRect proposedRect = self.collectionView.bounds;