Skip to content

Instantly share code, notes, and snippets.

View Iomegan's full-sized avatar

Daniel Witt Iomegan

View GitHub Profile
@atierian
atierian / DataCompression.swift
Last active August 5, 2022 20:18
Compressing and Decompressing Data
import Foundation
import Compression
import XCTest
extension Encodable {
/// Returns a string object describing the encodable object's byte size using `ByteCountFormatter`. Or a description of the `DecodingError` generated during the decoding process
var size: String {
do {
return try JSONEncoder().encode(self).size
} catch {
@Iomegan
Iomegan / CloudKitController.swift
Last active October 23, 2019 17:28
CloudKit Example Controller (macOS 10.12+)
import Cocoa
import CloudKit
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate {
func applicationDidFinishLaunching(_ notification: Notification) {
if #available(OSX 10.12, *) {
NSApp.registerForRemoteNotifications(matching: [])
}
@MatiMax
MatiMax / DNSResolve3.swift
Last active October 9, 2021 09:44
This Playground shows how to use Core Foundation's CFHost in *Swift 3* to try to produce an array of Strings containing the host name and all its aliases for a given IP address. Unfortunately, CFHostGetNames() does not supply the aliases of a host, so we're left alone with the gethostbyaddr() C function.
//: # How to retrieve a host name and associated aliases from an IP address using Core Fondation's `CFHost` in Swift 3
import Foundation
import PlaygroundSupport
//: In order to get the callback working we use a simple class to implement the showcase.
class DNSResolve {
//: The IP address may be a Swift `String` thanks to the toll-free bridging to C strings.
let ip: String = "17.172.224.47"
//: We use an optional `CFHost` variable because CFHost neither comes with an initializer nor is conforming to the Nullable protocol.
var host: CFHost?
//: We use this array of `String`s to store the resolved host names.
@Thesaurus
Thesaurus / BPCheckBoxButton.m
Created September 16, 2015 12:13
NSButton checkbox with wrapping title (despite what IB says a check box title does not wrap)
#import <Cocoa/Cocoa.h>
@interface BPCheckBoxButton : NSButton
@end
@implementation BPCheckBoxButton
- (void)setTitle:(NSString *)aString
{
@tempire
tempire / swift_draw_image_on_pdf.swift
Created April 25, 2015 09:24
swift draw image on pdf
func drawOnPDF(path: String) {
// Get existing Pdf reference
let pdf = CGPDFDocumentCreateWithURL(NSURL(fileURLWithPath: path))
// Get page count of pdf, so we can loop through pages and draw them accordingly
let pageCount = CGPDFDocumentGetNumberOfPages(pdf);
// Write to file
UIGraphicsBeginPDFContextToFile(path, CGRectZero, nil)
@JohnEstropia
JohnEstropia / JEProgressView.h
Last active October 5, 2023 14:59
Workaround an annoying bug with iOS 7.1 where custom track and progress images for UIProgressView gets ignored
//
// JEProgressView.h
//
//
// Created by John Rommel Estropia on 2014/03/11.
// Copyright (c) 2014 John Rommel Estropia.
//
// 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