Skip to content

Instantly share code, notes, and snippets.

View jarsen's full-sized avatar

Jason Larsen jarsen

View GitHub Profile
@rnapier
rnapier / observer.swift
Last active April 17, 2022 17:51
New ideas on Observer pattern in Swift
import UIKit
// Lots of ideas here that I'd love thoughts about. Some of this creates new highly generic types
// (UniqueIdentifier, IdentifiedSet) that may have broader purpose. Some of it defines a new Observer pattern.
// I've been playing around with this UniqueIdentifier type. Its purpose is to let you store things
// in dictionaries (or possibly sets) that you couldn't otherwise.
// It's just a self-referencial ObjectIdentifier. I used to use NSUUID for this purpose, but wondering
// if this is better.
@t-mart
t-mart / netrw quick reference.md
Last active March 25, 2024 07:47
A quick reference for Vim's built-in netrw file selector.
Map Action
<F1> Causes Netrw to issue help
<cr> Netrw will enter the directory or read the file
<del> Netrw will attempt to remove the file/directory
- Makes Netrw go up one directory
a Toggles between normal display, hiding (suppress display of files matching g:netrw_list_hide) showing (display only files which match g:netrw_list_hide)
c Make browsing directory the current directory
C Setting the editing window
d Make a directory
@BigZaphod
BigZaphod / Pathfinding.swift
Created November 24, 2015 17:33
AStar pathfinding in Swift
// uses PriorityQueue from https://github.com/mauriciosantos/Buckets-Swift
protocol Pathfinding {
typealias Node: Hashable
func neighborsFor(node: Node) -> [Node]
func costFrom(from: Node, to: Node) -> Int
func heuristicFrom(from: Node, to: Node) -> Int
}
@sahrens
sahrens / React Native: Animated - Code
Last active July 4, 2020 00:07
Example code from ReactEurope 2015 talk - React Native: Animated
/**
* The examples provided by Facebook are for non-commercial testing and
* evaluation purposes only.
*
* Facebook reserves all rights not expressly granted.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL
* FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
@chriseidhof
chriseidhof / json.swift
Last active March 21, 2019 07:45
Reflection
import Cocoa
struct Person {
var name: String = "John"
var age: Int = 50
var dutch: Bool = false
var address: Address? = Address(street: "Market St.")
}
struct Address {
@andymatuschak
andymatuschak / gist:2b311461caf740f5726f
Created December 28, 2014 18:17
A pragmatic and intentionally non-abstract solution to JSON decoding / initialization that doesn't require learning about five new operators.
struct User {
let id: Int
let name: String
let email: String?
}
extension User: JSONDecodable {
static func create(id: Int, name: String, email: String?) -> User {
return User(id: id, name: name, email: email)
}
@CodaFi
CodaFi / Sections.swift
Last active August 29, 2015 14:10
Operator sections for the Swift STL.
/// Sectional Sale
prefix operator >> {}
postfix operator >> {}
public prefix func >>(rhs: UInt16) -> UInt16 -> UInt16 {
return { lhs in lhs >> rhs }
}
public postfix func >>(lhs: UInt16) -> UInt16 -> UInt16 {
@andymatuschak
andymatuschak / CollectionViewDataSource.swift
Last active February 12, 2021 09:44
Type-safe value-oriented collection view data source
//
// CollectionViewDataSource.swift
// Khan Academy
//
// Created by Andy Matuschak on 10/14/14.
// Copyright (c) 2014 Khan Academy. All rights reserved.
//
import UIKit
@jordoh
jordoh / entity.lua
Last active May 22, 2022 22:08
Starbound lua API
--- Stubs for entity.* callbacks defined in C++.
--
-- DO NOT INCLUDE this file in your scripts, it is for documentation purposes only.
--
-- Entity callbacks query and mutate the specific entity that is running the
-- lua script. They can be called from a _different_ entity using
-- world.callScriptedEntity(targetEntityId, "entity.*"), replacing "*" with the
-- name of a function defined below.
--
-- Specific types of entities (e.g. NPCs, Objects) define different sets of
@orta
orta / gist:7117853
Created October 23, 2013 12:36
HTML -> NSAttributedString using only UIKit
+ (NSAttributedString *)artsyBodyTextAttributedStringFromHTML:(NSString *)HTML withFont:(UIFont *)font
{
NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
style.lineHeightMultiple = 1.2;
style.paragraphSpacing = font.pointSize * .5;
NSDictionary *textParams = @{
NSFontAttributeName : font,
NSParagraphStyleAttributeName : style,