hasan's blog (বল্গ)

work for fun!!!

i always got that attitude

with 7 comments

I have very bad attitude, i always love to add idea on whatever i touch. so when i have found this excellent wordpress template, i thought i should make it through my way. today i gave it a new look, i wish this won’t be bad on your eyes. thanks to rashid bhai for my face design and hasin bhai for hosting.

picture-14

best wishes,

Written by nhm tanveer hossain khan

April 17, 2009 at 7:22 pm

Posted in theme, wordpress

yes!!! i have moved on wordpress still my domain is valid.

leave a comment »

thanks goes to hasin bhai and his this post also with his hosting space.

previously my blog was hosted on my official server, so when i moved on, i had to move it elsewhere.
i thought wordpress’d have better facilities. since it’s a hosted solution, so i don’t have to maintain it at all.
later i discovered i had to pay 10$ per year to activate my domain based hosting setup on wordpress.
without making further delay i asked hasin bhai to give me an account on his server, without second thought or delay he set it up for me.

later i followed hasin bhia‘s procedure to use my hasan.we4tech.com on top of we4tech.wordpress.com.
now it’s working without any problem.

best wishes,

Written by nhm tanveer hossain khan

April 3, 2009 at 5:12 pm

i haven’t maintained my blog for a long while, lets say i just kicked it back.

with 5 comments

i was so lazy that stopped me from what i was supposed to put on my blog. haven’t touched or written anything for a long while. since i joined in new company where i am officially bounds to write something on our official blog. so i guess this is better if i’d tried few blogs first on my site first.

many changes are happening in 2009, i just prepared a list i can think of right now -

  • moved my job to tekSymmetry
  • my beliefs are very strong because of the secret
  • working for bringing the change to our local people
  • more preciously started giving time on the stuffs i really feel from my hurt
  • having so much fun with friends and well wishers
  • always discussing with people about “how to bring the changes?”
  • loving travel alone
  • moved my blog on wordpress
  • need to fix hasan.we4tech.com
  • i can drive better than before

you know these stuffs sounds noise or kinda confusing, i guess thats what i can add so far.

best wishes,

Written by nhm tanveer hossain khan

April 1, 2009 at 7:12 pm

Posted in personal

cox’s bazar trip feb 2009

leave a comment »

i was watching the sunset, suddenly i discovered some unusual stuffs, well guys nothing to be wondered it was a collection of mosquitoes. all of them were protecting me from some unknown fear.

they guided me throughout my hotel. my camera didn’t miss this moment to keep for future reminder.
my other pictures could be found here
best wishes,

Written by nhm tanveer hossain khan

February 11, 2009 at 12:56 pm

Posted in cox\'s bazar, tour

why unit test (a developer perspective) ? (contd. after coffee with sqabd session)

leave a comment »

hi,
just jotting down all my thoughts what we partially discussed today at coffee with sqabd session.

why unit test (a developer perspective) ?

when we (developer) code we need to spit out some information to verify certain point of function/logic to ensure they are returning or working as the way they suppose to behave.

for example –
def convert_to_taka(p_dollar)
  return p_dollar * get_current_taka_conversion_rate()
end

def get_current_taka_conversion_rate
  # let’s say, this function retrieve this value from remote web service call
end
as you can see “convert_to_taka” function is not all in all, it has dependency to another method where it delegates it responsibility to get the current currency rate for taka.

so as a developer my responsibility is not only to ensure convert_to_taka method also my responsibilities include to verify whether get_current_taka_conversion_rate is behaving properly.

so before i was introduced with test first approach. i used to write my code in the following manner -
def convert_to_taka(p_dollar)
  logger.debug(“converting dollar #{p_dollar} to taka”)
  conversion_rate = get_current_taka_conversion_rate()
  logger.debug(“conversion rate for taka – #{conversion_rate}”)
  return p_dollar * conversion_rate
end
so during my development process i had to watch these logging outputs with my eagle eyes so that nothing could get out my concern.

why test first development ?

as you can understand from the “test first development approach”, it reflects something has to be upfront.
without developing we can’t test what is going to be developed, but using test first approach it means you are preparing your expectation upfront to get your code working with your expectation. so here what i would have written if i knew test first approach before.

def setup
  # mock currency retrieval web service or whatever requires to set 70
  # as the returnable value from get_current_taka_conversion_rate()
end

def test_should_successfully_convert_currency_with_valid_input
  assert_equal(7000, convert_to_taka(100))
  assert_equal(525, convert_to_taka(7.5))
end

similarly you could have the following test cases
def test_should_fail_to_convert_currency_when_webservice_returns_error; end
def test_should_fail_to_convert_currency_with_negative_value; end

so if you compare this with the above statement where i mentioned “logger.debug” related stuffs.
you can see the difference where this one is more understandable for us to re imagine what our task means to us.
this approach would give us chance to rethink about the task we have chosen (if agile team).

why it has nothing to do with tester test ?

test driven development is for developer to do his/her job properly to ensure better code (less bug) according to his task definition
eg. user stories
as a developer
i want to see my function is working while currency web service is not returning anything

or perhaps


as a
developer
i want to see my function is taking last known currency exchange rate from cache data while currency web service is failing.

or perhaps

as a visitor
i want to convert my currency by clicking on “convert currency” button

or


as a
visitor
i want to convert my currency without refreshing the whole page….

this has nothing to do with 1px design issue, or notification message doesn’t appear immediately or problem from user kinda tester point of view. still we need them badly to bet on burger per bug ;)

so i think i could make sense why it won’t worth anything if tester prepare the test case for developer :p

TDD is to verify our own code
(because client changed his mind, or because we need to support another scenario)

when requirement changes or adds new scope, we have to review our own code to enhance the scope.
here comes compatibility issue, as you can understand old test cases would become the more kissable asset to verify our recently modified code against the old requirements and new requirements. (perhaps some function requires old way to do the job)

TDD is enabling us to run continuous integration and build process

as you can recall what sajjad bhai was mentioning about continuous integration and warning for those (developer) who break the code.
using these developer created test cases we can do this job.
or perhaps we can employ our testers (hardly a few) those who LOVE (or forced to love) to write integration test case.

anyway, thanks for nice afternoon with mouth watering pizza and coffee, wish to see more pizza slices ;)
best wishes,

