Skip to content

Instantly share code, notes, and snippets.

@th3m477
th3m477 / NSLayoutAnchor+Shortcuts.swift
Created August 2, 2019 07:35
Constraint shortcuts
extension NSLayoutAnchor {
@objc @discardableResult func eq(_ anchor: NSLayoutAnchor, _ constant: CGFloat = 0.0) -> NSLayoutConstraint {
let c = constraint(equalTo: anchor, constant: constant)
c.isActive = true
return c
}
@objc @discardableResult func lte(_ anchor: NSLayoutAnchor, _ constant: CGFloat = 0.0) -> NSLayoutConstraint {
let c = constraint(lessThanOrEqualTo: anchor, constant: constant)
c.isActive = true
@th3m477
th3m477 / Web3Connection.js
Last active June 13, 2019 21:20
Web3.js websocket connection logic
const RECONNECT_MILLIS = 2000
class Web3Connection {
constructor() {
this.connect()
}
async connect() {
const provider = new Web3.providers.WebsocketProvider('...')
@th3m477
th3m477 / emojihash.swift
Created September 13, 2018 16:22
Emoji hash example in Swift
func emojiHash(_ input: String) -> String {
// HashEmoji.txt is a line separated file of 256 emojis (1 per byte)
// https://gist.github.com/th3m477/c0b306fd7992459f366e1a49fe0520d2
guard let path = Bundle.main.path(forResource: "HashEmoji", ofType: "txt"),
let emojiData = try? String(contentsOfFile: path, encoding: .utf8)
else {
preconditionFailure("HashEmoji resource not available")
}
let emojis = emojiData.components(separatedBy: .newlines)
@th3m477
th3m477 / HashEmoji.txt
Created September 13, 2018 16:12
Emoji Hash v1
💩
👻
🤖
🎃
🤡
🦅
🐢
🐔
🐧
👁
@th3m477
th3m477 / gist:14e9eac2e41e312cf825f06b97312509
Created September 3, 2018 09:38
HelloWorldKittens Ethereum Smart Contract ABI
[
{
"constant": true,
"inputs": [
{
"name": "_name",
"type": "string"
}
],
"name": "howManyKittensCalled",
@th3m477
th3m477 / JSONDecoder+Date.swift
Created July 26, 2018 08:01
Swift JSON Date Decoder for unix millis, secs, ISO8701 with and without fractional seconds
extension JSONDecoder {
enum DateDecodeError: String, Error {
case invalidDate
}
static var bestDateAttemptDecoder: JSONDecoder {
let decoder = JSONDecoder()
decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in
let container = try decoder.singleValueContainer()
if let dateSecs = try? container.decode(Double.self) {