Friday, 20 May 2016

Every one has faced the issue of Github not showing the complete blob diff for a file because it is too large. It asks you to see the diff on your own machine, locally.

Github Diff too big file
Github Diff too big

If you are my kind who doesn’t like seeing big diffs in terminal, then this solution is for you.
Git has a hidden feature to let you browse your repository on browser.

git-instaweb - Instantly browse your working repository in gitweb

Once you start the server for your repo

git instaweb

The issue is that there is not straight way of looking at blob diff between two specific commits.

Digging into the documentation I found that passing the correct the parameters can help you see the diff.

let SHA1 = SHA of commit to check diff from
let SHA2 = SHA of commit to check diff to

Once we have SHA1 and SHA2 resolved,
Just create the URL like: # Endpoint on which git is running instaweb

Just open this URL in your favourite browser and you would be able to see the diff of the file.

Sunday, 1 March 2015

Comparisons to YES are broken

This post is inspired from the eye-opener article -> bignerdranch.

I always had this question, Why does Objective-C need a BOOL when C gives it a free bool, which effectively works the same?.

Well, I couldn’t have been more wrong. BOOL and bool are entirely different beasts.

BOOL is a typedef, defined at /usr/include/objc/objc.h (Also available here)

typedef signed char BOOL;

Similar to, Boolean, which is defined at /usr/include/MacTypes.h (Also available here)

typedef unsigned char Boolean;

Also, YES and NO are macros for 1 and 0. Reference

#define YES (BOOL)1
#define NO (BOOL)0

This means that our usual comparisons might fail. Example:

12 == YES

For more such examples, look at bignerdranch.

The thing to note is that, you should be careful about the same comparisons for Boolean too.

Friday, 9 January 2015

Exchange variables in swift with an operator

Aim is to create an operator <-> to exchange two variables. The two variables can be of any type, but they should be of the same type (Obviously!).

We start by declaring an infix operator <->
infix operator <-> {}

