neutrofoton

Science, Technology and Life

GroovyDynamicElementReader Is Missing Import Spring Framework Source to Eclipse STS

| Comments

Sometime for some reasons when dealing with open source technology we have interest to download the full source code of the frameworks we use. Either for customization, extending them or just for having a look to have more knowledge how exactly they work.

Spring is a popular framework in Java world. It’s one of my favorite framework in Java. At the time of this blog post, I have just grabbed the source of it from github repository. The source code is fantastic. Nice coding style, project structure, build tool and of course its documentations. While following the guidance to build and import to Spring Tool Suite, I got an error on spring-beans-groovy project in GroovyBeanDefinitionReader.java. Navigating to the errors, STS seems try to find a class GroovyDynamicElementReader but not found.

Honestly I have no any experience with groovy before. When I try to drill through spring-beans-groovy/src/main/groovy/org/springframework/beans/factory/groovy, finally get a clue GroovyDynamicElementReader.groovy.

Installing Groovy Eclipse seems solve the problem.

In case you have the same problem as what I got, just ensure you have Groovy Eclipse on your eclipse base IDE.

Reference

  1. https://github.com/groovy/groovy-eclipse/wiki
  2. http://blog.csdn.net/zlx510tsde/article/details/46241675

Math in Web

| Comments

There are several frameworks that can be used to display math equation on web page. Usually math equestion written in LaTeX format. LaTeX is used for the communication and publication of scientific documents in many fields, including mathematics, physics, computer science, statistics etc.

MathJax and KaTeX are two popular javascript frameworks that can render LaTeX expression to beautiful math equation in browser.

The following are examples math LaTeX expression rendered with KaTeX. To use KaTeX we just need to include katex.min.css and katex.min.js

KaTeX
1
2
3
4
5
6
7
8
9
10
11
12
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.5.1/katex.min.css"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.5.1/katex.min.js"></script>

<div>
<p><span class="katex" id="eq1"></span></p>
<p><span class="katex" id="eq2"></span></p>
<p><span class="katex" id="eq3"></span></p>
<p><span class="katex" id="eq4"></span></p>
<p><span class="katex" id="eq5"></span></p>
<p><span class="katex" id="eq6"></span></p>
<p><span class="katex" id="eq7"></span></p>
</div>
KaTeX sample
1
2
3
4
5
6
7
8
9
katex.render("c = \\pm\\sqrt{a^2 + b^2}", eq1);
katex.render("f(a,b,c) = (a^2+b^2+c^2)^3", eq2);

katex.render("\\int u \\frac{dv}{dx}\\,dx=uv-\\int \\frac{du}{dx}v\\,dx", eq3);

katex.render("f(x) = \\int_{-\\infty}^\\infty \\hat f(\\xi)\\,e^{2 \\pi i \\xi x}", eq4);
katex.render("\\oint \\vec{F} \\cdot d\\vec{s}=0", eq5);

katex.render("\\left( \\sum_{k=1}^n a_k b_k \\right)^2 \\leq \\left( \\sum_{k=1}^n a_k^2 \\right) \\left( \\sum_{k=1}^n b_k^2 \\right)", eq6);

The comparison between MathJax and KaTeX can be found here. At the time of writing this blog post, I got KaTeX is faster than MathJax. But KaTeX can not render a few expressions that MathJax can.

The comparison results could be changed in the next. Since both of them are actively developed.

Create iOS Ipa for In-House Distribution

| Comments

Couple of month ago in the era of iphone 6, the company I work for was officially migrate official mobile device from BlackBerry to iphone 6. By the time of migration, development team also got initiative request from users to create an app for android. On the other hand, we also want to anticipate another request for ios platform. To simplify the porting to another platform, we use HTML5, Kendo UI and Apache Cordova to build the app. The app just consumes data from REST services. The other requirement is the app will not be published to App Store. We have internal mobile device management (MDM) called MobileIron.

In this post, I will not write about how to build the app with Apache Cordova, I just want to focus on how to create ipa distribution package for in house enterprise distribution. The steps should be the same for app that is created with native. I also will not discuss about how to deploy to MDM.

The first requirement is we have to be a member of iOS Developer Enterprise Program which costs $299. The steps how to register is clearly explained in apple developer site.

