Skip to content

Instantly share code, notes, and snippets.

View designatednerd's full-sized avatar

Ellen Shapiro designatednerd

View GitHub Profile

Keybase proof

I hereby claim:

  • I am designatednerd on github.
  • I am designatednerd (https://keybase.io/designatednerd) on keybase.
  • I have a public key whose fingerprint is 636E F994 2D18 33BB 86A3 97C4 F94C 162F 31C3 B0E1

To claim this, I am signing this object:

@designatednerd
designatednerd / Constants.h
Last active August 29, 2015 14:06
Struct Constants Example
FOUNDATION_EXPORT const struct DNSUserDefaults {
__unsafe_unretained NSString *hasRunBefore;
__unsafe_unretained NSString *hasMadeInAppPurchase;
} DNSUserDefaults;
@designatednerd
designatednerd / RangeDoesNotWorkThisWay
Last active August 29, 2015 14:09
Welp, I'm an idiot.
- (BOOL)doesStringContainSpecificString:(NSString *)passedInString
{
NSRange rangeOfString = [passedInString rangeOfString:@"a string"];
if (rangeOfString.location != NSNotFound) {
//String was found, do stuff
return YES;
} //else string was not found, don't bother
return NO;
}
@designatednerd
designatednerd / BadTest.m
Last active August 29, 2015 14:13
How Not To Write A Test
/*
The most horrendous test case I've ever found in client code, and a great example
of why "Your code must have X% test coverage" is a dangerous way to evaluate
whether something is properly tested.
Class prefixes have been changed to CLT (for Client) to protect the guilty. All
else is from the original.
*/
- (void)testShouldLogResponseOnSuccess
package com.[my package].rule;
import org.junit.Assume;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
import timber.log.Timber;
import java.lang.annotation.*;
import java.lang.reflect.Modifier;
/*
Some playing around with a playground in Swift to try and figure out how to make Funcitonal
stuff more readable. Initial example from:
http://www.raywenderlich.com/82599/swift-functional-programming-tutorial
*/
import Foundation
let words = [ "Cat", "Chicken", "fish", "Dog", "Mouse", "Guinea Pig", "monkey"]
@designatednerd
designatednerd / rdar-20211159.playground
Last active August 29, 2015 14:17
NSDecimalNumber lulz
/*
Fun with NSNumber to integer and unsigned integer conversions! This
bit someone trying to use key-value coding to get the average of a
given number out of an array of items with an NSUInteger property.
The NSNumber which came out of the @avg.value KVC method was of value
588.33333333333333333333333333333333333. The person then tried to access
this value by calling both average.integerValue and
average.unsignedIntegerValue.
/**
How to get a method which takes any string enumeration in Swift 2.1.
Actually figured out by Carl Hill-Popper, documented by me.
*/
import UIKit
// 1) Make you some string enums.
@designatednerd
designatednerd / build.gradle
Created December 16, 2015 21:31
Using the number of commits in the HEAD to auto-increment your android version count.
//Counts the number of commits on the HEAD of the repo.
def headCommitCount() {
def cmd = "git rev-list HEAD --count"
return cmd.execute().text.toInteger()
}
android {
defaultConfig {
versionCode headCommitCount() //Auto-increment the version based on how many commits have occurred.
versionName "x.x.x (" + versionCode + ")"
@designatednerd
designatednerd / CountableIntEnum.swift
Last active August 3, 2018 06:14
Swift 3 Helpers for getting all the cases of a given enum [Swift 3]
import Foundation
/**
A swift protocol to make any Int enum able to count its cases.
Super-useful for making enums to help you deal with sections in tableviews without having to maintain a case for the count of the enum.
Originally developed by Logan Wright for Swift 2.0 here:
https://gist.github.com/LoganWright/c8a26b1faf538e40f747