Now we provide a definition for the operator using a generic function.
func <-><T>(inout a: T, inout b: T) {
  swap(&a, &b)

That’s it!

The following swift powers have been tested in the snippet above
1. Custom operators
2. In-out variables
3. Generic functions

We can test the operator like:

var a = 2, b = 4
a                            2
b                            4
a                            4
b                            2

var ab = "a", ba = "b"
ab                            a
ba                            b
ab                            b
ba                            a

Do notice that the operands of the operator <-> should be declared variable (var) for the exchange to work.

Edit: From +Rogier Pinkers's comment, the implementation for the operator has been changed with the inbuilt function to exchange two variables. Thanks +Rogier Pinkers!

Wednesday, 7 January 2015

How to check if a UIViewController is being dismissed/popped?

To know if your UIVIewController is being dismissed or popped, you can ask your UIVIewController if it is being dismissed or being moved from it’s parent UIVIewController.

- (void)viewWillDisappear:(BOOL)animated {
  [super viewWillDisappear:animated];
  if (self.isBeingDismissed || self.isMovingFromParentViewController) {
    // Handle the case of being dismissed or popped.

This has been documented in UIVIewController.h at lines 270-275 (iOS 8.1, Xcode 6.1.1).

Via StackOverflow

Thursday, 18 December 2014

Resymbolicating crash reports for iOS

Resymbolication in Xcode 6.1

  • Get the crash report from Device via Xcode

  • From the crash report get the version of the app.
  • Get the IPA and dSYM file for the version from ios-ci.
  • Put the following in a common folder (named lets say XYZ, which should not be in /tmp):
    • The unsymbolicated crash report.
    • The binary extracted from the IPA.
    • The dSYM file for the related binary.
  • On the terminal now, execute the following command:
    DEVELOPER_DIR=`xcode-select -print-path` /Applications/ -v -o resymbolicated.crash crashreport.crash
  • This should symbolicate your crash report and export the unsymbolicated version to resymbolicated.crash

Possible error case:

The whole file might not get symbolicated even with a successful run.
The verbose output in that case should end with something like:
Running /Applications/ -arch armv7 -l 0x91000 -o '/Users/ayushgoel/Downloads/11/Talkto' 0x001a3d44 0x0034f262 0x001188be 0x0031d23a 0x000978e2
Here symbolication of only 5 addresses has been tried. But in the crash report there are more addresses, which needed to be symbolicated. See code below.
Thread 5 name:  Session Background Thread  Dispatch queue: NSPersistentStoreCoordinator 0x166a8420
Thread 5 Attributed:
0   libsystem_kernel.dylib          0x338e6324 0x338e4000 + 8996
1   libsqlite3.dylib                0x335a31a0 0x3359c000 + 29088
2   libsqlite3.dylib                0x335bb7fe 0x3359c000 + 129022
3   libsqlite3.dylib                0x335ba720 0x3359c000 + 124704
4   libsqlite3.dylib                0x335d558e 0x3359c000 + 234894
5   libsqlite3.dylib                0x335dbab0 0x3359c000 + 260784
6   libsqlite3.dylib                0x335d5670 0x3359c000 + 235120
7   libsqlite3.dylib                0x335cb4aa 0x3359c000 + 193706
8   libsqlite3.dylib                0x335c9ed6 0x3359c000 + 188118
9   CoreData                        0x257ffab8 0x257ea000 + 88760
10  CoreData                        0x257ff7ae 0x257ea000 + 87982
11  CoreData                        0x258e72b2 0x257ea000 + 1036978
12  CoreData                        0x25805f0e 0x257ea000 + 114446
13  CoreData                        0x25805894 0x257ea000 + 112788
14  CoreData                        0x258b2520 0x257ea000 + 820512
15  CoreData                        0x258b97c8 0x257ea000 + 849864
16  libdispatch.dylib               0x338127a4 0x33811000 + 6052
17  libdispatch.dylib               0x33819ac4 0x33811000 + 35524
18  CoreData                        0x258ad302 0x257ea000 + 799490
19  CoreData                        0x25805512 0x257ea000 + 111890
20  CoreData                        0x258041da 0x257ea000 + 106970
21  Talkto                          0x0030fd0c 0x91000 + 2616588
22  Talkto                          0x0030f92e 0x91000 + 2615598
23  Talkto                          0x0030f9a2 0x91000 + 2615714
24  Talkto                          0x0011de7a 0x91000 + 577146
25  Talkto                          0x0011dce6 0x91000 + 576742
26  Talkto                          0x0013b77e 0x91000 + 698238
27  Talkto                          0x00128722 0x91000 + 620322
28  CoreFoundation                  0x25b00b10 0x259f6000 + 1092368
29  CoreFoundation                  0x25a2d690 0x259f6000 + 226960
30  Talkto                          0x00128324 0x91000 + 619300
31  Talkto                          0x0012769a 0x91000 + 616090
32  Talkto                          0x00127422 0x91000 + 615458
33  Talkto                          0x00126ea4 0x91000 + 614052
34  Talkto                          0x0030d2ee 0x91000 + 2605806
35  Talkto                          0x00126de2 0x91000 + 613858
36  Talkto                          0x00125fca 0x91000 + 610250
37  Talkto                          0x00311458 0x91000 + 2622552
38  Foundation                      0x2680cd6a 0x2673c000 + 855402
39  CoreFoundation                  0x25ac2d54 0x259f6000 + 838996
40  CoreFoundation                  0x25ac2162 0x259f6000 + 835938
41  CoreFoundation                  0x25ac07c8 0x259f6000 + 829384
42  CoreFoundation                  0x25a0e3bc 0x259f6000 + 99260
43  CoreFoundation                  0x25a0e1ce 0x259f6000 + 98766
44  Foundation                      0x26747bf8 0x2673c000 + 48120
45  Talkto                          0x000ebc42 0x91000 + 371778
46  Foundation                      0x2680cb56 0x2673c000 + 854870
47  libsystem_pthread.dylib         0x33975e90 0x33973000 + 11920
48  libsystem_pthread.dylib         0x33975e02 0x33973000 + 11778
49  libsystem_pthread.dylib         0x33973b8c 0x33973000 + 2956

This is because of the faulty parsing by the script.
To fix this convert: Thread 5 Attributed: -> Thread 5:.
And now run the script again to see the magic!