Tuesday, January 19, 2016

Add resources from Resources.resx to XAML

You may have tried this technique gleaned from the Internet in order to change your WPF GUI's text at runtime according to the language.
When you write the next snippet in your Window's XAML for adding resources from the Resources.resx file and rebuild and run in Visual Studio 2015,

<Window
    ...
    xmlns:props="clr-namespace:MyProject.Properties" 
    >
    <Window.Resources>
        <props:Resources x:Key="LocalResources" />
    </Window.Resources>
    <Window.BindingGroup>
        <BindingGroup Name="localization"/>
    </Window.BindingGroup>
    <Window.Title>
        <Binding Path="WindowTitleStringName"
                 Source="{StaticResource LocalResources}"
                 BindingGroupName="localization"/>
    </Window.Title>
    <Label Content="{Binding LabelContentStringName,
                             Source={StaticResource LocalResources},
                             BindingGroupName=localization}"
        ...
       />
</Window>
// Change to the default Resources.resx in MyWindow.cs
Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture ;
Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture ;
BindingGroup.BindingExpressions
    .Where( be => be.BindingGroup.Name=="localization" )
    .ToList().ForEach( be => be.UpdateTarget() );

the next exception is thrown.

System.Windows.Markup.XamlParseException / System.MissingMethodException :
    No matching constructor found on type MyProject.Properties.Resources.
    You can use the Arguments or FactoryMethod directives to construct this type.

If you slightly modify Resources.Designer.cs like adding meaningless spaces and just build(not rebuild) and run, the exception is not thrown any more.

Even so, this can be a problem when this app is built in an automated build system.

In order to solve this problem, derive your own Resources class from MyProject.Properties.Resources  and use it with the already defined "local" namespace in your xaml like the next.
namespace MyProject
{
    public class Resources 
        : Properties.Resources
    {
        public Resources()
        {
        }

    }  // End Of Class
}

<Window
    ...
    xmlns:props="clr-namespace:MyProject.Properties"
    >
    <Window.Resources>
         <local:Resources x:Key="LocalResources" />
    </Window.Resources>
    ...
</Window>

Tuesday, March 24, 2015

Spring REST and wildcard url-pattern in web.xml

The wildcard url-pattern '/api/*' in web.xml doesn't work with Spring REST @RequestMapping's absolute path like '/api/customers'.
@RequestMapping's relative path without any leading slash like 'customers' does work.

