Skip to content

Instantly share code, notes, and snippets.

@jmcd
jmcd / Dirty.cs
Last active August 29, 2015 14:14
using System;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
namespace DIrtyWars
{
[TestFixture]
public class TestFixture
{
@jmcd
jmcd / v1.cs
Last active August 29, 2015 14:22
public class Counter
{
private readonly string directoryPath;
private int count = 0;
private static readonly object lockable = new object();
public const string AggregatedCountFilename = "agg_count.txt";
public const string PendingFileExt = "pnd";
@jmcd
jmcd / split.swift
Created June 18, 2015 07:05
Master Detail with a UISplitViewController without StoryBoards
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
let viewController = SplitVc()
@jmcd
jmcd / BcdCoderTests.java
Last active August 29, 2015 14:26
Simple BCD coder
public class BcdCoderTests extends InstrumentationTestCase {
private int[][] decimalAndBcd = new int[][]{
{0, 0},
{1, 1},
{2, 2},
{3, 3},
{4, 4},
{5, 5},
{6, 6},
@jmcd
jmcd / L.java
Last active August 29, 2015 14:26
Android Log Wrapper to: [1] automatically (and probably expensively) add class/method tracing to debug messages and [2] ability to hack in loggint to other places (e.g. a dirty log to a TextView)
import android.util.Log;
import java.util.ArrayList;
import java.util.List;
public final class L {
public static final String MAGICAL_EXPENSIVE_AUTO_TAG = "JPgpKvpxrnB1zrs8WnGqVNTeK0NgMyY8SXnMEaXPnTY=";
public final static List<Println> PRINTLNS = new ArrayList<>();
private final static String[] NAMES_OF_EXCLUDED_CLASSES = new String[]{L.class.getName()};
import android.os.Handler;
import android.widget.TextView;
import timber.log.Timber;
public class TextViewTimberDebugTree extends Timber.DebugTree {
private final static long UNINITIALIZED_DEBUG_START_TIME = -1;
@jmcd
jmcd / Foo.swift
Last active February 22, 2018 07:10
MKMapView contested annotation location handling in Swift
import UIKit
import MapKit
/**
* Define behaviour of app through its lifetime
*/
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?

Keybase proof

I hereby claim:

  • I am jmcd on github.
  • I am jmcd (https://keybase.io/jmcd) on keybase.
  • I have a public key whose fingerprint is 93D9 D187 F8BE 3AF1 928C E85D A80D E3B5 5B06 3294

To claim this, I am signing this object:

@jmcd
jmcd / UIColorW3.swift
Created February 18, 2016 15:03
W3 colors
import UIKit
extension UIColor {
static func aliceblueW3Color() -> UIColor { return UIColor(red:240/255.0, green:248/255.0, blue:255/255.0, alpha:1.0); }
static func antiquewhiteW3Color() -> UIColor { return UIColor(red:250/255.0, green:235/255.0, blue:215/255.0, alpha:1.0); }
static func aquaW3Color() -> UIColor { return UIColor(red:0/255.0, green:255/255.0, blue:255/255.0, alpha:1.0); }
static func aquamarineW3Color() -> UIColor { return UIColor(red:127/255.0, green:255/255.0, blue:212/255.0, alpha:1.0); }
static func azureW3Color() -> UIColor { return UIColor(red:240/255.0, green:255/255.0, blue:255/255.0, alpha:1.0); }
static func beigeW3Color() -> UIColor { return UIColor(red:245/255.0, green:245/255.0, blue:220/255.0, alpha:1.0); }
static func bisqueW3Color() -> UIColor { return UIColor(red:255/255.0, green:228/255.0, blue:196/255.0, alpha:1.0); }
import Foundation
class ObjectWithCriticalResource: NSObject {
private let semaphore = dispatch_semaphore_create(1)
func doTask() {
guard dispatch_semaphore_wait(semaphore, DISPATCH_TIME_NOW) == 0 else {
// abort this call without doing the task