Skip to content

Instantly share code, notes, and snippets.

View dokun1's full-sized avatar
🤠
Howdy

David Okun dokun1

🤠
Howdy
View GitHub Profile
import Foundation
struct Bakery {
func bakeBread() {
print("make some Bread")
}
}
struct Kitchen {
func cookPizza() {
import Foundation
enum ComputerModel: String {
case apple = "Apple"
case windows = "Windows"
case linux = "Linux"
}
enum ComputerError: Error {
case tooEarly
import Foundation
struct Ingredient {
var name: String
var amount: Double
}
protocol Cookable {
func cook()
}
@dokun1
dokun1 / simpleDispatchExample
Created March 27, 2014 23:11
A simple example of calling one of my custom connection manager methods with a success and failure block, a-la AFNetworking
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[[EDAConnectionManager sharedManager] getQuestionsWithSuccess:^(NSArray *questions) {
self.questions = questions;
dispatch_async(dispatch_get_main_queue(), ^{
[self.refreshControl endRefreshing];
[self.tableView reloadData];
});
}failure:^(NSError *error) {
NSLog(@"error: %@", [error localizedDescription]);
}];
@dokun1
dokun1 / UILabel with Countdown
Last active February 27, 2017 17:00
UILabel as countdown timer given NSTimeInterval
-(void) updateCountdown {
NSTimeInterval timeToClosing = [_deleteDate timeIntervalSinceDate:[NSDate date]];
div_t h = div(timeToClosing, 3600);
int hours = h.quot;
div_t m = div(h.rem, 60);
int minutes = m.quot;
int seconds = m.rem;
NSString *hoursStr, *minutesStr, *secondsStr;
@dokun1
dokun1 / UIScrollView Infinite Paging
Last active August 29, 2015 13:57
Infinite UIScrollView w/Paging for UIImageViews - determining new page to load
-(void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
CGFloat xOffset = _scrollView.contentOffset.x;
CGFloat newStart = 0;
BOOL done = NO;
NSInteger newIndex = 1;
while (done == NO) {
if (newStart + 320 < xOffset) {
newStart += 320;
newIndex++;
@dokun1
dokun1 / UICollectionView Lazy Loading
Created January 31, 2014 15:45
Asynchronous Image Loading in UICollectionViewCell
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellIdentifier = @"AfterpartyPhotoCell";
AfterpartyPhotoCell *cell = (AfterpartyPhotoCell *)[collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
if (!cell)
cell = [[AfterpartyPhotoCell alloc] init];
[cell.downloadIndicator startAnimating];
cell.downloadIndicator.center = cell.center;
cell.imageView.contentMode = UIViewContentModeScaleAspectFill;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{