Skip to content

Instantly share code, notes, and snippets.

View samskiter's full-sized avatar

Sam Duke samskiter

View GitHub Profile
#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
@interface NSManagedObjectArchiver : NSObject
/*
* Takes a NSManagedObject and converts it to a NSData archive - it traverses all relationships ( including circular ) and archives it
*/
+ (NSData *)archivedDataWithRootObject:(NSManagedObject *)pObject;
@samskiter
samskiter / gist:ef9ce09fdd64f3c389fa
Created January 29, 2015 21:36
First cut of Google-http-client retrofitting
package uk.co.airsource.android.authtest;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
import retrofit.client.Client;
import retrofit.client.Header;
@samskiter
samskiter / gist:822c78795f46df2571f9
Last active August 29, 2015 14:14
Url encode requests from GSON objects :)
package uk.co.airsource.android.authtest;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import java.io.UnsupportedEncodingException;
import java.util.Map;
import java.util.Set;
import retrofit.converter.GsonConverter;
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="blah" >
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".HomeScreen"
android:label="@string/app_name" >
private void waitForResponse()
{
signal = new CountDownLatch(1);
try
{
assertTrue(signal.await(30, TimeUnit.SECONDS));
}
catch (InterruptedException e)
{
fail();
/*
* Copyright 2014 Chris Banes
*
* 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
@samskiter
samskiter / a
Created February 20, 2017 14:49
Broken preservesSuperviewLayoutMargins
a
@samskiter
samskiter / iOS11CompatibleLabel.swift
Last active April 1, 2021 15:59
A UILabel subclass that detects and attempts to fix intrinsicContentSize bugs in UILabel on iOS 11
import UIKit
/// A UILabel subclass that detects and attempts to fix intrinsicContentSize bugs in UILabel
class iOS11CompatibleLabel: UILabel {
override var intrinsicContentSize: CGSize {
// First attempt at a fix...
// All UILabels that misbehave have numberOfLines==0 and preferredMaxLayoutWidth=0
// but all UILabels that have these two properties as 0 do not necessarily misbehave
@samskiter
samskiter / Playground.swift
Created January 11, 2018 16:19
A playground demonstrating an issue with UILabel's intrinsic content size
//: Playground - noun: a place where people can play
import UIKit
import PlaygroundSupport
class LabelView: UIView {
let label = UILabel()
override init(frame: CGRect) {