Skip to content

Instantly share code, notes, and snippets.

@simme
simme / diff.swift
Created August 10, 2016 13:43
Utility for diffing two arrays of arrays.
enum DiffModification<T: Equatable> {
case inserted(position: NSIndexPath, value: T)
case deleted(position: NSIndexPath, value: T)
case moved(position: NSIndexPath, newPosition: NSIndexPath, value: T)
}
extension DiffModification: CustomDebugStringConvertible {
var debugDescription: String {
switch self {
case .inserted(let position, let value):
@simme
simme / DateRange.swift
Last active July 20, 2016 10:50
A struct representing a range of dates.
/// License: MIT
import Foundation
/**
A struct representing a range of dates.
*/
public struct DateRange {
// MARK: Properties
@simme
simme / UINavigationBar+Looks.swift
Last active August 15, 2017 07:51
UINavigationBar extension for setting and applying "looks" in one go.
//
// UINavigationbar+Looks.swift
//
// License: MIT
//
import UIKit
/**
Stores information about navigation bar looks.
/**
A default implmentation that provides a few convenience methods for starting and stopping coordinators.
*/
extension Coordinator {
// Default implementation, so that we don't have to do this for all coordinators.
func startChild<T: NSObject where T: Coordinator>(coordinator coordinator: T, withIdentifier identifier: String, callback: CoordinatorCallback?) -> T {
childCoordinators[identifier] = coordinator
coordinator.start(withCallback: callback)
return coordinator
//: Playground - noun: a place where people can play
import UIKit
/// Just an object specific to my use case.
class AppContext { }
/// Save some typing
typealias CoordinatorCallback = (Coordinator) -> Void
@simme
simme / String+Typography.swift
Created May 20, 2016 07:28
Swift String extension to get an orphan-less version of the string.
//
// String+Typography.swift
// FilibabaKit
//
// Created by Simon Ljungberg on 09/05/16.
// Copyright © 2016 Filibaba. All rights reserved.
//
import Foundation
@simme
simme / gist:084b35d8353a06e24bc4
Created June 21, 2015 08:53
basecamp estimater
var minutes = $('.todo .content a').map(function (index, itm) {
var pattern = /^\[(\d+)\]/;
var matches = $(itm).text().match(pattern);
return matches ? parseInt(matches[1], 10) : 0;
});
var total = 0;
for (var i = minutes.length - 1; i >= 0; i--) { total += minutes[i]; }
console.log(total/60);
@simme
simme / gist:e2171e7c7a717d3844c5
Created June 1, 2015 06:13
Responsive images wordpress
function lpg_get_attachment( $attachment_id ) {
$attachment = get_post( $attachment_id );
return array(
'alt' => get_post_meta( $attachment->ID, '_wp_attachment_image_alt', true ),
'caption' => $attachment->post_excerpt,
'description' => $attachment->post_content,
'href' => get_permalink( $attachment->ID ),
'src' => $attachment->guid,
'title' => $attachment->post_title
);
function test() {
for (var i=0;i < 5;i++) {
console.log('orig: '+ i);
setTimeout((function (x) {
return function () {
console.log('cb: '+ x);
}
}(i)), 100);
}
(function () {
var Foobar = function MyModule() { /* ... */ };
var hasDefine = typeof define === 'function' && define.amd;
var hasExport = typeof exports !== 'undefined';
if (hasDefine) {
define('Foobar', Foobar);
}