Category Archives: development

Fix new line characters with Eclipse

One of the most popular differences between operating systems is the new line separators used in each one of them.

Typically, the top three OS out there print new lines this way:

  • Windows - CRLF, \r\n
  • Mac OS X - CR, \r
  • Linux/UNIX - LF, \n

It's normally an issue when working with a text document under different OS (or deploying to servers).

Luckily, there is a function in Eclipse that would help you automatically convert line endings - "Convert Line Delimiters To" under "File"

eclipse-convert-lines

As a Linux user myself I personally prefer the UNIX-style as our servers are always running under some Linux derivative (and it helps mitigating possible issues related to this for version control systems or deploy scripts).

del.icio.us Digg DZone Facebook Google Google Reader Magnolia reddit SlashDot Technorati ReadMe.ru Dobavi.com Dao.bg Lubimi.com Ping.bg Pipe.bg Svejo.net Web-bg.com

Setting up Grails and Postgres on Fedora

On Fedora, install Groovy with yum.

Then, download Grails and follow the guide: http://grails.org/doc/latest/guide/gettingStarted.html#requirements

Important: set correct Java and Grails home paths to be used by the engine.

Plain and simple guide for Postgres - https://community.jboss.org/wiki/InstallPostgreSQLOnFedora?_sscc=t

The only difference here was that initdb was called through:

sudo postgresql-setup initdb

del.icio.us Digg DZone Facebook Google Google Reader Magnolia reddit SlashDot Technorati ReadMe.ru Dobavi.com Dao.bg Lubimi.com Ping.bg Pipe.bg Svejo.net Web-bg.com

Hourly rates, Amount of work and Availability

Note: This essay is not always applicable while some projects definitely demand a straight work schedule, reporting and collaboration between the team members. However it reflects the majority of projects and clients out there in the wild.

As an employer I prefer to charge on a project basis. It's easier to plan my budgets and the costs of the final results. 

As a contractor I prefer hourly payments. It helps dropping the pressure from incorrect specifications and further negotiations after the project and the budget have already been set.

However I am well acquainted with the pros and cons of both methods. But there are three terms that I believe most clients use in an inappropriate context without gaining the maximum productivity and optimal costs for their projects. We're speaking about the hourly rates, the amount of work and availability.

Hourly rate

As I said I got tired of arguing with clients with dummy specifications and clonings of the "Clients from Hell" samples. I don't expect all of them to be technicians. But usually the time dedicated for meetings, specifications and other meetings during the process exceeds the actual development time. And also the initial meetings and negotiations are still 'Awaiting' and projects are not actually accepted so there is a serious risk of "This price doesn't fit to my budget, I cancel" so... yeah.

So I prefer the hourly rates. I estimate single tasks and modules based on what I know. In case of any misunderstanding we have a short chat/call with detailed data what is the extra work all about, what else needs to be done and how will this reflect the previous estimate. On approval we work, on rejection - I don't waste my time. Simple as that. 

What annoys me most is that clients are looking for specific hour rates. For instance: "I am able to pay $10 per hour" while I am estimating some projects on $20/h. And I get rejected because of my _hourly rate_ without even being able to estimate the amount of work to be done.

This is completely wrong for one simple and basic reason. A task to be solved is based on the following formula:

Solution = amount of time * hourly cost * quality coefficient

Lets start backwards.

  1. Quality coefficient - a decimal variable between 0 and 1 that values the final quality of the solution. For instance, talking about a website creation, a QC of 0 would be completely useless end product. A coef of 1 would be a multilingual website (if needed) which is W3C valid, cross-browser compatible, reusable and well documented source code, stable and secure. 
  2. Hourly cost - simply the price for working for 60 minutes.
  3. Amount of time - here is the tricky moment. This is the time that an expert needs to complete a given task. You know what? My $5-coders I work with are pretty slow and their end work quality often needs refactoring. While they solve a simple problem in 4+ hours with a coefficient of 0.7, my core developers for $20/h complete their assignment in less than an hour with 0.95+ quality. And asking for more.

So, what I am about to tell is: don't judge the coder by the hourly rate. It's irrelevant until you know the end estimate and the quality of the work.

Amount of work

This is another standard requirement which is particularly based on the hourly rate.

In my experience there are 2 types of projects - maximum work for a short term or flowing work which is long term. Most employers require long-term non-stop working. This usually affects the productivity of the worker and his/her motivation as well. 

