Skip to content

Instantly share code, notes, and snippets.

- (void)someRecursiveThingWithCompletionHandler:(void (^)(id response, NSError *))completionHandler;
{
__weak typeof(self) welf = self;
__block void (^fetchPageR)(int page);
void (^fetchPage)(int page);
fetchPageR = fetchPage = ^void(int page)
{
NSString *url = [NSString stringWithFormat:@"%@/?page=%i", SomeBaseUrl, page];
[self taskFromPath:url method:@"GET" parameters:nil completionHandler:^(NSURLResponse *response, id responseObject, NSError *error)
{
@oskob
oskob / .m
Created August 24, 2017 11:17
Listen to key commands in iOS
- (BOOL)canBecomeFirstResponder {
return YES;
}
- (NSArray *)keyCommands {
UIKeyCommand *left = [UIKeyCommand keyCommandWithInput:UIKeyInputLeftArrow modifierFlags:0 action:@selector(handleKeyLeft:)];
UIKeyCommand *right = [UIKeyCommand keyCommandWithInput:UIKeyInputRightArrow modifierFlags:0 action:@selector(handleKeyRight:)];
return @[left, right];
}
- (void) monitorPendingConnections {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0f * NSEC_PER_SEC)), dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
NSTimeInterval difference = [[NSDate date] timeIntervalSinceDate: _lastConnectionRefresh];
...
});
}
- (id)getThingWithIdentifier:(NSString *)identifier;
{
NSArray * arr = [things filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(Thing *thing, NSDictionary *bindings) {
return [thing.identifier isEqualToString:identifier];
}]];
return arr.count > 0 ? arr[0] : nil;
}
class ImagePagerGermainView: ImagePagerView {
override func awakeFromNib() {
super.awakeFromNib()
productImageView.clipsToBounds = true
}
override func layoutSubviews() {
super.layoutSubviews()
productImageView.layer.cornerRadius = productImageView.frame.size.width / 2
- (void)doTaskIfNotWaitingForResponse:(void (^)(void (^done)()))task;
{
task(^void () {
//done
});
}
[self doTaskIfNotWaitingForResponse:^(void (^done)()) {
// do stuff
done();
app.use(passport.initialize());
app.use(passport.session());
app.use(function (req, res, next)
@oskob
oskob / 0_reuse_code.js
Created January 30, 2014 13:18
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
D/debug ( 2479): Response: <html>
D/debug ( 2479): <head><title>401 Authorization Required</title></head>
D/debug ( 2479): <body bgcolor="white">
D/debug ( 2479): <center><h1>401 Authorization Required</h1></center>
D/debug ( 2479): <hr><center>nginx</center>
D/debug ( 2479): </body>
D/debug ( 2479): </html>
//
// User.m
// Sambofejden
//
// Created by Oskar Öberg on 2013-01-22.
// Copyright (c) 2013 Oskar Öberg. All rights reserved.
//
#import "NSManagedObject+Extended.h"
#import "DataManager.h"