This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// itoa.c | |
// itoa | |
// | |
// Created by Jacob Relkin on 14/02/2021. | |
// | |
#include <stdlib.h> | |
#include <stdio.h> | |
#include <math.h> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@interface JRMutableDictionary : NSMutableDictionary | |
@end | |
@implementation JRMutableDictionary { | |
dispatch_queue_t queue; | |
NSMutableDictionary *storage; | |
} | |
- (void)dealloc { | |
if(queue) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@interface NSCountedSet (JRCountedSetAdditions) | |
- (NSArray *) objectsWithCount:(NSUInteger) count; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
typedef void (^JRIterationBlock)(NSUInteger index); | |
static inline void invokeBlockIterativelyUsingRange(JRIterationBlock block, NSRange rng) { | |
NSParameterAssert(block); | |
for(NSUInteger i = rng.location; i < NSMaxRange(rng); ++i) { | |
block(i); | |
} | |
} | |
@implementation NSNumber (BlockAdditions) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@interface NSLock (JRAdditions) | |
- (void)lockWithBlock:(dispatch_block_t)block; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)printRecursivelyUpTo:(NSUInteger)max { | |
__block dispatch_block_t block; | |
__block NSUInteger iterator = 0; | |
dispatch_block_t b = ^{ | |
if(iterator == max) return; | |
NSLog(@"%u", iterator); | |
++iterator; | |
block(); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@interface NSArray(JRAdditions) | |
- (id)jr_objectAtIndex:(long long)index { | |
NSUInteger realIndex = index; | |
if(index < 0) { | |
realIndex = [self count] - (+index); | |
} | |
return [self objectAtIndex:realIndex]; | |
} |
NewerOlder