At the time of write this post, my development environment :

  1. OS X El Capitan (10.11.3)
  2. Xcode (7.2)
  3. iphone 6 (iOS 9.2)

Before we start create ipa package, ensure our code runs well as expected on iphone simulator.

The steps of creating ipa package for distribution basically similar to deploying to real device for development as explained on my previous post. In this post, I will only capture the things that are difference between them.

Certificate

While creating certificate preparation in Apple Developer portal, showed its slightly difference from my previous post

In this case, I choose In-House and Ad Hoc distribution option instead of iOS App Development, since we plan to create ipa package for In House distribution. If we notice upon the above screenshot, in the Production section has option for In-House and Ad Hoc distribution. Meanwhile on my previous post has App Store and Ad Hoc. The difference because of the apple id I used on this post is enrolled as an iOS Developer Enterprise Program, and on my previous post uses Individual Apple Developer Program. The detail difference between them and other developer license schema can found here.

The rest of preparing certificate installation for production is the same as certificate installation for development.

App IDs

The step of registering app Bundle ID is the same as the previous post. If we already registered for development, we should not do it again.

Provisioning Profiles

Creating provisioning also similar to the creation Provisioning for Development. Except at the wizard option we need to choose one of in the Distribution group instead of Development group. In this sample I select In House, since the ipa package we created will be deployed via MDM.

The next step is opening Xcode and add apple id via Xcode Proferences > Accounts as I did on previous post. Now we should get the similar picture as follow.

Ensure distribution profile already downloaded. If not we can click download button on the list above of picture.

The next thing is opening iOS project with Xcode and ensuring we select Distribution Profile we installed on Code signing section group both on Project and Target.

The next step is select Product menu > Archive, then follow the wizard.

When the wizard finish, by default Xcode will create ipa package for us on desktop.

That’s all my share and thanks for reading :)

Deploying iOS App to Real Device

| Comments

While developing ios app, sometime we don’t just testing run the app on ios simulator we also need to test the app on real device though.

The are couple of things that we need to prepare to make our app be able to run on real devices.

Certificate

Development certificate basically tells us that we are apple developers. To be it, our apple id has to be enrolled as an apple developer. Information about apple developer enrollment can be found at Apple Developer site.

Once our apple id enrolled as an apple developer, there are couple of steps for preparing development certificate. App need to be signed to be able to deployed to real devices. To do that:

  1. Go to Launchpad or Spotlight Search, type Keychain Access then open the app.
  2. At top menu, click Keychain Access > Certificate Assistance > Request a Certificate from a Certificate Authority

    Fill the Email and Common Name. The email should be apple id email then select save to disk and checked Let me specify key pair information. When we click continue, we should get save dialog

    Select Key Size 2048 bits and RSA algorithm, click continue then done.

    The certificate request that we create just saved to disk (desktop in my case).

  3. Open apple developer portal, login using apple id that already enrolled as apple developer.

    click Certificates, Identifiers and Profiles

  4. Select Sertificates group > All

    On the right pane, select add (+) button, select type of certificate that we want to create. At this post we will create for development only. Not for production such as for deploy our app in app store nor internal store (in-house) like mobile device management.

    If everything already done on this page, scroll down > click continue

    We may notice a information message that we have to ensure on our OS X development machine keychain installed Worldwide Developer Relations Certificate Authority

  5. Follow the wizard, till we’re asked to upload our certificate request that we already created on previous step.

  6. After completed the wizard, we should be able to download the generated certificate and ready to install on development machine.

  7. Download the development certificate > double click. The certificate should be installed on our Keychain Access

    NOTE : Please ignore the distribution certificate on my screenshot. It just another certificate for distribution which is out of scope of this post.

Devices

This part informs to the xcode that the device is belongs to me. So let me run my app on it. To register our devices, select Devices on the apple developer portal as we did for certificate section above.

Click add (+)

Enter Name and UUID. To get UUID, plug idevice to computer, itune will display it. If itune display Serial Number or ECID or Product Type, click the label till UUID displayed. Just copy it and paste in the UUID text box above.

Follow the wizard till finish. We should be able to get our idevices listed on the device list.

App IDs

