Skip to content

Instantly share code, notes, and snippets.

View atnan's full-sized avatar

Nathan de Vries atnan

View GitHub Profile
@atnan
atnan / spring-utils.js
Created October 13, 2018 15:13
Functions to convert spring parameters to and from mass/stiffness/damping and damping ratio/frequency response.
function convertDampingRatioResponseToStiffnessDamping(dampingRatio, response) {
let mass = 1
let angularFrequency = (2 * Math.PI) / response
let stiffness = Math.pow(angularFrequency, 2) * mass
let damping = dampingRatio * (2 * Math.sqrt(stiffness * mass))
return { mass: mass, stiffness: stiffness, damping: damping }
}
function convertMassStiffnessDampingToDampingRatioResponse(mass, stiffness, damping) {
@atnan
atnan / gist:5069334
Created March 2, 2013 02:02
Is a "café" a "café", and are they the same length?
// $ clang -framework Foundation -o unicode-is-hard-lets-go-shopping unicode-is-hard-lets-go-shopping.m && ./unicode-is-hard-lets-go-shopping
// 2013-03-01 17:56:56.132 unicode-is-hard-lets-go-shopping[3390:707] string1='café', string2='café', string1.length=4, string2.length=5, [string1 isEqualToString:string2]=NO
// 2013-03-01 17:56:56.134 unicode-is-hard-lets-go-shopping[3390:707] precomposedString1='café', precomposedString2='café', precomposedString1.length=4, precomposedString2.length=4, [precomposedString1 isEqualToString:precomposedString2]=YES
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[]) {
@autoreleasepool {
NSString *string1 = [NSString stringWithUTF8String:"\x63\x61\x66\xC3\xA9\x00"];
NSString *string2 = [NSString stringWithUTF8String:"\x63\x61\x66\x65\xCC\x81\x00"];
@implementation CSAccountTests
- (void)testGetAPIKeyWithValidCredentials {
[self testAsync:^{
CSAPI* validCredentialsAPI;
validCredentialsAPI = [[[CSAPI alloc] initWithSiteURL:kCSTestsValidSiteURL
username:kCSTestsValidUsername
password:kCSTestsValidPassword] autorelease];
[validCredentialsAPI getAPIKey:^(NSString* APIKey){
@atnan
atnan / post-checkout
Created March 14, 2012 05:28
Git post-checkout hook demoing how one might achieve branch-specific Xcode breakpoints
#!/usr/bin/env ruby
previous_sha, current_sha, branch_checkout, _ = *ARGV
exit if branch_checkout == 0 || previous_sha == current_sha
begin
require 'pathname'
require 'fileutils'
<style type="text/css">
#banner img { width: 240px; height: 56px; }
#banner img.retina { display: none; }
@media only screen and (-webkit-min-device-pixel-ratio: 2), only screen and (min-device-pixel-ratio: 2) {
#banner img.non-retina { display: none; }
#banner img.retina { display: block; }
}
</style>
/**
Prevent Xcode 4.1 from using 100% CPU due to a bug while attempting to
connect to a remote iOS device.
# 1. Compile the patch
$ gcc -lobjc -fobjc-gc -framework Foundation -bundle -o _patch NDVXcodeRemoteDevicePatch.m
# 2. Find the PID of Xcode
$ XcodePID=`pidof Xcode`
$ cat /var/folders/p2/ks11y6qj4kb2dyyl7n5rydcm0000gn/T/com.apple.mail.drag/\[cocoaheadsau\]\ CocoaHeads\ Sydney\ August\ –\ For\ Real\ this\ time\! | tr -dc '!' | wc -c
24
/Developer/usr/include/_locale.h
/Developer/usr/include/_structs.h
/Developer/usr/include/_types.h
/Developer/usr/include/_wctype.h
/Developer/usr/include/_xlocale.h
/Developer/usr/include/aio.h
/Developer/usr/include/alloca.h
/Developer/usr/include/apache2
/Developer/usr/include/apache2/ap_compat.h
/Developer/usr/include/apache2/ap_config.h
@atnan
atnan / lightweight_toolchain.sh
Created July 27, 2011 07:06
Install a minimal development toolchain
#!/bin/env bash
packages=(
DevSDK.pkg
DeveloperToolsCLI.pkg
DeveloperToolsSystemSupport.pkg
gcc4.2.pkg
llvm-gcc4.2.pkg
clang.pkg
)
@atnan
atnan / gist:1100998
Created July 23, 2011 04:03
Creating arbitrarily-colored icons from a black-with-alpha master image (iOS)
// Usage example:
// input image: http://f.cl.ly/items/3v0S3w2B3N0p3e0I082d/Image%202011.07.22%2011:29:25%20PM.png
//
// UIImage *buttonImage = [UIImage ipMaskedImageNamed:@"UIButtonBarAction.png" color:[UIColor redColor]];
// .h
@interface UIImage (IPImageUtils)
+ (UIImage *)ipMaskedImageNamed:(NSString *)name color:(UIColor *)color;
@end