Showing posts with label programming. Show all posts
Showing posts with label programming. Show all posts

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

Friday, June 28, 2013

Enable Xdebug in MAMP

Uncomment the zend_extension line and modify the /Applications/MAMP/bin/php/php5.x/conf/php.ini file to look like this:-
[xdebug]
zend_extension="/Applications/MAMP/bin/php/php5.4.10/lib/php/extensions/no-debug-non-zts-20100525/xdebug.so"
xdebug.remote_enable=1
xdebug.remote_host=localhost
 
; On my machine, the default port 9000 has already been taken by something else.
xdebug.remote_port=9099
 
; Recommended when using Symfony
xdebug.max_nesting_level=250
Then restart the servers in MAMP.

Refs

Wednesday, June 26, 2013

Custom php.ini on shared hosting

  • Find the default php.ini path. Mine is /usr/local/lib/php.ini
<?php phpinfo() ?>
  • Copy the default php.ini to the user's home folder and customise it.
<?php copy("/usr/local/lib/php.ini", "/home/username/php.ini") ?>
  • Create a .htaccess file in the user's home folder with the following content.
SetEnv PHPRC /home/username/php.ini
# The following lines are important if the php.ini file is put in the document root.
<Files php.ini>
order allow,deny
deny from all
</Files>
Refs

Friday, May 24, 2013

Convert an object array to a string array in Java


  • System.arraycopy(Object src, int srcPos, Object dest, int destPos, int length);
  • Arrays.asList(Object_Array).toArray(new String[Object_Array.length]);  
  • Java 1.6
        String[] stringArray = Arrays.copyOf(objectArray, objectArray.length, String[].class);

Refs

Friday, January 13, 2012

Make Eclipse look better on Ubuntu

  • Compact the look and fix unreadable selected entry in content assist in some themes (e.g. Ambience) by creating a new text file called "gtkrc" (a stylesheet file for GTK apps) with the following content:- 
gtk-color-scheme = "selected_text_color:#000000"
style "compact"
{
  GtkButton::default_border={0,0,0,0}
  GtkButton::default_outside_border={0,0,0,0}
  GtkButtonBox::child_min_width=0
  GtkButtonBox::child_min_heigth=0
  GtkButtonBox::child_internal_pad_x=0
  GtkButtonBox::child_internal_pad_y=0
  GtkMenu::vertical-padding=1
  GtkMenuBar::internal_padding=1
  GtkMenuItem::horizontal_padding=4
  GtkToolbar::internal-padding=1
  GtkToolbar::space-size=1
  GtkOptionMenu::indicator_size=0
  GtkOptionMenu::indicator_spacing=0
  GtkPaned::handle_size=4
  GtkRange::trough_border=0
  GtkRange::stepper_spacing=0
  GtkScale::value_spacing=0
  GtkScrolledWindow::scrollbar_spacing=0
  GtkExpander::expander_size=10
  GtkExpander::expander_spacing=0
  GtkTreeView::vertical-separator=0
  GtkTreeView::horizontal-separator=0
  GtkTreeView::expander-size=12
  GtkTreeView::fixed-height-mode=TRUE
  GtkWidget::focus_padding=0

  font_name="Liberation Sans,Sans Regular 8"
  text[SELECTED] = @selected_text_color
}
class "GtkWidget" style "compact"
style "compact2"
{
  xthickness=1
  ythickness=1
}
class "GtkButton" style "compact2"
class "GtkToolbar" style "compact2"
class "GtkPaned" style "compact2" 
  • To use the above stylesheet with Eclipse (my version is Indigo - 3.7.1), run Eclipse like this:-
GTK2_RC_FILES=$GTK2_RC_FILES:/somewhere_1/gtkrc /somewhere_2/eclipse
  • Make tooltip readable by using #000000 as its foreground colour (tooltip_fg_color) and #f5f5b5 as background (tooltip_bg_color) in the following files:- 
/usr/share/themes/<your-current-theme>/gtk-3.0/settings.ini
/usr/share/themes/<your-current-theme>/gtk-3.0/gtk.css
/usr/share/themes/<your-current-theme>/gtk-2.0/gtkrc
  • Install Eclipse theme colour plugin and may want to try my TumCode theme which keeps the number of colours to the minimum.
     
  • Replace the default "Monospace" font with "Liberation Mono" and optionally reduce the font size to 8 or 9.
Windows -> Preferences -> General -> Appearance -> Colors and Fonts
(for Java Editor Text Font, Javadoc display font, Properties File Editor Text Font, etc.)

Here is how it looks after the above changes:-

Refs
http://blog.xam.dk/?p=70 
http://askubuntu.com/questions/70599/how-to-change-tooltip-background-color-in-unity
http://blog.valotas.com/2010/02/eclipse-on-linux-make-it-look-good.html

Tuesday, May 3, 2011

Uninstall NetBeans

NetBeans IDE 7.0 has arrived! It's time to uninstall the old one (v6.9.1).

If NetBeans was installed with the root privilege, uninstall it using
cd /usr/local/netbeans-6.9.1
sudo ./uninstall.sh
With normal user privilege, use:-
cd ~/netbeans-6.9.1
./uninstall.sh

Monday, April 18, 2011

Mouse movement is very jerky when using rdesktop

Mouse pointer movement is not smooth especially when using RDP to a remote Windows Vista or Windows 7. Disabling motion events notification using the -m switch helps but any mouse-over event won't also be triggered. It's a bit inconvenient but worth sacrificing for smooth mouse movement. However, with the -m switch, the mouse pointer will disappear. Apply the patch below to make the local cursor always appear and exclude the suppression of motion events when a mouse button is pressed (needed for drag & drop action).

patch -i rdp-path
  • To compile,
sudo apt-get install libssl-dev
./configure
sudo make install
  • To run this patched rdesktop,
/usr/local/bin/rdesktop -m -d<domain> -u<user-name> server

Thursday, April 16, 2009

Team Explorer Error

After I installed IE8 two weeks ago, I couldn't use Team Explorer anymore. I got the "Unable to cast COM object of type . . . {6D5140C1-7436 ...." error. The weird thing is it worked fine when running Visual Studio in user mode. It seems like a permission issue to me. Following the suggestion posted here by re-registering actxprxy.dll didn't fix the problem. I tried that in both system32 and syswow64 (I'm running Vista 64 SP1).

During that time I was so tied up with my work that I kind of lived with it by running 2 instances of Visual Studio; one in admin mode for my development and the other in user mode just for using Team Explorer. Until recently I needed Profiler and it crashed every time when it tried to load the report. Reinstalling Visual Studio 2008 SP1 didn't help. I had a feeling that it might be related to the initial problem so I tried re-registering actxprxy.dll again. But this time, I unregistered it first in both system32 and syswow64 before re-registering it. It worked! Both Team Explorer and Profiler are now back to live. (Visual Studio's devenv is a 32-bit process so doing so just in syswow64 should do the trick I guess).