On Apple developer portal mentioned that an App ID is a string that defines both a keychain identity and a set of apps you are developing. Its primary use is as part of a provisioning profile, it specifies which apps are authorized by the profile to be signed and launched.

To register App ID, click Add (+). Fill Name and Bundle ID.

In this sample, my application Name is HelloWorld and Bundle ID is com.neutrofoton.helloworld

Click continue till the wizard dialog finished. We can get list all of App IDs that we registered by clicking the App IDs on the left menu panel

Provisioning Profiles

On Apple Developer portal Provisioning Profiles defined that it allows us to install apps onto our iOS devices. A provisioning profile includes signing certificates, device identifiers, and an App ID. Development provisioning profiles are used to build and install versions of our app during the development cycle, while distribution provisioning profiles are used to submit our apps to the App Store and distribute them to beta testers.

To start create provisioning, click add (+) select iOS App Development. In this case I will create provisioning for test. For distribution we select on distribution group option as our need.

Follow the wizard by selecting App ID, Devices, and Certificates that will be applied to the Provisioning Profile

Now open Xcode > Preferences select Accounts tab. Add apple id that we use for login to apple developer portal.

Select the apple id on the left pane > click View Details button. We should get the similar picture as below.

If the profiles are not downloaded yet, we can click Download button that make Xcode do for us.

To test provisioning we created, let’s create simple application. At the time of write this post, my development environment :

  1. OS X El Capitan (10.11.3)
  2. Xcode (7.2)
  3. iphone 4s iOS 9.1

Ensure we have the same Bundle Identifier as we registered on Provisioning Profile. At this sample app, I just create a simple lable Hello World Application on storyboard.

Now run the application by selecting Device instead of Simulator. We may get the following message while running on real device, just click Allow

The above picture shows that the Hello World app can be run on real device.

From WordPress to Octopress

| Comments

I have just migrated my blog engine from WordPress to Octopress. After exploring (googling) for hours about it, how to install, customize, hosting etc, finally I got a decision :

Ok I will migrate my blog to Octopress.

Octopress is a framework designed for Jekyll, the static blogging engine powering Github Pages. In this post, I will not write detail about Octopress. Many complete articles out there available to be as reference.

The reasons that make me interest in Octopress are :

  1. No database needed
  2. Hosting does not have to have php support
  3. Using Markdown
  4. Having nice project structure, very intuitive to customize it. Just need html, would be better if have ruby knowledge but not have to
  5. Supported by github, so can use terminal to post articles
  6. Many plugin support
  7. Can use any simple text editor like Atom, Sublime, Notepad++ or even Vim etc

I plan will not maintain http://www.neutrofoton.com anymore. Even though at the time of this blog post the site is still accessible and maybe some articles visible on google search. In case the links are broken, please kindly find the related articles on https://neutrofoton.github.io

The last, I would say thank you very much to WordPress for had been my platform writing blog, and welcome Octopress for being the new one :)

Extract C# Exception

| Comments

Throwing or catching exception strategy on building an application is a very important to get detail exception message, inner exception and detail strack trace where or which part of line of code that fired the exception.

The following snipped code shows how to extract detail exception message, innner excepion and its detail strack trace to be recorded / written on log.

exception extractor
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/// <summary>
    /// Extracting <seealso cref="System.Exception"> class include its inner exception
    /// </seealso></summary>
    public sealed class Extractor
    {
        /// <summary>
        /// Parse the specified ex.
        /// </summary>
        /// <param name="exception">Ex.
        public static string Parse(System.Exception exception)
        {
            string errMessage = Environment.NewLine;

            errMessage += FormatErrorDescription(exception);

            while (exception.InnerException != null)
            {
                errMessage += ExtractInnerException(exception.InnerException);
                exception = exception.InnerException;
            }

            errMessage += Environment.NewLine;

            return errMessage;
        }



        /// <summary>
        /// Extract exception message and its strack trace
        /// </summary>
        /// <param name="innerException">inner excepion object
        /// <returns>extracted exception info including message and strack trace</returns>
        static string ExtractInnerException(System.Exception innerException)
        {
            string errMessage = string.Empty;

            errMessage += Environment.NewLine + " InnerException ";
            errMessage += FormatErrorDescription(innerException);

            return errMessage;
        }

        /// <summary>
        /// Formating exception description format
        /// </summary>
        /// <param name="exception">
        /// <returns>Error description</returns>
        static string FormatErrorDescription(System.Exception exception)
        {
            if (exception == null)
                return string.Empty;

            return Environment.NewLine + exception.Message + Environment.NewLine + exception.StackTrace;
        }
    }

