Skip to content

Instantly share code, notes, and snippets.

View akey7's full-sized avatar

Alicia Key akey7

View GitHub Profile
@akey7
akey7 / one-animation.m
Created April 22, 2014 19:46
Block based animation that only happens once
@property (nonatomic) dispatch_once_t oneAnimation;
// ... other code here
- (void)testAnimation
{
dispatch_once(&self->_oneAnimation, ^{
const CGFloat WidthHeight = 50.0;
UIView *floaterView = [UIView new];
floaterView.backgroundColor = [UIColor redColor];
- (void)listAvailableFonts
{
for (NSString *s in [UIFont familyNames]) {
NSLog(@"%@: %@", s, [UIFont fontNamesForFamilyName:s]);
}
}
@akey7
akey7 / gist:f3c631450c10cb010fef
Created June 12, 2014 20:52
Cheat sheet for implementing an image picker
// Must implement UIImagePickerControllerDelegate
- (IBAction)selectImageTapped:(UIBarButtonItem *)sender
{
[self displayImageSelector];
}
- (void)displayImageSelector
{
@akey7
akey7 / minMaxSumMean.scala
Created June 17, 2014 19:04
Get the min, max, and mean of a Vector[Int]
def minMaxSumMean(v: Vector[Int]) = {
val min = (Integer.MAX_VALUE /: v) { (large, elem) => Math.min(large, elem) }
val max = (Integer.MIN_VALUE /: v) { (large, elem) => Math.max(large, elem) }
val sum = (0 /: v) { (carryover, elem) => carryover + elem }
val mean = sum / v.length
(min, max, sum, mean)
}
val all = minMaxSumMean(Vector(4,5,6))
println("ALL> " + all)
@akey7
akey7 / operationAfterFoldLeft.scala
Created June 17, 2014 20:02
Inject a function across a Vector[Double] and do another operation after that
// Takes two functions as arguments, and returns another function.
//
// The resulting function takes a single Vector[Double] argument and first
// performs an inject operation and the first function then takes the result of the inject
// and uses the second function to creates the final result.
//
// foldLeftOperation: the function used in the inject operation
//
// afterFoldLeftOperation: the operation run after the injection.
//
@akey7
akey7 / pi-scalatra.bash
Created June 22, 2014 21:31
How to get Scalatra to run on a Raspberry Pi in limited RAM
# For JVM and Scala
export PATH=$PATH:/usr/local/jdk/bin:/usr/local/scala/bin
export SCALA_HOME=/usr/local/scala
export JAVA_OPTS="-Xms300m -Xmx300m -XX:MaxPermSize=100m -XX:ReservedCodeCacheSize=4m -Djava.awt.headless=true"
@akey7
akey7 / gist:8e5737672425bde0a593
Created July 1, 2014 16:42
How to blur a background.
@implementation BigViewController
- (void)viewDidLoad
{
[super viewDidLoad];
UIImage *grassImage = [UIImage imageNamed:@"Grass"];
UIImageView *grassImageView = [[UIImageView alloc] initWithImage:grassImage];
grassImageView.frame = self.view.bounds;
@akey7
akey7 / tiled-view-text
Created July 25, 2014 18:14
Core Text in tiled view.
//
// XNChartOfNuclidesView.m
// Xplore Nuclides
//
// Created by Alicia Key on 24/07/2014.
// Copyright (c) 2014 Alicia M. F. Key. All rights reserved.
//
//
// If this is a child of a scroll view, the size of this view has
// been tested to 9000x5000 on an iPad3
@akey7
akey7 / didDetermineStateForRegion
Created August 14, 2014 18:54
How to determine state for a region
- (void)locationManager:(CLLocationManager *)manager didDetermineState:(CLRegionState)state forRegion:(CLRegion *)region
{
NSString *stateString = @"";
switch (state) {
case CLRegionStateUnknown:
stateString = @"CLRegionStateUnknown";
break;
case CLRegionStateInside:
@akey7
akey7 / gist:e78b3998f33f7e9b230c
Created August 27, 2014 15:22
IP addresses for iOS and OSX
#import "XXX.h"
#import <sys/types.h>
#import <sys/socket.h>
#import <arpa/inet.h>
#import <ifaddrs.h>
NSString * const XXXAddress = @"XXXAddress";
NSString * const XXXAddressFamily = @"XXXAddressFamily";