Skip to content

Instantly share code, notes, and snippets.

Simon Ljungberg simme

Block or report user

Report or block simme

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View ImportOperations.swift
private var didBeginImport = false // This is a hack until I've figured out why completion block runs twice..
private func createImportOperations(data: [String: AnyObject]) {
guard !didBeginImport else { return }
didBeginImport = true
if let ingredients = data["ingredients"] as? [[String: AnyObject]] {
ingredients.forEach {
let op = IngredientOperation(data: $0, repository: repo, state: state)
if let id = op.identifier {
state.ingredientOperations.updateValue(op, forKey: id)
@simme
simme / debounce-throttle.swift
Created Dec 20, 2016
Swift 3 debounce & throttle
View debounce-throttle.swift
//
// debounce-throttle.swift
//
// Created by Simon Ljungberg on 19/12/16.
// License: MIT
//
import Foundation
extension TimeInterval {
View Debounce.swift
import PlaygroundSupport
PlaygroundPage.current.needsIndefiniteExecution = true
func debounce1<T>(delay: DispatchTimeInterval, queue: DispatchQueue = .main, action: @escaping ((T) -> Void)) -> (T) -> Void {
var currentWorkItem: DispatchWorkItem?
return { (p1: T) in
currentWorkItem?.cancel()
currentWorkItem = DispatchWorkItem { action(p1) }
queue.asyncAfter(deadline: .now() + delay, execute: currentWorkItem!)
@simme
simme / UNNotification+Reschdule.swift
Created Nov 17, 2016
Exntension to `UNNotification` for "snoozing" a notification.
View UNNotification+Reschdule.swift
//
// UNNotification+Reschedule.swift
// Meal Plan
//
// Created by Simon Ljungberg on 17/11/16.
// License: MIT
//
import UIKit
import UserNotifications
View json_api_response.json
"data": [
{
"id": 1,
"type": "ingredient",
"attributes": {
"name": {
"en": "Cilantro",
"sv": "Koriander"
},
View .vimrc
" Use Vim settings
set nocompatible
set encoding=utf-8
" Use , as leader
let mapleader=","
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
@simme
simme / UIButton+hitBox.swift
Last active Jan 19, 2018
Extension to set an extended hitbox on UIButtons.
View UIButton+hitBox.swift
//
// UIBotton+hitBox.swift
//
// LICENSE: MIT
//
import UIKit
extension UIButton {
@simme
simme / diff.swift
Created Aug 10, 2016
Utility for diffing two arrays of arrays.
View diff.swift
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 Jul 20, 2016
A struct representing a range of dates.
View DateRange.swift
/// License: MIT
import Foundation
/**
A struct representing a range of dates.
*/
public struct DateRange {
// MARK: Properties
@simme
simme / UINavigationBar+Looks.swift
Last active Aug 15, 2017
UINavigationBar extension for setting and applying "looks" in one go.
View UINavigationBar+Looks.swift
//
// UINavigationbar+Looks.swift
//
// License: MIT
//
import UIKit
/**
Stores information about navigation bar looks.
You can’t perform that action at this time.