Get Excel Column Name by Index and Vice Versa

| Comments

I used to got a need to build small and simple plugin for Excel using VSTO. But I won’t write about VSTO in this post. The thing that I want to share is just a simple code to get excel column name by index and vise versa. I felt it was very important for me cause I worked intensively with index at that project.

excel helper
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
public class ExcelUtility
    {
        /// <summary>
        /// Convert Excel column name into number/index. Column number start from 1. A equal to 1
        /// </summary>
        /// <param name="columnName">Column name
        /// <returns>Excel column in numeric</returns>
        public static int GetExcelColumnNumber(string columnName)
        {
            if (string.IsNullOrEmpty(columnName))
                throw new ArgumentNullException("Invalid column name parameter");

            columnName = columnName.ToUpperInvariant();

            int sum = 0;

            char ch;
            for (int i = 0; i < columnName.Length; i++)
            {
                ch = columnName[i];

                if (char.IsDigit(ch))
                    throw new ArgumentNullException("Invalid column name parameter on character " + ch);

                sum *= 26;
                sum += (ch - 'A' + 1);
                //sum += (columnName[i] - 'A');
            }

            return sum;
        }

        /// <summary>
        /// Convert Excel column index into name. Column start from 1
        /// </summary>
        /// <param name="columnNumber">Column name/number
        /// <returns>Column name</returns>
        public static string GetExcelColumnName(int columnNumber)
        {
            int dividend = columnNumber;
            string columnName = String.Empty;
            int modulo;

            while (dividend > 0)
            {
                modulo = (dividend - 1) % 26;
                columnName = Convert.ToChar(65 + modulo).ToString() + columnName;
                dividend = (int)((dividend - modulo) / 26);
            }

            return columnName;
        }
    }
sample code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
class Program
    {
        static void Main(string[] args)
        {
            try
            {
                string columnName = "A";

                int columnIndex = ExcelUtility.GetExcelColumnNumber(columnName);

                Console.WriteLine("Index of {0} is {1} ", columnName, columnIndex);

                //increment columnIndex
                ++columnIndex;

                Console.WriteLine("Increment index = " + columnIndex);

                columnName = ExcelUtility.GetExcelColumnName(columnIndex);
                Console.WriteLine("Column name of index {0} is {1}", columnIndex, columnName);

            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            Console.Read();

        }
    }

I write the code in my blog just to remind me in the future in case I get the same need. And it would be great if it can help others who have the same need as me :)

Reference

  1. http://stackoverflow.com/questions/181596/how-to-convert-a-column-number-eg-127-into-an-excel-column-eg-aa
  2. http://stackoverflow.com/questions/667802/what-is-the-algorithm-to-convert-an-excel-column-letter-into-its-number

ASP.Net MVC 4 in Xamarin Studio

| Comments

