Skip to content

Instantly share code, notes, and snippets.

@ajayjapan
ajayjapan / RVM issue
Created January 12, 2011 03:10
cinderella
bash-3.2$ rm -rf ~/Developer
bash-3.2$ open http://www.atmos.org/cinderella/
bash-3.2$ curl https://github.com/atmos/cinderella/raw/master/bootstrap.sh \
> -o - | sh
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
102 1333 102 1333 0 0 3772 0 --:--:-- --:--:-- --:--:-- 33325
Ensuring we have the latest version of cinderella installed
A first time install takes about 45 minutes on a modern machine
Password:
@ajayjapan
ajayjapan / Reformatting JSON
Created January 19, 2011 20:41
Input & Output
Input: {
"venues": [{
"name": "Grand Central Terminal",
"type": "Trending Now"
},
{
"name": "New York Penn Station",
"type": "Trending Now"
},
{
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
@ajayjapan
ajayjapan / gist:3456708
Created August 24, 2012 22:48
Super quick hack to fix recursive json object mapping
// 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:
// 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:
@ajayjapan
ajayjapan / gist:5e7ba49e51f1ca24b76d
Created August 28, 2014 18:16
Adjust content size of collection view when flexible iOS 8 simulator size changes
@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;
@ajayjapan
ajayjapan / RPSGameViewController.m
Created October 2, 2015 21:36
1. Modify line 402 in RPSGameViewController.m 2.logging in and out multiple times 3. get 308 error
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];
@ajayjapan
ajayjapan / main.m
Created October 3, 2016 01:46
Two functions on how to handle zero elements in an NSArray
#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 {
@ajayjapan
ajayjapan / permutations.m
Last active October 3, 2016 01:55
Given a string return all the permutations of that string.
-(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);
}
@ajayjapan
ajayjapan / regionMonitoring.swift
Last active November 13, 2024 09:55
Here App Region Monitoring and Notification Trigger Logic
// 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]) {