Wednesday, January 18, 2017

Wireshark - The capture could not be initiated (You don't have permissiont o capture on that device).


It seems Wireshark installer fails to set up permissions.

To fix it, run this manually:-

chgrp access_bpf /dev/bpf*
chmod g+rw /dev/bpf*

Make sure the user is in the "access_bpf" group.

Refs
https://josephhall.org/nqb2/index.php/wrshrkinstll
http://apple.stackexchange.com/questions/138694/what-is-access-bpf-group

Monday, February 1, 2016

Have fun with cross platform mobile development

A short presentation about a sample cross platform mobile project called TumChatter for both Android and iOS.





You can find the project on github at the link below:-
https://github.com/have-fun/TumChatter

Programming Language: Kotlin
Frameworks: Java, RoboVM
Dependency Injection: Dagger 2
Json: Gson
REST Client: Retrofit
Reactive Libraries: RxKotlin, RxJava
Unit Testing: Spek (Specification Framework), AssertJ, Mockito
Embedded Server: TumWeb, Nanohttpd
Android UI Binding: KotterKnife, ButterKnife


Tuesday, April 1, 2014

Create an array


1
  NSArray *array = [NSArray arrayWithObjects:@"One", [NSNumber numberWithInt:1], nil];

Or use literal array expression:-

1
  NSArray *array =@[ @"One", [NSNumber numberWithInt:1] ];

Use NSNumber to add boolean or integer values to an array, or prefix a boolean value with ‘@':-

1
  NSArray *array = @[ [NSNumber numberWithInt:1], [NSNumber numberWithBool:YES], @NO ];

Otherwise we will get an error like this:-

     Collection element of type ‘NSInteger’ (aka ‘int’) is not an Objective-C object

Use NSNull to add a nil equivalent value to an array:-

1
  NSArray *array = @[ @"a", [NSNull null], @"b" ];


Refs
http://stackoverflow.com/questions/1602572/how-to-create-an-array-of-strings-in-objective-c-for-iphone
http://clang.llvm.org/docs/ObjectiveCLiterals.html
http://stackoverflow.com/questions/1309535/why-does-nsarray-arraywithobjects-require-a-terminating-nil
http://stackoverflow.com/questions/2057910/how-to-add-nil-to-nsmutablearray

Saturday, March 29, 2014

Managed Object ID


  • Get the string URL representation from a ManagedObjectID
1
2
  NSURL *urlID = [objectID URIRepresentation];
  NSString *strUrlID = [urlID absoluteString];

  • Get the ManagedObjectID from a URL string
1
2
  NSURL *urlID = [[NSURL alloc] initWithString:strUrlID];
  NSManagedObjectID *objectID = [[managedObjectContext persistentStoreCoordinator] managedObjectIDForURIRepresentation:urlID];

  • Get the ManagedObject by a ManagedObjectID
1
2
  NSError *error = nil;
  NSManagedObject *managedObject = [moc existingObjectWithID:objectID error:&error];

  • Check if a ManagedObject is new
1
  BOOL isNew = managedObject.objectID.isTemporaryID;

  • Get the permanent object IDs for the objects in a child context.
1
2
3
4
5
6
7
8
  NSError *error = nil;
  [childManagedObjectContext obtainPermanentIDsForObjects:childManagedObjectContext.insertedObjects.allObjects error:&error]);

  // . . . Check for an error . . .

  [childManagedObjectContext save:&error];

  // . . . Check for an error . . .


Refs
http://stackoverflow.com/questions/3519334/how-to-uniquely-identify-nsmangedobject-with-string
http://stackoverflow.com/questions/10811280/how-to-get-the-objectid-from-url
http://stackoverflow.com/questions/3013288/how-to-use-managedobjectid-the-right-way
http://iphonedevelopment.blogspot.com.au/2009/07/core-data-determining-if-managed-object.html
http://stackoverflow.com/questions/11990279/core-data-do-child-contexts-ever-get-permanent-objectids-for-newly-inserted-obj/11996957#11996957

Thursday, March 27, 2014

Compare NSDate instances


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
  NSComparisonResult result = [date1 compare:date2];  
  if (result == NSOrderedAscending)
  {
    // date1 < date2
  }
  else if (result == NSOrderedDescending)
  {
    // date1 > date2
  }
  else
  {
    // date1 == date2
  }

or

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
  if ([date1 timeIntervalSinceReferenceDate] < [date2 timeIntervalSinceReferenceDate])
  {
    // date1 < date2
  }
  else if ([date1 timeIntervalSinceReferenceDate] > [date2 timeIntervalSinceReferenceDate])
  {
    // date1 > date2
  }
  else
  {
    // date1 == date2
  }

Refs
http://stackoverflow.com/questions/5965044/how-to-compare-two-nsdates-which-is-more-recent

lldb Error - no known method '-class'; cast the message send to the method's return type

p [[navigationController topViewController] class] 

returns

error: no known method '-class'; cast the message send to the method's return type 

To fix it, cast it first:- 

p [(NSObject *) [navigationController topViewController] class]

Refs
http://stackoverflow.com/questions/14007942/lldb-error-property-not-found-on-object-of-type

Monday, November 25, 2013

Start/Stop PostgreSQL on Mac

Start PostgreSQL:-
sudo -u postgres /Library/PostgreSQL/9.3/bin/pg_ctl -D /Library/PostgreSQL/9.3/data start
Stop PostgreSQL:-
sudo -u postgres /Library/PostgreSQL/9.3/bin/pg_ctl -D /Library/PostgreSQL/9.3/data stop
Stop PostgreSQL from auto-starting on reboot:-
sudo launchctl unload -w /Library/LaunchDaemons/com.edb.launchd.postgresql-9.3.plist 
Make PostgreSQL auto-start on reboot:-
sudo launchctl load -w /Library/LaunchDaemons/com.edb.launchd.postgresql-9.3.plist 
Refs
http://www.xtuple.org/faq/xtuple-faq/postgresql/how-do-i-stop-postgresql-service-mac 
https://gist.github.com/abhishekdev/1960888