Skip to content

Instantly share code, notes, and snippets.

View plantpurecode's full-sized avatar
🎯

Jacob Relkin plantpurecode

🎯
View GitHub Profile
@plantpurecode
plantpurecode / gist:686908d873f9d210096b
Last active August 29, 2015 14:16
Threadsafe Mutable Dictionary
@interface JRMutableDictionary : NSMutableDictionary
@end
@implementation JRMutableDictionary {
dispatch_queue_t queue;
NSMutableDictionary *storage;
}
- (void)dealloc {
if(queue) {
@plantpurecode
plantpurecode / OptionalChecking.swift
Created February 23, 2020 07:45
A neat way to avoid nil checks with collections...
let array = ["a", "b", "c", "d"].map(Optional.init)
array.contains("a") // true
array.contains(Optional("a")) // true
array.contains("e") // false
array.contains(Optional("e")) // false
let otherArray = ["a"]
// `Array.first` is an Optional property, but we can use it as an argument to `Array.contains` since the array is actually of Optional<String> type...
array.contains(otherArray.first) // true
/**
* Definition for a binary tree node.
* public class TreeNode {
* public var val: Int
* public var left: TreeNode?
* public var right: TreeNode?
* public init() { self.val = 0; self.left = nil; self.right = nil; }
* public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }
* public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {
* self.val = val
public class TreeNode {
public var val: Int
public var left: TreeNode?
public var right: TreeNode?
public init() { self.val = 0; self.left = nil; self.right = nil; }
public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }
public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {
self.val = val
self.left = left
self.right = right
@plantpurecode
plantpurecode / itoa.c
Created February 14, 2021 15:42
A C implementation of stdlib's itoa function
//
// itoa.c
// itoa
//
// Created by Jacob Relkin on 14/02/2021.
//
#include <stdlib.h>
#include <stdio.h>
#include <math.h>