Skip to content

Instantly share code, notes, and snippets.

@simme
simme / pixels.processing
Created February 5, 2018 21:42
Processing pixel manip
void setup() {
fullScreen();
frameRate(15);
}
void draw() {
// Loads all pixels on screen into an array of size width*height
loadPixels();
color onColor = #000000;
color offColor = #FFFFFF;
@simme
simme / UITabBarController+ToggleTabBar.swift
Created January 25, 2018 15:36
Extension on UITabBarController for hiding/showing the tab bar.
extension UITabBarController {
/**
Show or hide the tab bar.
- Parameter hidden: `true` if the bar should be hidden.
- Parameter animated: `true` if the action should be animated.
- Parameter transitionCoordinator: An optional `UIViewControllerTransitionCoordinator` to perform the animation
along side with. For example during a push on a `UINavigationController`.
*/
@simme
simme / UITextView+FadeLast.swift
Last active April 25, 2021 21:57
Fades the last line of a `UITextView` horizontally, instead of truncating it.
extension UITextView {
var lineFrames: [CGRect] {
let numberOfGlyphs = layoutManager.numberOfGlyphs
var numberOfLines = 0
var index = 0
var lineRange = NSRange()
let maxNumberOfLines = textContainer.maximumNumberOfLines
var lineRects = [CGRect]()
while (index < numberOfGlyphs) {
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 December 20, 2016 10:04
Swift 3 debounce & throttle
//
// debounce-throttle.swift
//
// Created by Simon Ljungberg on 19/12/16.
// License: MIT
//
import Foundation
extension TimeInterval {
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 November 17, 2016 09:43
Exntension to `UNNotification` for "snoozing" a notification.
//
// UNNotification+Reschedule.swift
// Meal Plan
//
// Created by Simon Ljungberg on 17/11/16.
// License: MIT
//
import UIKit
import UserNotifications
"data": [
{
"id": 1,
"type": "ingredient",
"attributes": {
"name": {
"en": "Cilantro",
"sv": "Koriander"
},
" 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 January 19, 2018 09:52
Extension to set an extended hitbox on UIButtons.
//
// UIBotton+hitBox.swift
//
// LICENSE: MIT
//
import UIKit
extension UIButton {