Skip to content

Instantly share code, notes, and snippets.

View atnan's full-sized avatar

Nathan de Vries atnan

View GitHub Profile
@atnan
atnan / gist:997780
Created May 29, 2011 13:28
Fading view transition...
[CATransaction begin];
CATransition *transition = [CATransition animation];
transition.type = kCATransitionFade;
transition.duration = animated ? 0.5f : 0.0f;
transition.fillMode = kCAFillModeForwards;
transition.removedOnCompletion = YES;
[[UIApplication sharedApplication].keyWindow.layer addAnimation:transition forKey:@"transition"];
[[UIApplication sharedApplication] beginIgnoringInteractionEvents];
@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"];
@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) {
United States 143441
Argentina 143505
Australia 143460
Belgium 143446
Brazil 143503
Canada 143455
Chile 143483
China 143465
Colombia 143501
Costa Rica 143495
#!/bin/bash
cat .gitignore | egrep -v "^#|^$" | while read line; do
if [ -n "$line" ]; then
OLD_IFS=$IFS; IFS=""
for ignored_file in $( git ls-files "$line" ); do
git rm --cached "$ignored_file"
done
IFS=$OLD_IFS
fi
#!/usr/bin/env bash
# Get a sample dictionary here:
# http://labs.kitiyo.com/files/t9.dic
umask 077
NUMN=/tmp/numn.$$
trap "exit 1" HUP INT PIPE QUIT TERM
trap "rm -f $DICTN $NUMN" EXIT
@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`