Friday, 7 December 2012

Basic vi colors on mac os x

vi ~/.vimrc

paste lines:

set nocompatible
syntax on
:wq
enjoy

Sunday, 25 November 2012

Testing with embedded mongodb

If you have to use embedded mongodb instance for testing there is a foursquare implementation called Fongo. You will have to install it locally or deploy it into your intranet repository in order to use with maven.

In order to use it with spring-data-mongodb you can use something like


1:  <bean id="mongoOperations" class="ru.sample.dal.utils.ImMemoryMongoFactory" factory-method="provide" scope="prototype"/>
2:  
3:  <bean id="mongoTemplate" class="ru.sample.dal.utils.ImMemoryMongoFactory" factory-method="provide" scope="prototype"/>
4:  
5:  public class ImMemoryMongoFactory {
6:    private static Fongo fongo = new Fongo("name");
7:  
8:    public static MongoOperations provide() {
9:      return new MongoTemplate(fongo.getMongo(), "database");
10:    }
11:  }


and just autore MongoOperations in your custom repository implemenations. Basic implementation of repositories should start using those beans by default too

Saturday, 24 November 2012

Stable WADL Maven plugin.

If your project is currently using

<dependency>
<groupId>org.jvnet.ws.wadl</groupId>
<artifactId>wadl-maven-plugin</artifactId>
<version>1.1-SNAPSHOT</version>
</dependency>
 and you are looking for stable version of a plugin, you should be using following:

<groupId>org.jvnet.ws.wadl</groupId>
<artifactId>wadl-client-plugin</artifactId>
 <version>1.1.3</version>
this is the most recent and least bogous version of plugin. Nothat you will have to refactor code if you was using client generated by wadl plugin. Also note that to reach endpoints with compound paths like
"/{classPath}/{methodPath}"  you will have to create java instance of generated client's {classPath} instance first and get reference to {methodPath} inner class instance from it in order for client to build URI's appropriately.

Wednesday, 17 October 2012

Profiling application on Tomcat with jVisualVM

jVisualVM allows to gater information about applications through JMX connection, which I had to use even for local tomcat.

Add following arguments to startup profile:
-Dcom.sun.management.jmxremote.port=8086
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false
Once that done add connection and start samplingapplication

Saturday, 25 August 2012

Fixing image size of Raphael.js image in IE8.

Raphael.js is using VML instead of SVG in IE6-8.
While most of the functionality was working fine for me, I've found out that .image is rendered with corrupted size.

After few hours of debug I've figured out that VML implementation is missing measurement points in image tag size definition.


Line number 4952 missing “pt” constant that has to be present in VML tag. So just changing 
fill.size = _.fillsize[0] * abs(sx) + S + _.fillsize[1] * abs(sy);
to something like

fill.size = _.fillsize[0] * abs(sx)/1.34 + "pt" + S + _.fillsize[1] * abs(sy)/1.34 + "pt";
helped me out. 
Side note: still had to division by constant to scale appropriately.

Wednesday, 16 May 2012

Git - ssh authentication with key on windows.

Git - ssh authentication with key on windows.
As I've noticed there is a common problem setting up ssh connection with remote git repo without having to enter your password all the time. If you follow all "standard" procedures you'll be getting something like:
Access denied
fatal: The remote end hung up unexpectedly 
I don't know why this is happening, don't even want to know. So here is a quick recepie to avoid that.

1. set GIT_SSH environment variable to point to plink.exe [C:\putty\plink.exe]
2. ssh to remote host where repo is
3. cd ~
4. mkdir .ssh
5. cd .shh
6. ssh-keygen -t dsa (hit enter all the time)
7. cat id_dsa.pub >> authorized_keys
8. copy id_dsa to your windows machine (somewhere)
9. run puttygen.exe
10. press "Load" - open id_dsa file
11. press "Save private key" (save somewhere)
12. run pageant.exe
13. add key that you saved fro puttygen to pageant
14. git clone...
Should be working from now on, without need to provide password all the time.
Adapted from here

Tuesday, 1 May 2012

Sphinx4 custom acoustic model files notes.

The whole process of creating custom acoustic model is described here.
Read it thoroughly. If you are still not getting what are the required files and where to get them from this note is for you.

Given that structure is:

  1. etc
    1. your_db.dic - Phonetic dictionary
    2. your_db.phone - Phoneset file
    3. your_db.lm.DMP - Language model
    4. your_db.filler - List of fillers
    5. your_db_train.fileids - List of files for training
    6. your_db_train.transcription - Transcription for training
    7. your_db_test.fileids - List of files for testing
    8. your_db_test.transcription - Transcription for testing
  2. wav
    1. speaker_1
      1. file_1.wav - Recording of speech utterance
    2. speaker_2
      1. file_2.wav


Following files could be built by lmtool web service :
  1. your_db.dic - 
  2. Phonetic dictionary
  3. your_db.phone - Phoneset file
  4. your_db.filler - List of fillers
after you've got those files ready, you'll need .DMP file:
  1. your_db.lm.DMP - Language model
it is generated from .lm file with sphinx_lm_convert programm which is shipped with sphinxbase-7.0 archive. See this section on installation instructions of sphinxbase. You should use following commands to generate this file:

 sphinx_lm_convert -i model.lm -o model.dmp
