Loading... Cancel

ruby dynamic abstract factory implementation R

May 10th, 2008

i was looking for some way out to implement abstract factory on ruby code. where i have a VersionControl::ServiceFactory which will take different implementation as factory method. ie. VersionControl::ServiceFactory::subversion, VersionControl::ServiceFactory::git and so on.

though all these “subversion, git, perforce” methods are not predefined, these will be added while new implemention is added. my skeleton (abstract) implementation was in VersionControl::Service, so whatever implemention (svn, git, perforce, other) comes ahead it will implement method from VersionControl::Service method. since ruby doesn’t support class abstraction so this was the only way  i got in head.

so my skeleton implemention was consist of the following code in summary -

module VersionControl

# log entry class for data object
class LogEntry; end

# local repository information
class Information; end

# abstract service class.
# define service which will be exposed for a
# normal version controlling service.
class Service

# retrieve recent logs from the current directory
# required parameters - *base project path* and other options.
def logs(p_path, p_options = {}); raise "not implemented method" end

# generate diff from mentioned revision number
# or current revision number
# required parameters - *base project path* and other options.
def diff(p_path, p_options = {}); raise "not implemented method" end

# find repository information
def info(p_path, p_options = {}); raise "not implemented method" end
# check out content from version control server
def checkout(p_source, p_path, p_options = {}); raise "not implemented method" end

end

# factory class for supporting different version control implementation
class ServiceFactory; end
end

and the implementation is written in this way -

class ServiceFactory

class < < self
# add subversion factory method implementation
@@subversion_instance = SubversionService.new
def subversion
return @@subversion_instance
end
end
end

so every implementation also push it’s factory method to “VersionControl::ServiceFactory” class. so this way i have implemented dynamic abstract factory on ruby.

GITIdea intelliJ idea plugin for GIT R

May 3rd, 2008

i just started using GIT, i say i love it.

since i have been using IntellIJ idea for a long while, in GIT world i felt like alone though i was using idea but not getting any idea how to live without some IDE’s version control support.

i want to compare my changes before i commit, i want to see more user friendly diff merging tool which idea is providing with other version control support.

so i found GITIDEA over here http://github.com/Fudge/gitidea/tree/master, after cloning and building this project.

i found it wasn’t working. so looking into code i found, it is executing “git” command. since my “git” executable is not under /usr/s|bin, i had to create a new symblink to make it work.

now it is working great, i can see where i have changed just by looking at the code (which bhaves like the usual svn support).

thanks fudge

Posted in Java, git

problem with lucene number range filter R

April 25th, 2008

today i was almost stucked with lucene RangeFilter. here is description -

i have used this query - “price:[0 TO 2000]” to find all items which are bellow 2000.
but my search result was also including 12000 any clue ?

good news is i got my solution though it took bit longer to find my actual reason.

the quick answer is i have to use NumberTools.longToString(…) to index my number fields and to perform range search i have to convert my range value using NumberTools.

you can see my code here -
source view

just digging through lucene source code here is what i found -
to perform range query (which is later rewrite to range filter), it tooks lower token for example price: [0 TO 1000] here ‘0′ is the lower token. it asks TermInfosReader to return a list of available terms for a specific field (such as price here).

RangeFilter iterate through each suggested term and seek for the token position in a random access segment file.

the problem is, the suggested terms are not sorted. also i didn’t find any way to sort them before filtering out.

though i index my content after sorting them properly. but it didn’t affect any result.

since lucene treats everything as string, and it uses String::compare to determine the range position, i think NumberTools, DateTools are the only way out there.

anyway, i am satisfy with what i got.
best wishes,
“…i do what i love to do…”

create new url protocol to load spring configuration resource from the relative path R

April 18th, 2008

i had a problem with spring framework, as you know while we are defining dependency over the xml documents, it becomes less changeable unless you know about my recent post about ext-util namespace handler and if you know any other alternatives.

before digging inside the problem better i clarify my context -

i have been working with one of my projects, where i have a several configurations which suppose to be different in different deployment environment, for example - to make my service avail, user has to define his database, his content index directory, server port, ip address and few more.

all these configurations were kept within the spring bean declaration scope. though few of them were moved to the properties file through ext-util namespace handler.

previously to make those configuration changeable i kept those files under WEB-INF/classes so it overrides the default bundled resource.

but still it wasn’t user friendly, since my user has to change one xml document to add more index services also he has to edit different configurations from java properties file.

again when i started bundling jetty with my whole application i found it is tricker to keep those xml outside of application, since i don’t wanna make my user confused with lot of xml files. and i have to keep few xml out of  my classpath context, so spring has to load my configuration from my “config/index-configuration/” directory.

though by default spring can do it over “file:///absolute/path/to/file.xml” since spring is using java URL class to locate this resource.  but in my case i can’t put any aboslute path.
so i found a simple way out there to support relative path reference.

previously i had the following xml document -

wow, i didn’t thought that moment would be too short. thanks goes to sajjad bhai and whole volunteering team, without them we were not suppose to get that WoWsome evening.

those who bored by my annoying, prolonging and noisy session, i am apologized. good suggestion might help me to understand how i can improve :)

here is my presentation slide, hope this will help you guys to check through about “what is preventing me” and “how to write nearly accurate code”

best of luck

upcoming project mojar_workflow, workflow engine in ruby R

February 10th, 2008

hi,
we just kicking start a new open source ruby based workflow engine project mojar workflow.
we named it after our deshi word “mojar” reason is very clear to
spread out this word.

