Skip to content

Instantly share code, notes, and snippets.

View jverkoey's full-sized avatar

Jeff jverkoey

View GitHub Profile
@jverkoey
jverkoey / Figma analytics API.md
Last active March 29, 2024 18:49
Figma's undocumented analytics API endpoints

Notice

This is an undocumented API. It may break at any time. Contributions welcome; please share in the comments and I will update the gist accordingly.

Authentication

Each request must be passed a valid authentication cookie. The cookie takes the following form and can be pulled from any authenticated request made in the browser:

@jverkoey
jverkoey / underdampedoscillations.m
Last active September 11, 2022 18:53
Underdamped Harmonic Oscillations
// NOTE: I've decided to use a much simpler approach to this as the complexity was starting to consume
// too much energy. Leaving this here for historical context.
// Building an Underdamped Harmonic Oscillator
//
// All equations derived from this wonderful paper by David Morin:
// http://www.people.fas.harvard.edu/~djmorin/waves/oscillations.pdf
//
// Note on mass: In order to simplify our calculations I'll assume that mass (m) is always 1. Where
// m would otherwise be written I've folded it into the expression.
@jverkoey
jverkoey / ios7springs.m
Created April 9, 2014 13:59
iOS 7 spring damping and stiffness calculation
@interface NSObject ()
- (void)generateSpringPropertiesForDuration:(float)arg1 damping:(float)arg2 velocity:(float)arg3;
- (id)_defaultAnimationForKey:(id)arg1;
@end
// This object calculates the damping and stiffness coefficients, given a damping value (0...1], a velocity, and a duration.
id obj = [[NSClassFromString(@"UIViewSpringAnimationState") alloc] init];
[obj generateSpringPropertiesForDuration:10 damping:0.5 velocity:10];
@jverkoey
jverkoey / rubberBand.swift
Created November 30, 2016 06:55
Rubber banding in swift
public func rubberBand(value: CGFloat, min: CGFloat, max: CGFloat, bandLength: CGFloat) -> CGFloat {
if value >= min && value <= max {
// While we're within range we don't rubber band the value.
return value
}
if bandLength <= 0 {
// The rubber band doesn't exist, return the minimum value so that we stay put.
return min
@jverkoey
jverkoey / UIFont+CustomizedDynamicType.m
Created April 14, 2021 01:07
Dynamic Type system fonts with custom point sizes, weight, and italics
static const CGFloat kFontWeightEpsilon = FLT_EPSILON;
@implementation UIFont (CustomizedDynamicType)
+ (nonnull UIFont *)preferredFontWithDefaultSize:(CGFloat)size
textStyle:(nonnull UIFontTextStyle)textStyle {
return [self preferredFontWithDefaultSize:size
textStyle:textStyle
fontWeight:UIFontWeightRegular
italic:NO];
@jverkoey
jverkoey / MIDIPacketList+SequenceType.swift
Last active November 18, 2020 14:46
Enumerating a MIDIPacketList in Swift 2.
// Blogged at http://design.featherless.software/enumerate-midipacketlist-in-swift-part-1/
// and http://design.featherless.software/enumerate-midipacketlist-in-swift-part-2/
extension MIDIPacketList: SequenceType {
public func generate() -> AnyGenerator<MIDIPacket> {
var iterator: MIDIPacket?
var nextIndex: UInt32 = 0
return anyGenerator {
if nextIndex++ >= self.numPackets { return nil }
if iterator != nil {
@jverkoey
jverkoey / UIView Layout
Last active May 16, 2020 02:51
Layout + size calculations for iOS.
- (CGSize)sizeOfContentsWithSize:(CGSize)size
shouldLayout:(BOOL)shouldLayout {
// Calculate frames.
if (shouldLayout) {
// Update frames.
}
return // size
}
@jverkoey
jverkoey / machine.sh
Last active February 7, 2019 01:04
Personal machine configuration
## One-time setup
# Deletes references to remote branches during git fetch
git config --global fetch.prune true
## .bashrc
# Pushes the local branch to origin and makes the local branch track the remote
gpush() {
git push origin $(git rev-parse --abbrev-ref HEAD) -u
@jverkoey
jverkoey / Data+xored.swift
Created February 6, 2019 18:33
Data+xored.swift
import Foundation
extension Data {
/**
Returns the result of xor'ing self with the given Data.
*/
public func xored(with rhs: Data) -> Data {
return Data(zip(self, rhs).map { $0 ^ $1 })
}
}
@jverkoey
jverkoey / Tuple+Generator.swift
Last active February 3, 2018 22:59
Tuple enumeration
/** The returned generator will enumerate each value of the provided tuple. */
func generatorForTuple(tuple: Any) -> AnyGenerator<Any> {
return anyGenerator(Mirror(reflecting: tuple).children.lazy.map { $0.value }.generate())
}
// Blogged at http://design.featherless.software/enumerating-tuple-values-swift/