Written by nhm tanveer hossain khan

January 17, 2009 at 11:09 pm

Posted in agile, test approach

what killed my time to run my first test using “cucumber”

leave a comment »

stucked with “No such file or directory – cucumber.yml” error?
then you must doing the same mistake as i was doing for last 1 hour.

i had the following code in Rakefile

require ‘cucumber/rake/task’

Cucumber::Rake::Task.new do |t|
profile = ENV['PROFILE'] || ‘default’
t.cucumber_opts = “–profile #{profile}”
end

the fix is just keep the following code only -

require ‘cucumber/rake/task’

Cucumber::Rake::Task.new do |t|
end

so are you still facing problem while you are executing “rake features” but it doesn’t come up with any output?
here is the check list – (this list may grow gradually) -
1. do you have features directory
2. do you have features/steps directory
3. lets say you have “features/transfer.feature” file do you know that you must have “features/steps/transfer_steps.rb” file?
4. do you know “feature name” must be prefixed for steps file?
hope this might help you.

Written by nhm tanveer hossain khan

October 19, 2008 at 6:12 pm

Posted in BDD, Ruby, tools

BDD(behavior driven development) with easyb

with one comment

hi,
just wondering is there anyone who started using easyb?
which is behavior driven development framework. if you are not familiar with BDD here is my explanation.

as you heard and practicing TDD (test driven development), (if you follow test first approach) you keep your specification up front through test case.
for example -

public void testShouldCreateAnUserWhenItHasValidData() {…}

as you can see, you are actually writing test case for behavior(specification) for your expected code.
and based on that test case you are implemented your logic in code. this how TDD works. for more explanation google IT :)

in BDD, this process is more simplified, for example if you look at my previous example -
public void testShouldCreateAnUserWhenItHasValidData() {…}

you can find, i have written one scenario when user object has valid data.
same test can be in different scenarios such as, when user object has no valid data. or the caller is not authorized and so on.

so to make such thing clear in java code, it requires code like the following. ie.
public void testShouldCreateAnUserWhenItHasNoValidData();
public void testShouldCreateAnUserWhenItHasValidDataButCallerIsNotPermitted();
public void testShouldCreateAnUserWhenItHasValidDataButCallerIsPermitted();

here how BDD is proposing a new approach of making this thing more fluent through a simplified test framework.
like JUnit, easyb is also another test framework, where you are writing your test context, and behavior in groovy code.

actullay the beauty is test scenario are written following the user story convention
which is similar with the ideal convention
as an Author
i want to write book
so that user can understand me”.
you can also generate user story from the groovy code which you can’t do with JUnit.
so you don’t need to maintain separate document for maintaing user stories.

so when you are preparing user story and you can use easyb and groovy to format your user story rather than using ms word, excel or notepad text file ;)
ie.

import com.somewherein.bdd.UserService
import com.somewherein.bdd.UserServiceImpl
import com.somewherein.bdd.Userscenario “create a new user with valid data”, {

given “an user with the valid data”, {
user = new User()
userService = new UserServiceImpl()
state = false
}

when “creating a new user”, {
state = userService.createUser(user)
}

then “returned state should be true”, {
state.shouldBe true
}

and “newly created user should be found”, {
userService.exists(user)
}
}

when i run this test it says -

Running user service story (UserServiceStory.groovy)
Scenarios run: 1, Failures: 0, Pending: 0, Time Elapsed: 0.649 sec1 behavior run with no failures

so if i ask for generating the user story – it generate the following text

1 scenario executed successfullyStory: user service

scenario create a new user with valid data
given an user with the valid data
when creating a new user
then returned state should be true
then newly created user should be found

this type of practice is very common in ruby on rails based development.
in ruby we have several options, but RSpec is the early comer who showed how cool it could be.

