Skip to content

Instantly share code, notes, and snippets.

View jverkoey's full-sized avatar

Jeff jverkoey

View GitHub Profile
@jverkoey
jverkoey / NINetworkImageExample1.m
Created June 23, 2012 08:08
NINetworkImage Example 1
// A NINetworkImageView is a subclass of UIImageView. We can provide an image to the initializer
// and it will be displayed until the network image is loaded. In this example we won't set an
// initial image.
NINetworkImageView* imageView = [[NINetworkImageView alloc] initWithFrame:CGRectZero];
imageView.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleBottomMargin;
// We don't set an initial image so let's create a nice-looking "frame" effect on the view.
// This will show a translucent background with a highlighted border.
imageView.backgroundColor = [UIColor colorWithWhite:1 alpha:0.2];
imageView.layer.borderColor = [UIColor colorWithWhite:1 alpha:0.1].CGColor;
@jverkoey
jverkoey / NIInterappExample1.m
Created June 23, 2012 08:11
NIInterapp Example 1
[NIInterapp phone]; // Open the Phone app
[NIInterapp phoneWithNumber:@"555-0102"]; // Make a call
NIMailAppInvocation* invocation = [NIMailAppInvocation invocation];
invocation.recipient = @"jverkoey@gmail.com";
invocation.subject = @"Nimbus made me do it!";
[NIInterapp mailWithInvocation:invocation];
// Open Twitter with the composer and a given message.
[NIInterapp twitterWithMessage:@"I'm playing with the Nimbus sample apps! http://nimbuskit.info"];
@jverkoey
jverkoey / gist:2985830
Created June 25, 2012 01:03
Memory mapping in Objective-C
const char* cstr = [string UTF8String];
void* anon = mmap(0, sizeof(char) * (string.length + 1), PROT_WRITE|PROT_READ, MAP_ANON|MAP_PRIVATE, 0, 0);
if (anon == MAP_FAILED) {
NSLog(@"Failed to map memory.");
return;
}
strcpy(anon, cstr);
// How do I get a file descriptor for use here?
//
// Copyright 2013 Jeff Verkoeyen
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
@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 / thingsimport.rb
Last active January 26, 2018 15:59 — forked from byingyang/gist:181626
Update for Things 2.2's use of Projects instead of Areas.
# format:
# --------------
# date (mm/dd/yy)
# assignment
# assignment
# ...
#
# date
# assignment
# ...
@jverkoey
jverkoey / shouldAutorotate_nonintrusive.m
Last active August 29, 2015 13:57
Implementing UINavigationController/UITabBarController support for shouldAutorotate without subclassing or extending.
// Add this to your app delegate.
// Neither `UINavigationController` nor `UITabBarController` have the slightest decency to ask their
// visible view controller whether IT would like to rotate and just go on and do whatever the hell
// they please. This'll show 'em.
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
UIViewController* topViewController = window.rootViewController;
do {
// Navigate modal controllers.
@jverkoey
jverkoey / newtonmethod.m
Created March 21, 2014 21:08
Newton's Method
// A quick-and-dirty implementation of Newton's method. Could use some tlc. May loop infinitely for certain inputs.
typedef CGFloat (^CalculateEquationBlock)(CGFloat x);
CGFloat NIFindRoot(CalculateEquationBlock fn, CalculateEquationBlock fndx, CGFloat guess) {
CGFloat root = guess;
while (1) {
CGFloat newRoot = root - fn(root) / fndx(root);
if (fabsf(newRoot - root) < 0.001) { // or whatever epsilon you want
return newRoot;
@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.

Keybase proof

I hereby claim:

  • I am jverkoey on github.
  • I am featherless (https://keybase.io/featherless) on keybase.
  • I have a public key whose fingerprint is F94C 449D 7054 635A 03FE BE95 A674 C56D 3DD7 D554

To claim this, I am signing this object: