Skip to content

Instantly share code, notes, and snippets.

Ajay Chainani achainan

Block or report user

Report or block achainan

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@achainan
achainan / example.swift
Last active Nov 28, 2018
UNLocationNotificationTrigger Example
View example.swift
// Define the content of the notification
let content = UNMutableNotificationContent()
content.title = place.title
content.body = place.blurb
content.sound = UNNotificationSound.default()
// Define the region
let region = CLCircularRegion(center: place.coordinate(), radius: place.radius ?? 100, identifier: place.identifier)
region.notifyOnEntry = true
region.notifyOnExit = false
@achainan
achainan / motionMonitoring.swift
Last active Nov 29, 2018
Here App Motion Monitoring and Notification Skipping Logic
View motionMonitoring.swift
// MARK - Motion Tracking Logic
func startTrackingMotionActivity(handler: @escaping (CMMotionActivity) -> Void) {
manager.startActivityUpdates(to: .main) { (activity) in
guard let activity = activity else { return }
if let lastActivity = self.currentActivity, lastActivity.automotive {
self.stoppedDrivingAt = Date() // now
}
self.currentActivity = activity
handler(activity)
@achainan
achainan / regionMonitoring.swift
Last active Nov 28, 2018
Here App Region Monitoring and Notification Trigger Logic
View regionMonitoring.swift
// MARK: - Significant location change montioring logic
// Called at launch of application if permission is already granted
func startMonitoringSignificantLocationChanges() {
locationManager.startMonitoringSignificantLocationChanges()
}
// Called by location manager if there is a significant location change
func locationManager(_ manager: CLLocationManager,
didUpdateLocations locations: [CLLocation]) {
@achainan
achainan / permutations.m
Last active Oct 3, 2016
Given a string return all the permutations of that string.
View permutations.m
-(NSArray<NSString> *)permutationsOfString:(NSString *)s {
NSMutableArray<NSString> *res = [NSMutableArray array];
if (s.length == 1) {
[res addObject:s];
} else if (s.length > 1) {
int lastIndex = s.length - 1;
String last = s.substring(lastIndex);
String rest = s.substring(0, lastIndex);
res = merge(permutation(rest), last);
}
@achainan
achainan / main.m
Created Oct 3, 2016
Two functions on how to handle zero elements in an NSArray
View main.m
#import <Foundation/Foundation.h>
#import <stdio.h>
@interface MyClass : NSObject
@end
@implementation MyClass
// 1. returns the number of non-zero elements (4)
+ (int)numberOfZeroElementsInArray:(NSArray *)array {
@achainan
achainan / RPSGameViewController.m
Created Oct 2, 2015
1. Modify line 402 in RPSGameViewController.m 2.logging in and out multiple times 3. get 308 error
View RPSGameViewController.m
case 4: { // Login and logout
if ([FBSDKAccessToken currentAccessToken]) {
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
[login logOut];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
// Clear up all the user defaults here.
NSString *appDomain = [[NSBundle mainBundle] bundleIdentifier];
[[NSUserDefaults standardUserDefaults] removePersistentDomainForName:appDomain];
[defaults synchronize];
@achainan
achainan / gist:5e7ba49e51f1ca24b76d
Created Aug 28, 2014
Adjust content size of collection view when flexible iOS 8 simulator size changes
View gist:5e7ba49e51f1ca24b76d
@interface UICollectionViewFlowLayout (InvalidateOnBoundsChange)
@end
@implementation UICollectionViewFlowLayout (InvalidateOnBoundsChange)
- (UICollectionViewLayoutInvalidationContext *)invalidationContextForBoundsChange:(CGRect)newBounds {
UICollectionViewLayoutInvalidationContext *context = [super invalidationContextForBoundsChange:newBounds];
CGRect oldBounds = self.collectionView.bounds;
CGFloat widthAdjustment = newBounds.size.width - oldBounds.size.width;
View gist:3490871
// AFIncrementalStore.m
//
// Copyright (c) 2012 Mattt Thompson (http://mattt.me)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
@achainan
achainan / gist:3456708
Created Aug 24, 2012
Super quick hack to fix recursive json object mapping
View gist:3456708
// AFIncrementalStore.m
//
// Copyright (c) 2012 Mattt Thompson (http://mattt.me)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
View iCuke Error
bash-3.2$ cucumber
Feature: Test
Background: # features/example.feature:3
Given "sonar.xcodeproj" is loaded in the simulator # iCuke-0.6.3/lib/icuke/cucumber.rb:197
execution expired (Timeout::Error)
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/timeout.rb:60:in `launch'
features/example.feature:4:in `Given "sonar.xcodeproj" is loaded in the simulator'
Scenario: User views the About screen # features/example.feature:6
You can’t perform that action at this time.