Xamarin Studio is a great Mono IDE (Integrated Development Environment) in OS X area. At the time of writing this article, the version of Xamarin studio and mono framework I use are : Xamarin Studio Version 4.2.1 (build 1) Runtime: Mono 3.2.5 ((no/964e8f0) GTK+ 2.24.20 theme: Raleigh GTK# (2.12.0.0) Package version: 302050000

Xamarin Studio includes with ASP.NET MVC 2 and 3 project template. While trying to create ASP.NET MVC 3 project, I got couples of errors such as authorization access etc. The good news is even though there is no project template for ASP.NET MVC 4, we still can convert our ASP.NET MVC 3 to run as ASP.NET MVC 4. The steps are :

  1. Create an ASP.NET MVC 3 project either with aspx or razor view engine
  2. Run the project via Xamarin studio menu (Run > Run With > Mono Soft Debugger for ASP.NET. While running the project, we may got an error message :
    1
    2
    3
    4
    5
    6
    7
    8
    
    System.UnauthorizedAccessException
    Access to the path "/Library/Frameworks/Mono.framework/Versions/3.2.5/etc/mono/registry" is denied.
    
    Description: HTTP 500.Error processing request.
    Details: Non-web exception. Exception origin (name of application or object): mscorlib.
    Exception stack trace:
    
    ......
    
    To solve the error, run the following command in terminal :
    1
    2
    
    sudo mkdir /Library/Frameworks/Mono.framework/Versions/3.2.5/etc/mono/registry
    sudo chmod g+rwx /Library/Frameworks/Mono.framework/Versions/3.2.5/etc/mono/registry
    
  3. Re-run again the ASP.NET MVC project. We may get another error message.
    1
    2
    3
    4
    5
    6
    7
    8
    
    System.IO.FileNotFoundException
    Could not load file or assembly 'System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
    
    Description: HTTP 500.Error processing request.
    Details: Non-web exception. Exception origin (name of application or object): mscorlib.
    Exception stack trace:
    
    ...
    
    To solve the error message, just use NuGet package manager, search for “ASP.NET MVC 4″ and add reference to it and its dependencies.
  4. Re-run the ASP.NET MVC again. Now we may get another error message as following :
    1
    2
    3
    4
    5
    6
    7
    8
    
    System.InvalidOperationException
    Conflicting versions of ASP.NET Web Pages detected: specified version is "1.0.0.0", but the version in bin is "2.0.0.0". To continue, remove files from the application's bin directory or remove the version specification in web.config.
    
    Description: HTTP 500.Error processing request.
    Details: Non-web exception. Exception origin (name of application or object): System.Web.WebPages.Deployment.
    Exception stack trace:
    
    ...
    
    As the error message, we need to make our ASP.NET Web Pages version to 2.0.0.0 in web.config. So just open web.config and change webpages:Version to 2.0.0.0. as follow :
    web.config
    1
    2
    
    <add key="webpages:Version" value="2.0.0.0">
    </add>
    
  5. Change assembly version declared in root web.config and /View/web.config of the following

    assembly from to

    System.Web.WebPages.Razor 1.0.0.0 2.0.0.0
    System.Web.Mvc 3.0.0.0 4.0.0.0

Now re-run the project again via Xamarin Studio and our project should run well as expected.

References

  1. http://curtis.schlak.com/2013/09/29/setup-asp-net-mvc-4-on-monodevelop.html

Xcode Failed to Download Use the Purchases Page to Try Again

| Comments

The following day after the release of iOS 7, I started update my iphone 4s to get to know how exactly the ios 7 is. My iphone successfully updated even though it was quite annoying with slow internet connection :( .

The next thing is updating my Xcode, since I got a notification to update my xcode from version 4.6.3 to version 5.0 via app store of version 1.2.2. My OSX version is 10.8.5. While updatig process, several times I got error message Xcode failed to download use the purchases page to try again, and my download prosess suddenly stopped. Googling on internet and asking forum got many different suggestion and solution. Thankfully one of them success that is by clearing appstore download cache.

The steps to get things to work are quite simple.

  1. Keep the AppStore App open. Open terminal and type
    1
    
    cd /private/var/folders/
    
    Once there, search for com.apple.appstore
    1
    
    find . | grep com.apple.appstore
    
    You will find folder structure like this ./40/lhn22jn901zdw2bpf82hkggw0000gn/C/com.apple.appstore
  2. Once inside the folder, open it in finder
    1
    
    open .
    
  3. While keeping AppStore open, remove this folder
    1
    
    rm -rf *
    
  4. Now, go back to AppStore and click on Download again.
  5. If download/update disappear, close the appstore then reopen it.

That steps worked well to me. Good luck and have a nice day.

References

  1. http://apple.stackexchange.com/questions/61646/xcode-failed-to-download-use-the-purchases-page-to-try-again/71202#71202

Unsupported IClasspathEntry in Eclipse-STS

| Comments

I often got annoying pup up error message. An internal error occurred during updating Maven project. The message was Unsupported IClasspathEntry kind=…

Googling for that problem finally got a trick how to resolve it.

  1. Right-click on your project, select Maven > Disable Maven Nature
  2. Open your terminal, go to your project folder and do
    clean eclipse cache
    1
    
    mvn eclipse:clean
    
  3. Right click on your Project and select Configure > Convert into Maven Project

After converting into maven project, I can update my maven project and everything running well :)