mojar workflow, is integral solution to execute a flow of business
rules. for example -

you have an action where you have the following set of rules -
1. start transaction
2. verify user account
3. verify user balance
4. verify user dues
5. reduce dues from balance
6. complete transaction

after few days you got a new requirement, where you suppose to reduce
user dues by the 10% because of company new discount policy.
so you have to implement the following rules -
1. start transaction
2. verify user account
3. verify user balance
4. verify user dues
5. reduce dues by 10% of discount
5. reduce discounted dues from balance
6. complete transaction

to implement such scenario you have to again code in your stable
release. but using mojar workflow, you can add that new concern from
the abstract flow maintenance layer. where you can define this flow in
yaml file or an xml document.

keep your eyes on -
http://rubyforge.org/projects/mojarworkflow/

best wishes,

mac dashboard widget for somewhere in… blog R

February 2nd, 2008

somewhere in… blog, is the most popular bangladeshi blog community.
on my spare time i like to keep in touch with this community activities. so here is a widget i have developed as my holiday product, which will help you to keep in touch with this community without going through the site.

currently this widget has the following features -
1. all activities through recently posted comment
2. online users log.

download links -
[download]

installation -
1. extract the downloaded archive file.
2. double click on “somewherein-latest-activity.wdgt” file.
screen snaps -

blog-activity-widget-2.jpg

blog-activity-widget-3.jpg

builder pattern with fluent interface just an example while i was doing by routine work :) R

January 26th, 2008

today while i was working with one of my projects, i was wondering how this came up with a bit more fluent with my credential object.
just i can’t resists myself to share this code with every one.

assertNotNull(mProfileManager.authenticate(
Credential.Builder
.aNew().userName(userName).password(password).build()));

uncaught exception: Permission denied to get property Object.constructor R

December 30th, 2007

seems you are getting “uncaught exception: Permission denied to get property Object.constructor” while you are  executing some javascript which was instantiating some objects and during that time it stucked with some exception.

for example

function get(pUpdate, pUrl, pParams) {
new Ajax.Updater(pUpdate, pUrl, {parameters: pParams});
}

if you want to regenerate this exception you can invoke this function with the following arguments -

get(”abc”, “http://abc”)

so why this crap ?

the main reason is in your code where you mentioned about “parameters” and which is not supposed to be null. you better write the following code -

function get(pUpdate, pUrl, pParams) {
var options = new Array();
if (pParams != null) {
options[”parameters”] = pParams;
}

new Ajax.Updater(pUpdate, pUrl, options);
}
that will take away your javascript exception.

best wishes,

“ext-util:resource” new spring namespace for loading property from different scope i.e. system, test, dev R

December 2nd, 2007

within spring container i was getting problem with managing multi level configuration.
for example while i am developing i got a specific filesystem path, database configuration and so on.
this configuration are mostly get changed while i an deploying them on the test or production environment.

this type of scenario is common on most of the projects. managing different scoped configuration is one of the bothering stuff. so i was always thinking some simpler way with in spring container.

so i wrote “ext-util” namespace handler, which is locating property from multi scoped resource.
lets give you a more details use case -

in my test environment i have a property “index.directory=/Users/…/index”
in my test server i use “index.directory=/var/index”
in my production server i use “index.directory=/nfs/index”

here i have a bean which need this property.

< bean id="fsDirectory" class="org.springmodules.lucene.index.support.FSDirectoryFactoryBean" >
< property name="location" value="file:////Users/nhmtanveerhossainkhanhasan/java-tmp/index" / >
< /bean>

you can see the hardcoded configuration. which is not easy to manage.
thats why here my “ext-util” goes with the simplest solution -

< ext-util:resource id="directoryResource" from-property="index.directory" scope="test" / >
< bean id="fsDirectory" class="org.springmodules.lucene.index.support.FSDirectoryFactoryBean" >
< property name="location" ref="directoryResource" / >
< /bean>

now my property resource is locating from “test” scope.

you might think, this “scope=’test’” is again hardcoded stuff, so i also support the following value -
scope=”sys:env”, now you have to define “-Denv=test” while you running your application, and spring bean will find the right property.

so what ever you put over your spring are no longer hardcoded as long as you locate them through “ext-util” which is stands for “extended utility”.

here is my attached source code - (i just extracted them from my on going project, thats why no build script or prebuilt package or maven artifact is bundled)

how to use -
include the source file with in your project
keep “META-INF” while you building your jar or keep them inside your classpath.
change your spring configuration -

xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”
xmlns:lang=”http://www.springframework.org/schema/lang”
xmlns:aop=”http://www.springframework.org/schema/aop”
xmlns:ext-util=”http://dev.somewherein.net/schema/ext-util”
xsi:schemaLocation=”http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://dev.somewherein.net/schema/ext-util http://dev.somewherein.net/resources/schemas/ext-util-0.1.xsd“/>
basic properties of ext-util -

1. from-property - which property you are looking for.

2. or-default - define default value if no property is found from default scope (system properties) this value is returned.

3. scope - define scope name, by default whatever you set except “sys:” prefixed string, will search for “classpath:”. also you can use “sys:abc” where abc is located from system properties.

4. path-prefix - you can define scope properties path prefix, this prefix can be “file:///, classpath:”. this value also can be prefixed by “sys:abc” where abc is located from system properties.

[download source code]
[download missing xsd file]

best wishes,