Skip to content

Instantly share code, notes, and snippets.

View datwelk's full-sized avatar
🏠
Working from home

Damiaan Twelker datwelk

🏠
Working from home
  • Amsterdam, The Netherlands
View GitHub Profile
@datwelk
datwelk / style.json
Last active February 26, 2021 13:03
style.json
{
"version": 8,
"name": "Bright",
"metadata": {
"mapbox:autocomposite": false,
"mapbox:groups": {
"1444849242106.713": {"collapsed": false, "name": "Places"},
"1444849334699.1902": {"collapsed": true, "name": "Bridges"},
"1444849345966.4436": {"collapsed": false, "name": "Roads"},
"1444849354174.1904": {"collapsed": true, "name": "Tunnels"},
// Definitions
NSDictionary *son = @{ @"firstname" : @"James", @"lastname" : @"Appleseed" };
NSDictionary *daughter = @{ @"firstname" : @"Susan", @"lastname" : @"Appleseed"};
NSArray *children = @[son, daughter];
NSDictionary *father = @{ @"firstname" : @"John", @"lastname" : @"Appleseed" };
NSDictionary *family = @{@"children" : children, @"father" : father};
NSDictionary *pedigree = @{@"family" : family };
// First test
id _family = [pedigree objectForKey:@"family"];
@datwelk
datwelk / gist:3780805
Created September 25, 2012 09:17
Emoji's, ranges and attributed strings
// The issue: the Twitter API returns so called 'tweet entities' for each tweet. These entities contain the ranges
// of hashtags, mentions and urls in the tweet. In iOS, emoji's have a length of 2. The Twitter API uses 1 as length
// for the emoji's. So when you try to change the foreground color attribute in the range Twitter gives, you change
// the foreground color of a part of the emoji. The affected thread will freeze and ultimately crash.
// This code fixes the issue with emoji's, but does not yet work with composed character sequences longer than 2.
// Feel free to fork/comment.
NSRange range; // The old, corrupted range that doesn't take emoji's in account
NSString *string; // The string
How to detect whether a tableview is scrolling or not?
- KVO on isDragging and isDecelerating?
NO. isDragging and isDecelerating are not KVO compliant.
- UITableView subclass with custom isScrolling property + UIScrollViewDelegate?
NO. UIScrollViewDelegate methods don't work in the UITableView subclass.
Ugly solution: implement 7 UIScrollViewDelegate methods in your viewcontroller subclass. Result: messy code.
- (void)start
{
NSData *imageData = [self dataFromImage:self.image];
//NSInteger maxBytes = 3145728;
NSInteger maxBytes = 30000;
NSInteger compressedSize = imageData.length;
NSLog(@"Compressed size: %i", compressedSize);
NSInteger g = 50; //bovengrens voor random getallen
NSInteger f = 20; //aantal benodigde random getallen
NSInteger i = 0; //loop var
NSMutableArray *chosenNumbers = [NSMutableArray array]; //container voor gekozen getallen
while (i < f) {
NSInteger random = arc4random() % g;
NSNumber *randomNumber = [NSNumber numberWithInt:random];
if ([chosenNumbers containsObject:randomNumber]) {
f++;
} else {
NSArray *names = @[@"Name", @"Name2", @"Name3", @"Name4"];
NSMutableArray *predicateStrings = [NSMutableArray array];
[names enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
[predicateStrings addObject:[NSString stringWithFormat:@"firstName == %@", obj]];
}];
NSString *predicateString = [predicateStrings componentsJoinedByString:@" || "];
NSPredicate *predicate = [NSPredicate predicateWithFormat:predicateString];