Skip to content

Instantly share code, notes, and snippets.

View PadraigK's full-sized avatar

Padraig PadraigK

View GitHub Profile
@PadraigK
PadraigK / change.diff
Last active October 2, 2023 17:29
New Prefix approach
diff --git a/generated-builtin/Projection.swift b/generated-builtin/Projection.swift
index 6f259ab..2141aa9 100644
--- a/generated-builtin/Projection.swift
+++ b/generated-builtin/Projection.swift
@@ -24,12 +24,12 @@ public struct Projection: Equatable, Hashable, GodotVariant {
public var z: Vector4
public var w: Vector4
public enum Planes: Int {
- case planeNear = 0 // PLANE_NEAR
- case planeFar = 1 // PLANE_FAR
@PadraigK
PadraigK / KeyboardDidShow.swift
Last active February 24, 2024 18:40
Wrapping Notifications for Sendability
// Example of wrapping `UIApplication.keyboardDidShowNotification` payload
struct KeyboardDidShowPayload {
let keyboardFrameBegin: CGRect?
let keyboardFrameEnd: CGRect?
}
extension NotificationWrapper where Payload == KeyboardDidShowPayload {
@MainActor static let keyboardDidShow: Self = .init(
name: UIApplication.keyboardDidShowNotification,
@PadraigK
PadraigK / generics.swift
Created May 12, 2022 00:21
Function signatures with generics
func makeOrReuse<T : IdentifierCellView>(_ cellType: T.Type, tableView: NSTableView) -> T
func makeOrReuse<T : IdentifierCellView>(tableView: NSTableView) -> T
// IMHO: The first signature is vastly superior even though the first argument is unncessary.
// Think about the call sites
let cell = makeOrReuse(ImageExportOptionCells.Toggle.self, tableView: tableView)
@PadraigK
PadraigK / NSTableViewFooter.swift
Last active November 14, 2019 20:48
Adding a footer to NSTableView
import Cocoa
class TableContainerView : NSView {
let tableView : NSTableView
let footerView : NSView
init(tableView: NSTableView) {
self.tableView = tableView
var containerFrame = tableView.frame
@PadraigK
PadraigK / clamp.swift
Last active May 17, 2019 17:51
Demonstrates clamping a closed range instead of min(maxBound, max(minBound, value))
/*
Instead of this...
CGFloat minConstant = -60.0f;
CGFloat maxConstant = self.actionViewDefaultBottomConstraintConstant;
CGFloat stuckConstant = maxConstant - distanceToBottom;
// :chefpoop:
actionViewBottomContraintConstant = fminf(maxConstant, fmaxf(minConstant, stuckConstant));
*/
Please go to
https://itunesconnect.apple.com/WebObjects/iTunesConnect.woa/ra/apps/[APP_ID]/promocodes/versions
(with [APP_ID] set properly)
and email us the JSON (support@supertop.co)

Keybase proof

I hereby claim:

  • I am PadraigK on github.
  • I am padraig (https://keybase.io/padraig) on keybase.
  • I have a public key whose fingerprint is CF1A 2C80 34ED 2A2A 8BD9 BD70 85D7 D932 29A7 0242

To claim this, I am signing this object:

@PadraigK
PadraigK / gist:d6d64787510136558552
Last active August 29, 2015 14:02
Help me get better at Swift
func rangeOfPixelsForRow(row: Int) -> Range<Int>
{
return row * imageSize.width..(row+1)*imageSize.width
}
func rangeOfPixelsForColumn(column: Int) -> StridedRangeGenerator<Int>
{
return (column..imageSize.height*imageSize.width).by(imageSize.width)
}
@PadraigK
PadraigK / gist:1362baef8b1912f78d09
Last active August 29, 2015 14:01
How do I pixels?
CGColorSpaceRef cs = CGColorSpaceCreateDeviceRGB();
CGContextRef bmContext = CGBitmapContextCreate(NULL, width, height, 8, 4 * width, cs, (CGBitmapInfo) kCGImageAlphaNoneSkipLast);
CGContextDrawImage(bmContext, (CGRect){.origin.x = 0.0f, .origin.y = 0.0f, .size.width = width, .size.height = height}, imageRep);
CGColorSpaceRelease(cs);
RGBAPixel *pixels = (RGBAPixel*)CGBitmapContextGetData(bmContext);
// Outputting the first 10 pixels on different hardware (iPad Air, iPhone 5, Simulator) gives slightly differing pixel values.
// I am confuse.
@PadraigK
PadraigK / Widon't
Last active August 29, 2015 13:57
Quick and dirty implementation of Shaun Inman's 'Widont' in Cocoa
// Example:
//
// Widont makes the last space non-breaking
// so you don't end up with one word on its
// own.
//
// Widont makes the last space non-breaking
// so you don't end up with one word on
// its own.
//