Skip to content

Instantly share code, notes, and snippets.

@eralston
eralston / NSArray+WeakArray.h
Last active July 5, 2023 09:11
An pair of Objective-C categories on NSArray and NSMutableArray that provides a mechanism for weak referencing any type of Objective-C object. This was created when I found a case, referencing protocols, where NSPointerArray did not work for my needs.
//
// NSMutableArray+WeakArray.h
//
#import <Foundation/Foundation.h>
///
/// Category on NSArray that provides read methods for weak pointers
/// NOTE: These methods may scan the whole array
///
uint64_t offset = section->offset;
struct segment_64 *text_segment = (struct segment_64 *)text_segment_pointer;
uint64_t addr_offset = section->addr - text_segment->vm_addr;
if (section->offset != addr_offset) {
offset = addr_offset;
}
uint64_t offset = section->offset;
struct segment_32 *text_segment = (struct segment_32 *)text_segment_pointer;
uint64_t addr_offset = section->addr - text_segment->vm_addr;
//
// KBCollectionExtensions.h
//
// Created by Guy English on 25/02/08.
// Copyright 2008 Kickingbear. All rights reserved.
//
#import <Cocoa/Cocoa.h>
/*
@finalfantasia
finalfantasia / fixing_text_anti_aliasing_in_fedora.md
Last active March 20, 2024 22:53
Fixing Text Anti-aliasing in Fedora
  1. Add the RPMFusion repositories (both free and non-free) to the YUM repository directory (/etc/yum.repos.d/):
sudo dnf localinstall --nogpgcheck http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm http://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$(rpm -E %fedora).noarch.rpm
  1. Install the patched version of FreeType with subpixel rendering enabled:
sudo dnf install -y freetype-freeworld
@ryancdotorg
ryancdotorg / rsabd.py
Last active March 13, 2023 15:57
backdoored rsa key generation
#!/usr/bin/env python
import sys
import gmpy
import curve25519
from struct import pack
from hashlib import sha256
from binascii import hexlify, unhexlify
@preble
preble / WeakSet.swift
Last active July 13, 2023 06:45
A pure Swift weak set.
//
// Created by Adam Preble on 2/19/15.
//
/// Weak, unordered collection of objects.
public struct WeakSet<T where T: AnyObject, T: Hashable> {
typealias Element = T
/// Maps Element hashValues to arrays of Entry objects.
/// Invalid Entry instances are culled as a side effect of add() and remove()
@jordanekay
jordanekay / Dictionary.swift
Last active February 11, 2021 16:01
Mapping dictionaries in Swift
extension Dictionary {
public func map<T: Hashable, U>(@noescape transform: (Key, Value) -> (T, U)) -> [T: U] {
var result: [T: U] = [:]
for (key, value) in self {
let (transformedKey, transformedValue) = transform(key, value)
result[transformedKey] = transformedValue
}
return result
}
@Bogidon
Bogidon / AnimatedGrowingTextView.swift
Last active January 11, 2023 07:04
A short and understandable UITextView subclass that grows with its text. Animatable. Updates intrinsicContentSize. If you don't need animations check out https://gist.github.com/Bogidon/cc0c9ae6f041413c39fb0ff146ad1b18
//
// AnimatedGrowingTextView.swift
// https://gist.github.com/Bogidon/632e265b784ef978d5d8c0b86858c2ee
//
// Created by Bogdan Vitoc on 02/15/2017.
// Distributed under the MIT License: https://gist.github.com/Bogidon/632e265b784ef978d5d8c0b86858c2ee#file-license
//
import UIKit
@Bogidon
Bogidon / GrowingTextView.swift
Last active February 15, 2021 20:06
A UITextView subclass that grows with its text but allows scrolling according to AutoLayout constraints. Updates intrinsicContentSize. For an animatable version see https://gist.github.com/Bogidon/632e265b784ef978d5d8c0b86858c2ee
//
// GrowingTextView.swift
// https://gist.github.com/Bogidon/cc0c9ae6f041413c39fb0ff146ad1b18
//
// Created by Bogdan Vitoc on 02/22/2017.
// Distributed under the MIT License: https://gist.github.com/Bogidon/cc0c9ae6f041413c39fb0ff146ad1b18#file-license
//
import UIKit

Value Subtypes and Generalized Enums, a manifesto

The goal of this document is to provide a comprehensive view of what value subtyping might look like in Swift and demonstrate how generalized enums play a significant role in this future.

Note: All syntax used in this document that is not currently valid Swift syntax is only intended to serve the purpose of demonstrating ideas and to serve as a point of reference for future proposals. The intent is not to propose that this exact syntax be used.

Acknowledgement: some of the ideas in this document have been inspired by Niko Matsakis' blog post exploring similar ideas in the context of Rust: http://smallcultfollowing.com/babysteps/blog/2015/08/20/virtual-structs-part-3-bringing-enums-and-structs-together/

Definition