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
import UIKit | |
enum Dimension { | |
case X, Y | |
} | |
class ViewController: UIViewController { | |
override func viewDidLoad() { | |
super.viewDidLoad() |
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)replaceFileNamesOfImagesWithUUIDsAtPath:(NSString *)path { | |
NSFileManager *fileManager = [NSFileManager defaultManager]; | |
NSURL *directoryURL = [NSURL fileURLWithPath:path]; | |
NSArray *keys = [NSArray arrayWithObject:NSURLIsDirectoryKey]; | |
NSDirectoryEnumerator *enumerator = [fileManager | |
enumeratorAtURL:directoryURL | |
includingPropertiesForKeys:keys | |
options:0 | |
errorHandler:^(NSURL *url, NSError *error) { |
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)getMax:(float *)max min:(float *)min on:(NSArray *)arr { | |
for (NSNumber *num in arr) { | |
*max = MAX(*max, num.floatValue); | |
*min = MIN(*min, num.floatValue); | |
} | |
} | |
- (int)indexForResponse:(float)response max:(float)max min:(float)min bucketCount:(int)count { | |
float bucketWidth = (max - min) / count; | |
return floorf((response - min) / bucketWidth); |
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
'a simple, (and pretty inefficient, but easy) macro to flip the values in a horizontal or vertical range. Saves a lot of time when you just want to swap two values or flip a list. | |
Sub flipRange() | |
' | |
' flipRange Macro | |
' | |
' | |
Dim i As Long | |
Dim num As Long |
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
' Replaces all the "=" with "#" or vice versa depending on first cell | |
' This is useful for copying cells that contain formulas with cell references that you don't want to change when you move them. For example, transposing, copying between workbooks | |
' | |
Sub toggleEqualsSign() | |
' | |
' toggleEqualsSign Macro | |
Dim replaceWhat As String | |
Dim replaceWithThat As String |
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
Sub extractNumbersFromCells() | |
' | |
' | |
' Extract numbers from cells in selected range | |
' | |
Dim rng As Range | |
Dim Last As Long | |
Last = ActiveSheet.UsedRange.Rows.Count | |
For Each rng In Selection |
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
- (NSString *)addSpacesToCharacters:(NSArray *)characters { | |
if (characters.count <= 1) { | |
return characters.firstObject; | |
} | |
// bounding rect of base string, divide by length, calculate optimium number of spaces | |
CGRect boundingRect = CGRectZero; | |
CGSize constraintSize = self.view.frame.size; | |
NSString *string = [characters componentsJoinedByString:@""]; |
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
import Darwin | |
func quickSort(inout data:[Int], _ left:Int, _ right:Int) { | |
let index = partition(&data, left, right) | |
if left < index - 1 { | |
quickSort(&data, left, index - 1) | |
} | |
if index < right { | |
quickSort(&data, index, 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
func isPalindrome(string:String) -> Bool { | |
if string.isEmpty || string.characters.count == 1 { | |
return true | |
} | |
var fromStart = string.startIndex | |
var fromEnd = string.endIndex.predecessor() | |
while fromStart != fromEnd { | |
if string[fromStart] != string[fromEnd] { |
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
import Foundation | |
extension NSObject { | |
var className: String { | |
return String(describing: type(of: self)) | |
} | |
class var className: String { | |
return String(describing: self) | |
} |
OlderNewer