anyway, this is something you should work try EiD vacation, happy test first development.

easyb makes it easy, man

here is an article from javalobby
Is easyb Easy? | Javalobby

you can use it with spring framework, here is the example -
best wishes,

Written by nhm tanveer hossain khan

October 1, 2008 at 5:07 pm

debugging rails internal query execution

leave a comment »

while we were working with somewhere in… ads project we came up with some debugging and performance mesuring tool, here in my post i will describe how you can use it for yourself.

query debugging –
picture-16
query debugging tool logs every executed query from active record and keep them in memory and using assisting template code it display all executed query from the active page.

also it executes query with mysql “explain” keyword. so on the same window you can see mysql query execution plan.
it helped us to track down queries which were not hitting the right index.
this is very simple trick – go through the code below -

module DebugUtil
class QueryDebug
@@QUERIES = {}
def self.add(p_query, p_report)
@@QUERIES[p_query] = p_report
end

def self.queries
q = @@QUERIES
clean
return q
end

def self.clean
@@QUERIES = {}
end
end
end

QueryDebug class keeps all executed query and their explained resultset in to the static array. so later in template QueryDebug::queries is invoked to get all executed query for the current page.

here is how we trap the query execution from active record -

if defined?(QUERY_DEBUG_ENABLED) && QUERY_DEBUG_ENABLED
ActiveRecord::ConnectionAdapters::MysqlAdapter.class_eval do
alias __existing_execute_method execute

def execute(sql, name = nil)
if sql.match(/^SELECT/i)
report = []
@connection.query(“explain #{sql}”).each do |row|
report < < row
end
DebugUtil::QueryDebug.add(sql, report)
end
__existing_execute_method(sql, name)
end
end

Object.class_eval do
def raise_during_query_debug
raise DebugUtil::QueryDebug::queries.inspect
end
end
end

you can see we have used “QUERY_DEBUG_ENABLED” constant to ensure whether this is enabled by intention.
now see how we are rendering on our template.

query debug

  1. checked
    < %= row.join(“ “) % >

we put this code in common layout. so it renders on every page. thats all :)

Written by nhm tanveer hossain khan

September 15, 2008 at 6:03 am

time based cache expiry for rails action cache

leave a comment »

rails has excellent support for caching action, page, query and so on.
rails default behavior is more than expected for most of the project. though i was looking for some time based expiry function on “caches_action” functionality. unfortunately there wasn’t anything so here is a simple trick i have used to make it work with different url and time based expiration.

i added “caches_action :recent” on my controller and added the following protected method -

protected
def fragment_cache_key(p_args)
cache_key = “cache_key_#{request.path}#{request.headers["QUERY_STRING"]}”.gsub(/=/, “”)
action_cache_key = get_from_cache(cache_key)
if action_cache_key
return action_cache_key
else
action_cache_key = Digest::MD5::hexdigest(“#{rand}#{Time.now}”)
add_to_cache(cache_key, action_cache_key, {:expiry => 1.hours})
return action_cache_key
end

end

actually i generate key and stored them inside my memcached instance with an hour expiry limit.
so when memcache invalidates my cache my action cache is also get invalidated.

so thus rails default action cache work with time limit :)

don’t think this is all, i suppose to cleanup the previously created cache file so i won’t get unnecessary store consumption .

Written by nhm tanveer hossain khan

June 23, 2008 at 10:54 pm

semantic-repository-0.5.2: deploymet update

leave a comment »

hi,
as some of you know, semantic repository version 0.5.2 has some problem with IOException (too many files open)
which was stopping repository to perform further search. thats what was reason to get empty search result.
after searching a while, we found the problem (which was also mentioned in lucene FAQ document).

by default bash shell allow limited files to open, since we had many index files, lucene has to open them up during performing search.
so when it exceeds the limit of 1025 files (which is default on our production environment). our application threw the following exception -
Caused by: java.io.FileNotFoundException: /var/indexes/ads-index/_gm.tvd (Too many open files)
at java.io.RandomAccessFile.open(Native Method)
at java.io.RandomAccessFile.(RandomAccessFile.java:212)
at org.apache.lucene.store.FSDirectory$FSIndexInput$Descriptor.(FSDirectory.java:506)
at org.apache.lucene.store.FSDirectory$FSIndexInput.(FSDirectory.java:536)
at org.apache.lucene.store.FSDirectory.openInput(FSDirectory.java:445)
at org.apache.lucene.index.TermVectorsReader.(TermVectorsReader.java:70)

after increasing this limit to 10,000 we didn’t find such problem exists. we had to apply “ulimit -n 10000″ command on bash shell to make it works.

TODO: possible bug, probable our system is opening up several index searcher.

semantic repository service is intended for indexing content from different sources and maintain multi indexes for different types of content and perform different types of search. yet another solr type indexing service on top of lucene but it will gradually support content versioning and more semantic search result.

Written by nhm tanveer hossain khan

June 6, 2008 at 3:00 pm