Skip to content

Instantly share code, notes, and snippets.

@jmcd
jmcd / RGBACGContext.swift
Last active September 25, 2024 21:23
Create CGContext (then images) from raw pixel data
import QuartzCore
extension CGContext {
private static let colorSpace = CGColorSpaceCreateDeviceRGB()
private static let bitmapInfo =
CGBitmapInfo.byteOrder32Big.rawValue |
CGImageAlphaInfo.premultipliedLast.rawValue & CGBitmapInfo.alphaInfoMask.rawValue
static func from(pixels: [UInt32], width: Int) -> CGContext? {
@BrandonRoehl
BrandonRoehl / Data+Extension.swift
Last active December 6, 2023 01:20 — forked from bleft/Data+Extension.swift
get md5 hash from Data in swift
import Foundation
import CommonCrypto
extension Data {
var md5 : String {
var digest = [UInt8](repeating: 0, count: Int(CC_MD5_DIGEST_LENGTH))
_ = self.withUnsafeBytes { bytes in
CC_MD5(bytes, CC_LONG(self.count), &digest)
}
var digestHex = ""
@jonhoo
jonhoo / README.md
Last active July 19, 2021 10:49
Distributed RWMutex in Go