Skip to content

Instantly share code, notes, and snippets.

@buranmert
buranmert / In-page navigation detection UIWebView
Created November 4, 2013 15:19
In-page navigation detection UIWebView
//
// WVViewController.m
// WebViewTrial
//
// Created by Mert Buran on 11/4/13.
// Copyright (c) 2013 Mert Buran. All rights reserved.
//
#import "WVViewController.h"
@buranmert
buranmert / sort.py
Created April 9, 2015 19:18
Simple sorting in Python
array = [1,2,3]
for x in range(len(array)-1):
indexToSwap = x
for y in range(x+1, len(array)):
if array[indexToSwap] > array[y]:
indexToSwap = y
array[x], array[indexToSwap] = array[indexToSwap], array[x]
print array
@buranmert
buranmert / MBArrayFilter
Created May 14, 2015 08:28
Filtering NSArray with predicate
- (void)test {
NSArray *test = @[@"ASDASD", @"BAQWEQWE", @"ASDQWEQEW", @"RTYTYERTRWEEWR", @"NBVBCVVA"];
for (unichar i = 'a'; i <= 'z' ; i++) {
NSPredicate *filterPredicate = [NSPredicate predicateWithBlock:^BOOL(NSString *evaluatedObject, NSDictionary *bindings) {
return tolower([evaluatedObject characterAtIndex:0]) == i;
}];
NSArray *filteredArray = [test filteredArrayUsingPredicate:filterPredicate];
}
}
@buranmert
buranmert / quicksort.py
Created May 31, 2015 10:03
Quicksort python
def quicksort(array):
if len(array) <= 1:
return array
less = []
more = []
equal = []
pivot = array[len(array)/2]
for x in array:
if x < pivot:
less.append(x)
@buranmert
buranmert / fibonacci.py
Created June 1, 2015 09:23
Fast Fibonacci algorithm
def fibonacci(n):
if n <= 2:
return 1
elif n <= 0:
return 0
if n % 2 == 0:
x = n/2
return fibonacci(x) * (fibonacci(x + 1) + fibonacci(x - 1))
else:
@buranmert
buranmert / MBTableViewController
Created June 25, 2015 13:24
A UITableViewController that has a UIView as its root view
//
// MBTableViewController.m
// MBTableViewController
//
// Created by Mert Buran on 20/06/2015.
// Copyright (c) 2015 Mert Buran. All rights reserved.
//
#import "MBTableViewController.h"
#import "CustomTableViewController.h" //just in case, you should use your own custom UITableViewController subclass
@buranmert
buranmert / subarray_with_given_sum.py
Created July 12, 2015 16:08
Subarray with given sum
#!/usr/bin/env/python
test_data = [3, 100, 200, 100, 200, 100, 200, 100, 200, 100, 200, 100, 200, 100, 200, 100, 200, 100, 200, 100, 200, 100, 200, 100, 200, 100, 200, 100, 200, 100, 200, 100, 200, 100, 200, 100, 200, 100, 200, 100, 200, 100]
test_goal = 5
def find_subsequence(data, goal):
temp = list(data)
depth = 1
while len(temp) > 0:
@buranmert
buranmert / ExampleViewController.m
Created June 23, 2016 15:47
Example View Controller for SDK
#import "ViewController.h"
#import <AVFoundation/AVFoundation.h>
#import "AFNetworking.h"
static NSString * const DummyModelUUID = @"a1303fcf-e6e2-4741-a028-82db4d566068";
@interface ViewController () <AGTViewControllerProtocol>
@property (weak, nonatomic) IBOutlet UIActivityIndicatorView *activityIndicator;
@property (weak, nonatomic) IBOutlet AGTView *ARView;
@buranmert
buranmert / replace_prefix.sh
Created August 2, 2016 16:13
Replace file prefixes in batch
# remove prefix
for file in *; do mv "$file" "$(echo "$file"|cut -c3-)"; done
# add prefix
for file in *; do mv "$file" {{{new_pre}}}"$file"; done
@buranmert
buranmert / MB_Autolayout.m
Created December 15, 2016 14:04
Autolayout helper
- (void)ag_addSubview:(UIView *)subview withInsets:(UIEdgeInsets)insets {
[self addSubview:subview];
[subview setTranslatesAutoresizingMaskIntoConstraints:NO];
[self addConstraintFromSubview:subview forAttribute:NSLayoutAttributeTop withConstant:insets.top];
[self addConstraintFromSubview:subview forAttribute:NSLayoutAttributeBottom withConstant:insets.bottom];
[self addConstraintFromSubview:subview forAttribute:NSLayoutAttributeLeft withConstant:insets.left];
[self addConstraintFromSubview:subview forAttribute:NSLayoutAttributeRight withConstant:insets.right];
}
- (BOOL)addConstraintFromSubview:(UIView *)subview forAttribute:(NSLayoutAttribute)attribute withConstant:(CGFloat)constantValue {