Skip to content

Instantly share code, notes, and snippets.

/*
* Block Safety
*
* We sometimes accidentally invoke a nil block...this protects against it.
*
*/
#define SAFE_CALL(b, ...) \
if(b) b(__VA_ARGS__);
/*
* Strongify / Weakify shortcuts
*
* These declare and instantiate weak and strong variables
* statically so it's easier to write. It's a nice middle-ground
* when compared to other solutions in the wild.
*
*/
#define WEAKIFY(aSelf) __weak typeof(aSelf) weakSelf = aSelf;
#define STRONGIFY(aSelf) __strong typeof(aSelf) strongSelf = aSelf;
/**
* Lazy Getter
*
* Helps reduce silly errors when writing lazy getters.
*/
#define ADD_LAZY_GETTER(type, name, initialValueBlock) \
-(type)name \
{ \
if (!_##name) { \
_##name = initialValueBlock(); \
#
# This is my preferred .bash_profile
#
# It has more context around git repositories, coloring, etc. Sections of this .bash_profile
# were certainly inspired by others' files (especially the git aliases).
#
export GITAWAREPROMPT=~/.bash/git-aware-prompt
source "${GITAWAREPROMPT}/main.sh"
@vinnybad
vinnybad / Fastfile
Created June 3, 2016 19:16
Shows one way to fail a build in fastlane when code coverage does not meet a minimum threshold.
#
# Shows one way to fail a build in fastlane when code
# coverage does not meet a minimum threshold.
#
# there are other ways to check the coverage of the commit,
# but I couldn't find an existing tool that makes this easier
# that will run on bitrise. I would have normally used diff-cover
# to do this because you can compare branches and only check the diffs.
# Unfortunately that means you have to find a way to install it on bitrise
# at the time of writing and that can be tricky.
/**
* Lazily initializes an object. Mainly used for reducing boilerplate code.
*/
#define DEFINE_LAZY_GETTER(type, name, initialValueBlock) \
- (type)name { \
if (! _ ## name) { \
_ ## name = initialValueBlock(); \
} \
return _ ## name; \
}
@vinnybad
vinnybad / mergegenstrings.py
Created January 21, 2016 19:24 — forked from yoichitgy/mergegenstrings.py
A script to generate .strings file for .swift, .m, .storyboard and .xib files by genstrings and ibtool commands, and merge them with existing translations.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Localize.py - Incremental localization on XCode projects
# João Moreno 2009
# http://joaomoreno.com/
# Modified by Steve Streeting 2010 http://www.stevestreeting.com
# Changes
# - Use .strings files encoded as UTF-8
@vinnybad
vinnybad / genAllStrings.m
Last active November 6, 2015 03:09
Generate .strings files for a particular language (overwrites existing strings file)
#!/bin/bash
# find all .m files and pump it through genstrings, outputting it to en.lproj/Localizable.strings
find . -name '*.m' | xargs genstrings -o en.lproj
@vinnybad
vinnybad / BJMWebService.m
Last active October 3, 2015 20:26
Download a file using AFNetworking
/*
* Downloading files using AFNetworking is not a 1-step process, but it's still pretty easy.
*
* NOTE: If you're downloading a file from S3, make sure to set the proper Content-Type. For example,
* a zip file should ideally have the content type of application/zip.
*
* Inspired by various sources online.
*/
#pragma mark - Downloading Files
@vinnybad
vinnybad / findAndZipFiles.sh
Created October 1, 2015 15:51
Finding all files of a particular type (e.g. all .strings files for iOS internalization) and adding them to a zip
#!/bin/bash
find . -name '*.strings' -print | egrep -v 'Pods' | zip source -@
# Break it down:
#
# Find all files with file name ending with .strings
# find . -name '*.strings' -print
#
# Search for all lines that don't have 'Pods' in it (the -v means invert)