Skip to content

Instantly share code, notes, and snippets.

View noahmiller's full-sized avatar

Noah Harrison noahmiller

  • Art & Logic
  • Montpelier, VT
View GitHub Profile
@noahmiller
noahmiller / EncryptionTransformer.h
Created July 25, 2012 02:56
EncryptionTransformer class
@interface EncryptionTransformer : NSValueTransformer
{}
/**
* Returns the key used for encrypting / decrypting values during transformation.
*/
- (NSString*)key;
@end
@noahmiller
noahmiller / StringEncryptionTransformer.h
Created July 25, 2012 03:18
StringEncryptionTransformer class
@interface StringEncryptionTransformer : EncryptionTransformer
{}
@noahmiller
noahmiller / EncryptionTransformer.m
Created July 25, 2012 05:38
EncryptionTransformer class with initialization vector
- (id)transformedValue:(NSData*)data
{
...
// Use another NSData category method (left as an exercise
// to the reader) to randomly generate the IV data
NSData* iv = [NSData randomDataOfLength:32];
data = [data dataAES256EncryptedWithKey:[self key] Iv:iv];
#pragma mark - State preservation
- (void)encodeRestorableStateWithCoder:(NSCoder*)coder
{
[super encodeRestorableStateWithCoder:coder];
// Preserve the managed objects
NSData* data =
[AManagedObjectArchiver ArchiveDataFromBlock:^(AManagedObjectArchiver* archiver)
{
@interface ACodableManagedObject : NSObject <NSCoding>
@property (nonatomic, strong) NSURL* url;
+ (id)ObjectWithManagedObject:(NSManagedObject*)obj;
@end
@implementation ACodableManagedObject
+ (id)ObjectWithManagedObject:(NSManagedObject*)obj
{
@noahmiller
noahmiller / Vagrantfile
Created September 13, 2013 15:56
Example Vagrantfile
# -*- mode: ruby -*-
# Vagrant file for the lolcats website
Vagrant.configure("2") do |config|
config.vm.hostname = "lolcats"
# Every Vagrant virtual environment requires a box to build off of.
config.vm.box = "precise64"
# The url from where the 'config.vm.box' box will be fetched if it
@noahmiller
noahmiller / OrderedCollectionSpec
Last active March 5, 2016 21:55
An example of using shared Specta behavior
SharedExamplesBegin(OrderedCollectionBehavior)
// A set of shared test cases are defined here under the key name
// "an ordered collection".
//
// The dictionary param is the only means of providing data from
// the shared examples caller to the set of shared examples.
// In this case pass in the collection class to be tested.
sharedExamplesFor(@"an ordered collection", ^(NSDictionary* data)
{
@noahmiller
noahmiller / gulp-scsslint-simple.js
Created May 13, 2014 19:32
Barebones SCSS-Lint plugin for gulp
// child_process is used to spawn the scss-lint binary
var child_process = require('child_process');
// map-stream is used to create a stream that runs an async function
var map = require('map-stream');
// gulp-util is used to created well-formed plugin errors
var gutil = require('gulp-util');
// The main function for the plugin – what the user calls – should return
// a stream.
var scssLintPlugin = function() {
@noahmiller
noahmiller / gulpfile-karma.js
Created May 14, 2014 17:02
Sample gulpfile calling Karma
var gulp = require('gulp');
var path = require('path');
var karma = require('karma').server;
/**
* Run the Karma server once with the given config file path.
*/
function runKarma(configFile, cb) {
karma.start({
configFile: path.resolve(configFile),
@noahmiller
noahmiller / gulpfile-error-handling.js
Created May 15, 2014 16:54
Example error handling in a gulpfile
var gulp = require('gulp');
var gutil = require('gulp-util');
var jshint = require('gulp-jshint');
// Command line option:
// --fatal=[warning|error|off]
var fatalLevel = require('yargs').argv.fatal;
var ERROR_LEVELS = ['error', 'warning'];