Custom Search

Sunday, December 21, 2008

Creating a new user in mysql

If we want to create a new user in mysql , we can use the following command.


mysql > create database newdb
> grant all privileges on newdb.* to newuser@"localhost" identified by 'newpassword';


This would create the new user identified by that username and password. This can be validated by logging in again.


mysql > mysql -u newuser -p
Enter password:

So - now we have created this user and password and tested the same.

Thursday, December 18, 2008

Solr - Http Caching enabled by default - how to disable the same.

Solr is a system , that provides service access (among many other things)  to the underlying Lucene implementation  and provides a much faster distributed search indexing / retrieval feature.

Much of the configuration in the Solr application is based on solrconfig.xml in the solr.solr.home directory .  Among the important set of options - that might be useful for development is ( especially when testing responses over the browser ) could be, disabling http caching so as to not to continue to clear the browser cache before viewing the page.

This is done as follows, by setting the never304 ,attribute to be true for httpCaching as follows.

<httpcaching never304="true" .... />



This should disable httpCaching so that we do not need to refresh the browser. But for the deployment in production - make sure to deploy the same with the property false ,(as it was by default).

Tuesday, December 16, 2008

JMeter - JUnit Sampler

JMeter has a JUnit sampler since release  . More details are available in the following PDF.  I will post an example once I get my first cut example working on the same.

Wednesday, December 10, 2008

Encryption library for Java - JBCrypt

I was looking for a good encryption library for Java.

The JBCrypt library (ported from BCrypt, a C++ implementation) is a very useful one for the given purpose.

An introductory article in GWT incubator discusses the plugin in detail.

Tuesday, December 9, 2008

Lucene 2.4.0 - Hello World

Lucene 2.4.0 - Hello World application to play around with indexing / searching capabilities of Lucene. The original code is attributed to Lucene tutorial mentioned here.

Some of the API in the code like Hits have been deprecated that creates costly Document objects. The revised code, after addressing compilation warnings is shown herewith.




import java.io.IOException;

import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriter.MaxFieldLength;
import org.apache.lucene.queryParser.ParseException;
import org.apache.lucene.queryParser.QueryParser;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.ScoreDoc;
import org.apache.lucene.search.TopDocs;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.RAMDirectory;

public class HelloLucene {
public static void main(String[] args) throws IOException, ParseException {
// 1. create the index
Directory index = new RAMDirectory();
IndexWriter w = new IndexWriter(index, new StandardAnalyzer(), true, new MaxFieldLength(25000));

addDoc(w, "Lucene in Action");
addDoc(w, "Lucene for Dummies");
addDoc(w, "Managing Gigabytes");
addDoc(w, "The Art of Computer Science");
w.close();

// 2. query
String querystr = args.length > 0 ? args[0] : "lucene";
Query q = new QueryParser("title", new StandardAnalyzer()).parse(querystr);

// 3. search
IndexSearcher s = new IndexSearcher(index);
TopDocs docs = s.search(q, null, 100);

// 4. display results
System.out.println("Found " + docs.totalHits + " hits.");
ScoreDoc [] hits = docs.scoreDocs;
int i = 0;
for(ScoreDoc scoreDoc : hits) {
System
.out.println((i + 1) + ". " + s.doc(scoreDoc.doc) );
++i;
}
s.close();
}

private static void addDoc(IndexWriter w, String value) throws IOException {
Document doc = new Document();
doc.add(new Field("title", value, Field.Store.YES, Field.Index.ANALYZED));
w.addDocument(doc);
}
}

Thursday, December 4, 2008

GWT - 1.5.3 - Ubuntu - libstdc++.so.5: cannot open shared object file

Started my work successfully on GWT 1.5.3 for a test project of mine.

I followed the sample instructions as given in the GWT website.

After using the projectCreator and applicationCreator scripts - when I tried to import the project in eclipse and run it - I encountered the following error trace.
/opt/software/gwt-linux/mozilla-1.7.12/libxpcom.so:libstdc++.so.5: cannot open shared object file: No such file or directory
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1751)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1647)
at java.lang.Runtime.load0(Runtime.java:770)
at java.lang.System.load(System.java:1005)
at com.google.gwt.dev.shell.moz.MozillaInstall.load(MozillaInstall.java:190)
at com.google.gwt.dev.BootStrapPlatform.go(BootStrapPlatform.java:40)
at com.google.gwt.dev.GWTShell.main(GWTShell.java:318)

I was working on Ubuntu 8.04.

I did the following

 sudo apt-get install libstdc++5
to get rid of the above mentioned error to install the missing .so files.  That fixed the issue.

Friday, February 1, 2008

Boost MPI implementation

Boost got a new MPI approved in its vast list of libraries -
Boost MPI.

Boost MPI is the way to go if we are planning to use it for high frequency applications.

Tuesday, January 29, 2008

Alignment

Sometimes when we are coding on architectures with limited memory footprints , we might end up writing a memory allocator ourselves (more often than not ). Having said that - one of the important design considerations for a memory allocator is getting an address that is probably aligned with the underlying architecture.

Here is the simple code fragment to do the alignment for a given size.
Note that - the align function returns a new address only when the input address is not aligned by itself.


#include <stdlib.h>
#include <stdio.h>

/* align address to be a multiple of n. */
void* align(void* memory, int alignment)
{
unsigned char* ptr;
unsigned int offset;

ptr =(unsigned char*)memory;
offset =(unsigned int)ptr % alignment;

return offset ? (ptr + alignment - offset ): ptr;
}



int main()
{
void * a;

a = malloc(sizeof(char) * 10);

printf("\nAddress: 0x%p ", a );
printf("\nAligned Address:0x%p ", align(a, sizeof(int) ));
return EXIT_SUCCESS;
}




Reblog this post [with Zemanta]

Thursday, January 24, 2008

C++ STL list with logarithmic lookup ??

If we talk about standard C++ SQL (C++03, at least) looking for a data structure to simulate a list with logarithmic lookup, the question will appear to be contradictory to begin with.

If we are looking for a data structure whose access pattern is different from that of the underlying storage mechanism - Boost MultiIndex is an option worth spending at.

Wednesday, January 23, 2008

C++ - atexit implementation

More than one occasion - when a program exits - we may want to do some cleanup operations and notify other processes ( this becomes extremely important in the case of child-parent processes).

C/C++ does have a function called atexit() that does that.

A sample code fragment to use the same is as follows.


#include <cstdlib>
#include <iostream>

using namespace std;

void do1()
{
std::cout << "do1 implementation\n";
}

void do2()
{
std::cout << "do2 implementation\n";
}


int main()
{
atexit(do1);
atexit(do2);

exit(EXIT_SUCCESS);
}

Sample output:


$ g++ -Wall -Werror testexit.cpp
[noname@localhost test]$ ./a.out
do2 implementation
do1 implementation

Monday, January 21, 2008

Tutorial on Boost Threads

If you are looking for a tutorial on Boost Threads, start here .

Wednesday, January 9, 2008

Books on Design Patterns for concurrent / networked objects

One of the interesting books on concurrent / networked objects is -
Pattern-Oriented Software Architecture Volume 2: Patterns for Concurrent and Networked Objects

Boost ASIO library for high performance networking servers

If anybody is venturing into developing networking libraries in C++ , the ACE framework is the one that strikes your mind first.

Recently came across the library called boost asio - available here .

Boost ASIO definitely makes things much easy and portable. If the application we are developing needs to be truly portable - the fact that asio is part of the boost framework guarantees portability by definition ( across a large number of compilers across many platforms).

There is also an interesting article on the design patterns to be used by the boost library available here.

That makes interesting reading for sure.