In web.xml
  <servlet-mapping>
    <servlet-name>dispatcher</servlet-name>
    <url-pattern>/api/*</url-pattern>
    <url-pattern>*.htm</url-pattern>
  </servlet-mapping>

In your java source code
 @RequestMapping( "customers" )

Now you can use the URL 'http://myserver.com/api/customers'.

Sunday, December 7, 2014

Gitblit with Active Directory

[ERROR] Error Connecting to LDAP
LDAPException(resultCode=49 (invalid credentials), errorMessage='80090308: LdapErr: DSID-0C0903A9, comment: AcceptSecurityContext error, data 52e, v1db1 ', diagnosticMessage='80090308: LdapErr: DSID-0C0903A9, comment: AcceptSecurityContext error, data 52e, v1db1 ')
This could be the wrong password.
So I tested with my personal Active Directory account and it worked.
realm.authenticationProviders = ldap
realm.ldap.server = ldap://192.168.0.2
realm.ldap.username = [DOMAINNAME]\\duncansungwkim
realm.ldap.password = [YourPassword]
realm.ldap.accountBase = CN=Users,DC=[domainname],DC=[your-org],DC=com
Any Active Directory account in the "Domain Users" group will work.
In fact, you should ask your Active Directory administrator for the password of a special account that is only for anthentication. That account should be only in the "Domain Users" group, which I believe has the least rights.

Tuesday, April 1, 2014

Workaround of git Shallow Clone with Submodules

You can clone a git repo only with the most recent revision by using git's "shallow clone" as the following
command.
$ git clone --depth 1 https://github.com/MyRepo.git

If you have submodules, you would use the option --recursive as follows
$ git clone --depth 1 --recursive https://github.com/MyRepo.git
And you would expect that the submodules are also shallowly cloned, but they are actually full clones.

You can work around this problem by using consecutive commands in one line like the next
$ git clone --depth 1 https://github.com/MyRepo.git ; cd MyRepo ; git submodule update --init --depth 1
If you use Windows, use &(ampersand) instead of ; (semicolon).
C:\> git clone --depth 1 https://github.com/MyRepo.git & cd MyRepo & git submodule update --init --depth 1
This is such a primitive solution. However, this was really a good tip for using git for build automation.

One of my build jobs kept failing with the following error message.
error: RPC failed; result=56, HTTP code = 200
fatal: The remote end hung up unexpectedly
fatal: early EOF
fatal: index-pack failed

It is said that this problem is caused by too big a git repo, maybe with over 20MB. I had big submodules but they were big due to its history. So I thought of the shallow clone, but it didn't work because git doesn't propagate the depth setting to the submodules when I use --recursive option. I couldn't wait for a new git version to fix this. Now I divided and conquered it.

Tuesday, December 3, 2013

C++ Exception Finally stand in

C++ has no equivalent of "finally" in the exception handling construct. So I wrote a class named Finally which can be used instead as "finally" in other languages. This only works in C++11 because this makes use of lambda.
#include <functional>
#include <array>
#include <assert.h>

template< std::size_t N >
class Finally
{
public:
    Finally() : m_uCount(0) {}

    typedef std::function<void()> deleter_type ;
    void operator += ( const deleter_type&& a_deleter )
    {
        assert( m_uCount < N ) ;
        if( m_uCount >= N ) return ;
        m_deleters[m_uCount++] = a_deleter ;
    }

    ~Finally()
    {
        for( int i=int(m_uCount)-1 ; i>=0 ; --i )
        {
            m_deleters[i]() ;
        }
    }

private:
    std::array<deleter_type,N> m_deleters ;
    size_t m_uCount ;

    Finally( const Finally& ) /* = delete */ ;
    Finally( Finally&& )  /* = delete */ ;
    void operator=( const Finally& ) /* & = delete */ ;
    void operator=( Finally&& ) /* & = delete */ ;
};
Following is a code snippet which my Finally class is applied to.
#include <stdlib.h>
#include "Finally.h"

void Test( int a_iException )
{
    Finally<3> finally ;
    FILE* pFile = ::fopen( "Test", "w" ) ;
    finally += [ pFile ]
    {
        if( NULL != pFile )
            ::fclose( pFile ) ;
    } ;

    try
    {
        if( 2 == a_iException )
            throw 2 ;
    }
    catch( std::logic_error& e )
    {
         throw ;
    }
}

int main()
{
    try
    {
        Test( 1 ) ;
        Test( 2 ) ;
    }
    catch( int iExc )
    {
        assert( 2 == iExc ) ;
    }
    return 0 ;
}

Tuesday, October 9, 2012

SmartSVN External Conflict Solver Arguments

KDiff3

${leftFile} ${baseFile} ${rightFile} -o ${mergedFile}

Wednesday, August 1, 2012

Select All the Keys at One Frame in Curve Editor

Whenever I used [Curve Editor] in 3ds Max, I always wondered why I couldn't easily vertically select all the keys at one frame. Now I have figured out the easy way. I should use [Track Bar] for it. Because [Track Bar] is away from [Curve Editor], they seemed to be so unrelated that I couldn't realize it, but the method seems to be official.
I'll show you the picture. Note those red rectangles.
As shown in the picture, if you select a collective key on [Track Bar] at the bottom, it gets highlighted and the corresponding keys in a pillar in [Curve Editor] in the separate floating window also get highlighted.
You can also move a pillar of keys in [Curve Editor] by grabbing and dragging the correspodning collective key on [Track Bar].
As a matter of fact, you don't need to use [Curve Editor] so as to deal with the all the key at one frame. You have only to use [Track Bar] for it.