If you work with an experienced coder or designer, or whatever who could do proficient and high quality work for a short time, you need to give him/her the freedom of the 9-5 working office schedule. Sometimes this is not possible due to some company requirements about the availability and meetings and so on, especially when people do work in different time zones. So here it is step 3 - the availability.

Availability

The availability is the time range while the worker is available to contact the project responsible person. However most clients expect that the person is available only during the time of the actual work and also, that he/she is working all the time during the availability period. Which is completely not mandatory.

For projects that need some quick reaction and support the contractor must guarantee availability hours and _not_ work hours. Its just like the support positions - 2 people should be _available_ 12h for any possible exceptional situation. But it doesn't necessary mean that they need to do actual work during this period. 

My practice is working on 2 or 3 projects a week, as the projects vary in their specifications I dedicate 40-50 hours a week at total. I am available 70+ hours a week for a client if needed to get some consulting or just status updates and I do quick and clean work for the 15-25 hours that I have agreed on working for the given project. This usually leads to best results at a minimal cost.

What I could have done for the conservative clients?

I don't like cheating and I usually cancel projects and reject client invitations for people that wouldn't understand this article. But, you know what? If I am confident in my skills (as I am in few technologies I've been polishing my skills in during the last 7 years) I could have done the following:

  • estimate projects completion time multiplied by three or four 
  • giving half of my availability

As a result I would charge for 4 times slower work and 2 times the price I would charge normally with a flexible client. I would mark in my work diary 120 hours of work (3 projects * 40 hours) while it is hardly possible while I actually work on my normal rates and schedule. No one would even doubt if I am a fast and clean worker. But why should I cheat if we could agree on my preferred rate and a flexible working time?

del.icio.us Digg DZone Facebook Google Google Reader Magnolia reddit SlashDot Technorati ReadMe.ru Dobavi.com Dao.bg Lubimi.com Ping.bg Pipe.bg Svejo.net Web-bg.com

JMockit Quick Tutorial and Revelation

JMockit is a powerful mocking framework in Java that provides extended functionality that goes beyond the capabilities of all other solutions on the market so far. While most mocking frameworks are proxy based and depend on Reflection to hide the dependent behavior, JMockit falls further and deeper with solving some critical problems such as mocking final classes and static methods by using the Instrumentation API presented in Java 5.

The Instrumentation API allows a direct bytecode replacement in the virtual machine via java agents that modify the codebase of the current classes with the one from our mocked representation (either empty stubs or entirely modified behavior). This is a powerful process that could be hardly debugged even with JMockit codebase - just because the whole lifecycle in the JVM is changed with the agents that do the low level modification (basically done with ASM in the mocking framework).

JMockit Components

JMockit toolkit contains 6 important separated components to be used for mocking reasons. They are:

  • JMockit Expectations
  • JMockit Verifications
  • JMockit State Oriented (Mockups)

  • JMockit Coverage

  • JMockit Hibernate Emulation
  • JMockit AOP

The AOP part is the dark power of that century - just like the other mystic words like Cloud or SaaS or Business Component/Entity. It gives some injection abilities in addition to the standard Mocking approach.

The Hibernate Emulation represents some fake mocks to the Hibernate 3 API, which is however still unstable and not ready (after some research on StackOverflow I found few comments from the author himself discussing the ineffectiveness of some parts of the implementation).

It took me few days to find any reasonable documentation, tutorial and/or codebase for starters. The only resources I found usable for intro to jmockit were Dhruba's examples and some other random code snippets around. The tutorial from the Google Code repository starts with business entities and hardcore logic at first place with no details explained from scratch.

Let's find out how Expectations, Verifications and Mockups work. With a dummy demo that shows the usage of all of them at a place.

Sample case

We have a bank system. A person has a name and some amount of money. We have a Bank object that calculates a resulting sum for a person based on some InterestCalculator. The bank has an interest rate and the calculator executes an algorithm to define additional rate based on the sum that a person owns. Pretty much that's our sample scenario and here there are our demo classes:

Person

  1.  
  2. public class Person {
  3. private String name;
  4. private double currentSum;
  5.  
  6. public Person() {
  7. super();
  8. }
  9. public Person(String name, double currentSum) {
  10. super();
  11. this.name = name;
  12. this.currentSum = currentSum;
  13. }
  14. public String getName() {
  15. return name;
  16. }
  17. // more getters and setters
  18. }
  19.  

Bank

  1.  
  2. public class Bank {
  3. private double bankInt;
  4. private String name;
  5. private InterestCalculator calc;
  6.  
  7. public Bank() {
  8. this("Test Bank", 0.15d);
  9. }
  10. public Bank(String name, double bankInt) {
  11. super();
  12. this.name = name;
  13. this.bankInt = bankInt;
  14. }
  15.  
  16. // count the sum with the interest for a month but after the bank fees
  17. public double getSumAfterInterest(Person p) {
  18. double currentSum = p.getCurrentSum();
  19. double interest = InterestCalculator.getInterest(currentSum);
  20.  
  21. // count current sum + the interest and keep in mind bank fees
  22. double result = (currentSum + interest) * (1-bankInt);
  23.  
  24. return result;
  25. }
  26. // get/set methods
  27. // ...
  28. }
  29.  

Interest Calc

  1.  
  2. public class InterestCalculator {
  3. // dummy interest counter
  4. // large interest for small sums
  5. public static double getInterest(double sum) {
  6. if(sum < 1000) {
  7. return sum * 0.3;
  8. }
  9. else if(sum >= 1000 && sum < 10000) {
  10. return sum * 0.2;
  11. }
  12. return 0.1;
  13. }
  14. }
  15.  

We have set a TestNG project with JMockit integration and we want to test our demo without relying on the InterestCalculator. Assuming that this is a class from an external library and we might not have access to him, we will presume three different cases: 

  1. the InterestCalculator is called twice and the result is 200 after the first call and 400 after the second
  2. the InterestCalculator method is called between 0 and 5 times
  3. the InterestCalculator will use a predefined algorithm that we could modify for the given test

Our demo will mock the InterestCalculator but we are going to use the mocked data through the invocations in the Bank class

Two calls - 200/400

Using the Expectations API we expect that 2 calls of the getInterest(...) method would be done and returned values will be 200d and 400d

  1.  
  2. public void testFlowMockedInterest() {
  3. new Expectations() {
  4. InterestCalculator interest;
  5. {
  6. interest.getInterest(anyDouble); result = 200.0;
  7. interest.getInterest(anyDouble); result = 400.0;
  8. }
  9. };
  10.  
  11. Person person = new Person("John", 1000);
  12. Bank bank = new Bank("Alpha", 0.2);
  13.  
  14. Assert.assertTrue(bank.getSumAfterInterest(person) == 960.0);
  15. Assert.assertTrue(bank.getSumAfterInterest(person) == 1120.0);
  16. }
  17.  

Expectations are strict here - so they will be executed in exactly the same order and any additional call to the mocked object (or missing call) will lead to exception. We could relace it with NonStrictExpectations class to just omit that obligation. Also, we haven't defined our field as @Mocked because this annotation is applied by default in this case (all fields defined in the anonymous class are being mocked).

Number of calls

If we ignore the exact results but we only need to check the number of invocations, we might test that through Verifications.

  1.  
  2. @Mocked InterestCalculator interest;
  3. @Test(enabled=true)
  4. public void testFlowVerifiedInterest() {
  5. Person person = new Person("John", 1000);
  6. Bank bank = new Bank("Alpha", 0.2);
  7.  
  8. bank.getSumAfterInterest(person);
  9. bank.getSumAfterInterest(person);
  10. bank.getSumAfterInterest(person);
  11. bank.getSumAfterInterest(person);
  12.  
  13. new Verifications() {
  14. {
  15. interest.getInterest(anyDouble); minTimes = 0; maxTimes = 5;
  16. }
  17. };
  18. }
  19.  

Note: for direct mocking we could add the class as a method parameter. However as we have indirect call through the Bank class, we should define a @Mocked declaration which is visible for all test methods. If you have different definitions in other test methods, remove the Mocked class field when executing other tests.

We could also mix the usage of Expectations and Verifications. Just don't repeat the same code in both blocks cause this would lead to ... well, mistake. Anyway, you could define the mocked class in the Expectations block and omit the usage of the class field. There are also three more types of verifications - InOrder, Full and both (FullVerificationsInOrder). 

Specific behavior

Sometimes we need to declare a more complex logic or just to redefine the class we would normally use in an application. This is the chance for creating a class - replacer as a MockUp where we could define our logic:

  1.  
  2. @Test(enabled=true)
  3. public void testStubbedInterest() {
  4. new MockUp<InterestCalculator>() {
  5. int percentage;
  6. @Mock
  7. public double getInterest(double sum) {
  8. return 0.1 * ++percentage;
  9. // hacky, nah?
  10. // return new Random().nextDouble() * 100;
  11. }
  12. };
  13.  
  14. Person person = new Person("John", 1000);
  15. Bank bank = new Bank("Alpha", 0.2);
  16.  
  17. System.out.println(bank.getSumAfterInterest(person));
  18. System.out.println(bank.getSumAfterInterest(person));
  19. System.out.println(bank.getSumAfterInterest(person));
  20. }
  21.  

Analogically we could mock the Bank class as well by using either Expectations, or Verifications or MockUp when we only expect specific calls, need to check the number of invocations or need to redefine behavior. Try it and see. And here is the demo downloadable (don't forget to set run parameters to enable the jmockit usage and the integration of testng).

Also, check out my JMockit presentation on Slideshare:

del.icio.us Digg DZone Facebook Google Google Reader Magnolia reddit SlashDot Technorati ReadMe.ru Dobavi.com Dao.bg Lubimi.com Ping.bg Pipe.bg Svejo.net Web-bg.com

Python, SVN and Android

 

Three things with not much in common, except that these are the three interesting things around me these days.

For the last 2 weeks I do python development (actually Django) for an international project while I'm ending my CakePHP and Digital Signer applications. I set up Subclipse in my Eclipse because I got tired of committing twice some of my files. This way my SVN is connected to the project in the IDE and the new data is deployed in an easy and beautiful way without any console commits.

The Django projects are fine as well. I do researches over the multilingual applications. So far I found url-locale and multilingual modules which serve to detect the language via the URL and create a multilingual content while create the intermediate tables for that. I continue researching the session system in order to save the languages there where switching around.

As for the Android, I plan to do my first app for almost a year. Recently I had a few job proposals for Android development plus the Mtel contest for Android app. That's why I downloaded the SDK and the Android plugin and started from the Hello World tutorial online. More researches are done and I am willing to test a more complex application with Internet activity, of course.

del.icio.us Digg DZone Facebook Google Google Reader Magnolia reddit SlashDot Technorati ReadMe.ru Dobavi.com Dao.bg Lubimi.com Ping.bg Pipe.bg Svejo.net Web-bg.com

Digital signatures and PDF signing

 

I am working on a project that requires PDF signing through a website.

The current infrastructure includes Apache + PHP website available. What we need to achieve is integrate the digital signature module of a user visiting the website and sign the required files. One of the most appropriate solutions after the negotiations was signed applet that signs PDFs.

  1. The steps for the project creation are the following:
  2. Create an applet
  3. Create a certificate to sign the applet via keystore tool (if root CA's are not available)
  4. Sign the applet (allowing read/write access to users' hard drives)
  5. Create a REST implementation that could read/write to the server database via HTTP
  6. Implement the iText API
  7. Create an appropriate interface to list certificates and documents, too
  8. Sign each of the documents

Some useful materials on the topic:

How to sign a Java applet

How to sign an applet (and get it to work)

Oracle Signed applets tutorial

Creating PDF with Java and iText

How to sign a PDF using iText

LifeCycle ES PDF signing (the Adobe way)

del.icio.us Digg DZone Facebook Google Google Reader Magnolia reddit SlashDot Technorati ReadMe.ru Dobavi.com Dao.bg Lubimi.com Ping.bg Pipe.bg Svejo.net Web-bg.com

Database training in Switzerland

 

Last week I gave a database training in Switzerland. We had a look into relational databases, normalization theory, some good principles on database modelling, SQL language.

As of the used tools, we had an overview of Oracle 11g free database server, as well as Oracle SQL Developer tool to access the database systems. The E/R diagram toolkit we used to train on was TOAD data modeller. The previous versions of the tool were freeware, but the last implementations available are only evaluation for 2 weeks. You could try to find an old version that does the general work - database drawing, generation of SQL (as well as simple reverse engineering), creation of relations - identifying and non-identifying, as for one-to-one, one-to-many and many-to-many relationships.

In my training here I also extend the presentations with PL/SQL tips and tricks, Object relational mapping with Hibernate and JPA and few practical projects in classes.

del.icio.us Digg DZone Facebook Google Google Reader Magnolia reddit SlashDot Technorati ReadMe.ru Dobavi.com Dao.bg Lubimi.com Ping.bg Pipe.bg Svejo.net Web-bg.com

Project-base, Support and Salary

 

During my couple years of work as a PC techy support guy, administrator, company hired developer and freelancer, I've finally separated three different types of work: project-base, support and salary.

Project-base

This is a popular way of working in USA and Europe. The client has a task to be performed by an expert. Therefore the employer seeks for an appropriate guru to fulfil the one's requirement. Simple as that.

What are the major characteristics of project-base work?

  • fixed requirements
  • usually short-term or medium-term
  • fixed price for the whole project or different phases

Focusing on the broader perspective, a freelancer could be hired for a small website or script, but there are big corporate systems developed for tens of manmonths, too. So borders may vary. But requirements are fixed at the beginning, as for the money, too. No surprises during the development process.

Support

Support staff is hired for a preliminary defined schedule. Let's say every second Monday of the month or for 10 hours for the whole month. This is a capacity being paid at the beginning for doing simple (or important, but not that time wasting) tasks. The client doesn't need a full time expert, but wants a regular technical guy to be available for consultations or small fixes.

Usually, typical support marks:

  • fixed work-time or hours
  • fixed month/hour price

Support work could be tricky if you maintain couple of different support projects. But if business case is clear and hours can be easily predicted, than it is a sweet and not that engaging perspective.

Salary

That's probably the most popular working type in the world. Rules are simple: you have a week amount to fill and... you just have to fill it. Let's say 40h a week, 9am to 6pm working  at the office and that's all. Irregular overtime, constant availability. Tasks may vary - the employee is available at the work time he is contracted for and can be 'squeezed' for different tasks/services.

What's cool with salary work?

  • regular and usually good payment
  • some benefits as transportation taxes covered or cell phone bills
  • work ands at 18 o'clock and then you're all free

And what kind of work do you do?

del.icio.us Digg DZone Facebook Google Google Reader Magnolia reddit SlashDot Technorati ReadMe.ru Dobavi.com Dao.bg Lubimi.com Ping.bg Pipe.bg Svejo.net Web-bg.com

Collabtive – cannot login after installation

 

I had a research on project management systems. My top 2 choices were .project and Collabtive. Unfortunately I was unable to properly install the .project and logically rejected using it as a personal PM solution.

What I find charming in Collabtive is the concept of usability - most important sections are in the horizontal menu on the top. The system is AJAX-oriented which makes passing through different modules almost transparent. There are few important mods:

  • Projects
  • Tasklists/Tasks
  • Users
  • Messages
  • Tracking

So, what can you do with Collabtive? Add users with privillegies, write description for your clients and projects, then divide them by phases and add tasklists with tasks. You could set start/end hour for working projects and receive an invoice-like print preview of all projects and how long did you work on them. Fair enough. The only missing feature is automatic tracking and start/stop button for tasks - when you don't have to take care of start and end hour of each task.

Hope this one would be implemented, too. Otherwise you could use Toggl - either the whole PM system, or the timer only. Or use a custom tracking script.

I was surprised that I was unable to login for second time after logout. There was a technical problem with the system. I tried a couple of things to fix the issue, but no success. Some of the known issues include incorrect session.save_path in the PHP settings which can be redefined to a path with writing permissions. The other was the magic quotes option that could misunderstand your user input and therefore change the password itself.

My server had writing permissions and session.save_path changed via php.ini file so problem was hiding somewhere else. The hardcore fix was changing the password from the database:

 

  1.  
  2. UPDATE user SET pass = SHA1('your password') WHERE ID = 1;

 

The Collabtive system uses SHA1 hashing for passes, so I just hashed the pass by myself. So it's working the correct way now.

del.icio.us Digg DZone Facebook Google Google Reader Magnolia reddit SlashDot Technorati ReadMe.ru Dobavi.com Dao.bg Lubimi.com Ping.bg Pipe.bg Svejo.net Web-bg.com

BubbleTip – jQuery bubble tooltip

 

I had to implement a bubble tooltip helper for a client. After a short research I tried the Coda Popup Bubbles.  Useful plugins that worked great for a couple of days, when I set it for a single text field and 2 browsers only. When I decided to integrate it as a platform independent snippet and add it to 10 more textfields, I hit a rock - indents from bubble to the textfield were not consistent, bubble was popping over the textfield etc. Some images were also missing - left and right borders in Firefox and the bottom arrow in Internet Explorer.

I used to hack the Javascript and CSS for 3 days and finally got stuck. I found a workaround working since then - the BubbleTip plugin, which is a modification of the upper one, but acting better in different browsers. Also, it's using an automatic offset which makes it far more useful when you have different text in bubbles.

del.icio.us Digg DZone Facebook Google Google Reader Magnolia reddit SlashDot Technorati ReadMe.ru Dobavi.com Dao.bg Lubimi.com Ping.bg Pipe.bg Svejo.net Web-bg.com