Skip to content

Instantly share code, notes, and snippets.

View nuthatch's full-sized avatar

Stephen Ryner Jr. nuthatch

View GitHub Profile
@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,
extension UIColor {
/// Blends this color into the specified color, as if this color was overlaid on top of the other at the specified alpha, but our result will instead be opaque. For instance if self was green, and we passed white and 0.1 alpha/opacity, the result would be a light, faded green.
///
/// - Note: This process is also called alpha compositing.
func blend(intoColor otherColor: UIColor, atOpacity alpha: CGFloat) -> UIColor {
let sourceRGB = rgb
let otherRGB = otherColor.rgb
return UIColor(
red: (sourceRGB.red * alpha) + (otherRGB.red * (1.0 - alpha)),
// by dave
float[][] result;
float t, c;
float ease(float p) {
p = c01(p);
return 3*p*p - 2*p*p*p;
}
float ease(float p, float g) {
@moutend
moutend / README.md
Created March 27, 2021 01:10
[Swift] Equalizing Audio Signal with vDSP.Biquad

[Swift] Equalizing Audio Signal with vDSP.Biquad

This script reads /tmp/input.wav, applies the low-pass filter, and writes the modified signal as /tmp/output.wav.

To run, open Terminal.app and hit the following command:

$ swift main.swift
// by dave @beesandbombs
int[][] result;
float t, c;
float ease(float p) {
return 3*p*p - 2*p*p*p;
}
float ease(float p, float g) {
//
// Lightweight but powerful state machine.
//
// Usage:
// enum TrafficLight: State {
// case red, orange, green
// }
//
// var trafficLights = StateMachine<TrafficLight>(initialState: .red)
// trafficLights.addRoute(from: .red, to: .green)
@sohayb
sohayb / ArrayDeepCopy.swift
Last active October 13, 2023 07:58
Array deep copy in Swift
//Protocal that copyable class should conform
protocol Copying {
init(original: Self)
}
//Concrete class extension
extension Copying {
func copy() -> Self {
return Self.init(original: self)
}
@jspahrsummers
jspahrsummers / main.m
Created November 24, 2015 16:11
[NSThread isMainThread] is probably not what you want!
#import <Foundation/Foundation.h>
int main (int argc, const char **argv) {
@autoreleasepool {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
dispatch_sync(dispatch_get_main_queue(), ^{
NSLog(@"is main thread? %i", (int)[NSThread isMainThread]);
});
});
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
<dict>
<key>shortcut</key>
<string>:smile:</string>
<key>phrase</key>
<string>😄</string>
</dict>
@kristopherjohnson
kristopherjohnson / psg.sh
Last active September 14, 2015 20:50
Bash function to print process info for matching process name
# psg NAME
function psg {
processes=$(pgrep $@)
if [ -z "$processes" ]; then
echo "No matches"
else
ps $processes
fi
}