Skip to content

Instantly share code, notes, and snippets.

View Jamonek's full-sized avatar
🏗️
Building.. Exploring.. Dreaming..

Jamone Kelly Jamonek

🏗️
Building.. Exploring.. Dreaming..
View GitHub Profile
@ItsJustMeChris
ItsJustMeChris / inline-assembly-mid-function-hooking-macos-unix.cpp
Created March 1, 2021 00:00
Code to perform a mid function hook using inline assembly on a unix / macos x86-64 system. GIST includes dummy program to test, offsets in main program should be valid when built.
#include <cstdio>
#include <iostream>
#include <sys/mman.h>
#include <mach/i386/kern_return.h>
#include <mach/mach_init.h>
#include <mach/mach_vm.h>
#include <mach/vm_region.h>
#include <mach/vm_types.h>
#include <unistd.h>
#include <mach/host_info.h>
@nicklockwood
nicklockwood / Color.swift
Created January 19, 2021 23:49
Getting the Display P3 values back out of a UIColor created with init(displayP3Red:green:blue:alpha:)
import UIKit
// Create color using P3 color space
let linearColor = UIColor(displayP3Red: 1, green: 0.5, blue: 0.2, alpha: 1)
do {
var r: CGFloat = 0, g: CGFloat = 0, b: CGFloat = 0, a: CGFloat = 0
linearColor.getRed(&r, green: &g, blue: &b, alpha: &a)
print(r, g, b, a) // 1.07, 0.46, 0.0, 1.0 - not the expected values
}
@iamstephenbrown
iamstephenbrown / UIColor+Luminosity.swift
Last active January 24, 2022 21:37
UIColor extension to adjust the luminosity of a colour
import Foundation
import UIKit
// Fantastic explanation of how it works
// http://www.niwa.nu/2013/05/math-behind-colorspace-conversions-rgb-hsl/
fileprivate extension CGFloat {
/// clamp the supplied value between a min and max
/// - Parameter min: The min value
/// - Parameter max: The max value
func clamp(min: CGFloat, max: CGFloat) -> CGFloat {
@RuiAAPeres
RuiAAPeres / SwiftUIBindsWithReactiveSwift.swift
Last active December 12, 2023 09:30
Couple of methods to bridge ReactiveSwift with SwiftUI
import Combine
import ReactiveSwift
import SwiftUI
class AnySubscription: Subscription {
private let cancelable: Cancellable
init(cancelable: Cancellable) {
self.cancelable = cancelable
@tad-iizuka
tad-iizuka / emojiToImage
Created October 20, 2017 03:14
Emoji convert to UIImage. Swift 4
func emojiToImage(text: String, size: CGFloat) -> UIImage {
let outputImageSize = CGSize.init(width: size, height: size)
let baseSize = text.boundingRect(with: CGSize(width: 2048, height: 2048),
options: .usesLineFragmentOrigin,
attributes: [.font: UIFont.systemFont(ofSize: size / 2)], context: nil).size
let fontSize = outputImageSize.width / max(baseSize.width, baseSize.height) * (outputImageSize.width / 2)
let font = UIFont.systemFont(ofSize: fontSize)
let textSize = text.boundingRect(with: CGSize(width: outputImageSize.width, height: outputImageSize.height),
options: .usesLineFragmentOrigin,
@steipete
steipete / ios-xcode-device-support.sh
Last active July 13, 2024 21:09
Using iOS 15 devices with Xcode 12.5 (instead of Xcode 13)
# The trick is to link the DeviceSupport folder from the beta to the stable version.
# sudo needed if you run the Mac App Store version. Always download the dmg instead... you'll thank me later :)
# Support iOS 15 devices (Xcode 13.0) with Xcode 12.5:
sudo ln -s /Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport/15.0 /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport
# Then restart Xcode and reconnect your devices. You will need to do that for every beta of future iOS versions
# (A similar approach works for older versions too, just change the version number after DeviceSupport)
@JaviSoto
JaviSoto / NibInstantiable.swift
Last active April 14, 2020 11:55
RSwift Fabric Extensions
import UIKit
import Rswift
struct NibResource: NibResourceType {
let name: String
let bundle: NSBundle
init(name: String, bundle: NSBundle = NSBundle.mainBundle()) {
self.name = name
self.bundle = bundle
@rauchg
rauchg / README.md
Last active January 6, 2024 07:19
require-from-twitter
import Darwin.C
import Venice
struct SubProcess {
let path: String
let arguments: [String]
func run(sync sync: Bool = true) -> Int? {
@papertigers
papertigers / dtrace fun
Created December 3, 2015 22:26
Swift on lx with dtrace!
root@3e4601c0-00af-4d93-c8b2-f4584487aa7c:~# dtrace -ln pid18959:main::entry
ID PROVIDER MODULE FUNCTION NAME
14543 pid18959 main main entry
14693 pid18959 main _TF4main6findMeFT_Si entry
14694 pid18959 main _TF4main1bFT_Si entry
14695 pid18959 main __libc_csu_init entry
14696 pid18959 main __libc_csu_fini entry
root@3e4601c0-00af-4d93-c8b2-f4584487aa7c:~# dtrace -ln pid18959:main::entry | swift-demangle
ID PROVIDER MODULE FUNCTION NAME