sphinx_lm_convert -i model.dmp -ifmt dmp -o model.lm -ofmt arpa
After you've got that running, you should list all audio files that you want use for training and their matching phrases in remaining files:
  1. your_db_train.fileids - 
  2. List of files for training 
  3. your_db_train.transcription - Transcription for training

Ubuntu 11.10 install sphinxbase.

Ubuntu 11.10 install sphinxbase.

There is a good manual at http://cmusphinx.sourceforge.net/wiki/tutorialpocketsphinx
Anyways. After you've downloaded and unpacked sphinx-0.7 archive

1. ./autogen.sh (It won't start right away, but will print what software packages are missing)
2. sudo apt-get install autoconf
3. sudo apt-get install libtool
4. sudo apt-get install automake
5. sudo apt-get install bison
6. sudo ./autogen.sh
8. sudo make
9. sudo make install 
10. export LD_LIBRARY_PATH=/usr/local/lib
Now try
sphinx_lm_convert
If you can see following message:
 ERROR: "cmd_ln.c", line 675: No arguments given, available options are:
Arguments list definition:
[NAME] [DEFLT] [DESCR]
-case Ether 'lower' or 'upper' - case fold to lower/upper case (NOT UNICODE AWARE)
-debug Verbosity level for debugging messages
-help no Shows the usage of the tool
-i Input language model file (required)
-ienc Input language model text encoding (no conversion done if not specified)
-ifmt Input language model format (will guess if not specified)
-logbase 1.0001 Base in which all log-likelihoods calculated
-mmap no Use memory-mapped I/O for reading binary LM files
-o Output language model file (required)
-oenc utf8 Output language model text encoding
-ofmt Output language model file (will guess if not specified)
Than everything works fine.
NOTE: this is required step to start training your own acoustic models for CMU Sphinx 4. 

Thursday, 26 April 2012

Spring-MongoDB: Checking if data member is of array type in map function.

If you'll ever have to do things like that, following code worked out perfectly for me:
if( Object.prototype.toString.call( myObj ) === '[object Array]' ) {}
source: http://stackoverflow.com/questions/4775722/javascript-check-if-object-is-array 

Spring-MongoDB: debugging map\reduce on ubuntu.

while using Spring-data-MongoDB on ubuntu system, with default mongo installation you migh be experiencing troubles with error messages, as they might look similar to this:
InvalidDataAccessApiUsageException: Command execution failed:  Error [db assertion failure], Command = { "mapreduce" : ... }
The error message will include whole command, an will give you no clues about what actually went wrong. Try executing following command from terminal and repeat issue:
 tail -f /var/log/mongodb/mongodb.log 
trace information will get printed to log and you'll see it in terminal.  You should be looking for messages as following:

 JS Error: TypeError: myVar has no properties nofile_b:69
You can also add print to log in map\reduce functions with print("...") method invocation.
print('variable state is : ' + myVar) ;

 

Tuesday, 24 April 2012

Spring-Data-MongoDB passing scope variables to map\reduce

Spring-Data-MongoDB passing scope variables to map\reduce:

It's becoming a little bit tricky if you want to pass something like wrapper that contains Map of Map's as a parameter to map\reduce.

Anyhow, If you'll find yourself in trouble passing parameters to map\reduce here is one way to handle it:


MapReduceOptions options = MapReduceOptions.options();
Map vars = new HashMap();
        try {
            ObjectMapper mapper = new ObjectMapper();
            DBObject dbo = new BasicDBObject(mapper.convertValue(myobject, Map.class));
            vars.put("myparamName",dbo);
        } catch (Exception e) {
            logger.error(e);
        }
        options.scopeVariables(vars);
this way scope parameter will be passed as a pure JSON map object, which will be automatically mapped to js object by MongoDB.

ObjectMapper is a Jackson framework class.

Saturday, 21 April 2012

JSON serialization of JS objects with Spring.

JSON serialization of JS objects with Spring.

Problem: pass JS object from spring MVC enabled backend to HTML page, use eval (...) on object and invoke function that have been passed from backend.

Solution: By default Spring framework is using Jackson to serialize Java objects. During that serialization all members are passed as strings, while we'd like to have data structure as following:

{
    member1 : "value1",
    action : function() {
             ...
    }
}
with such an object it would be possible to do the following to invoke function:
 obj.action()
 In order to do that one would have to implement custom serializer class

public class MySerializer extends JsonSerializer<MyTO> {
    public void serialize(MyTO value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException {
        jgen.writeStartObject();
        jgen.writeObjectField("member1", value.getMember1());
        jgen.writeFieldName("action");
        jgen.writeRaw(":" + value.getAction());
    }
}

Done. use eval on front end to convert JSON into actual JS object and enjoy. 

Ubuntu 11.10 installing CMU Sphinx 4.

Ubuntu 11.10 installing CMU Sphinx 4.

The process is fairly straightforward:

1. Install Oracle JDK (I've used version 1.6)
2. install ant
sudo apt-get install ant
3. install sharutils
sudo apt-get install sharutils
4. navigate to desired folder
cd /usr/share
5. install svn
sudo apt-get install subversion
6. checkout files
sudo svn co https://cmusphinx.svn.sourceforge.net/svnroot/cmusphinx/trunk/sphinx4
7. run jsapi.sh
sudo sh ./sphinx4/lib/jsapi.sh
8. build project
cd sphinx4 sudo ant

Next steps will take you to the journey of creating a real project.