Skip to content

Instantly share code, notes, and snippets.

View heestand-xyz's full-sized avatar

Anton Heestand heestand-xyz

View GitHub Profile
/**
Returns an array of vertex positions.
- precondition: the geoemetry must have vertices which are 3-vectors with floating point component values
*/
fileprivate func vertices(source:SCNGeometrySource) -> [SCNVector3]
{
precondition(source.usesFloatComponents == true, "I can only handle three-vectors whose components are floating-point values, i.e., floats or doubles")
precondition(source.componentsPerVector == 3, "I can only be used for three vectors")
@lukeed
lukeed / OSX-Dock-Spacers.md
Last active March 26, 2025 07:25
OSX Dock Spacers

Huh?

Some MacOS users have very cluttered Docks & wish they could organize them without removing any App icons from the mix.

This snippet will add an empty "spacer" that you can drag around and use to separate icons into groups! See example.

Command

Paste this into your Terminal. Run the command for additional placeholders!

@itsthejb
itsthejb / main.swift
Created April 17, 2017 15:18
Simple Async Swift commandline tool outline
#!/usr/bin/swift
import Foundation
var keepAlive = true
dump(ProcessInfo().arguments)
let runLoop = RunLoop.current
let distantFuture = Date.distantFuture
@ivanbruel
ivanbruel / SnakeCase.swift
Last active March 19, 2023 16:42
Camel case to snake case in Swift
extension String {
func snakeCased() -> String? {
let pattern = "([a-z0-9])([A-Z])"
let regex = try? NSRegularExpression(pattern: pattern, options: [])
let range = NSRange(location: 0, length: self.characters.count)
return regex?.stringByReplacingMatches(in: self, options: [], range: range, withTemplate: "$1_$2").lowercased()
}
}
@powhu
powhu / GIF2MP4.swift
Last active December 10, 2024 20:44
Swift 5.0 GIF to MP4
//
// GIF2MP4.swift
//
// Created by PowHu Yang on 2020/4/24.
// Copyright © 2020 PowHu Yang. All rights reserved.
//
/* How to use
let data = try! Data(contentsOf: Bundle.main.url(forResource: "gif", withExtension: "gif")!)
let tempUrl = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent("temp.mp4")
@swillits
swillits / Keycodes.swift
Last active July 15, 2025 04:47
Swift Keyboard Keycodes
struct Keycode {
// Layout-independent Keys
// eg.These key codes are always the same key on all layouts.
static let returnKey : UInt16 = 0x24
static let enter : UInt16 = 0x4C
static let tab : UInt16 = 0x30
static let space : UInt16 = 0x31
static let delete : UInt16 = 0x33
static let escape : UInt16 = 0x35
@PoeHaH
PoeHaH / gist:ab9d8ac1b4ddee168d4d96c71797df31
Last active November 21, 2022 11:12
JSON representation of EU countries, 2 letter codes and VAT amounts. Good to check the EU VIES database
var euList =
[
{country:'Austria',code:'AT',vat:20},
{country:'Belgium',code:'BE',vat:21},
{country:'Bulgaria',code:'BG',vat:20},
{country:'Croatia',code:'HR',vat:25},
{country:'Cyprus',code:'CY',vat:19},
{country:'Czech Republic',code:'CZ',vat:21},
{country:'Denmark',code:'DK',vat:25},
{country:'Estonia',code:'EE',vat:20},
@CanTheAlmighty
CanTheAlmighty / DisplayLink.swift
Last active May 24, 2025 06:45
DisplayLink for OSX
@josephsieh
josephsieh / CGImage Rotation.png
Last active January 26, 2024 16:12
Rotate CGImage 90 degree clock wise
CGImage Rotation.png
@kaishin
kaishin / snapshot.swift
Created January 10, 2016 14:29
NSView Snapshot
extension NSView {
var snapshot: NSImage {
guard let bitmapRep = bitmapImageRepForCachingDisplayInRect(bounds) else { return NSImage() }
bitmapRep.size = bounds.size
cacheDisplayInRect(bounds, toBitmapImageRep: bitmapRep)
let image = NSImage(size: bounds.size)
image.addRepresentation(bitmapRep)
return image
}
}