by Njål

Cancelling old S-* PayPal Subscriptions from code

2015-10-26_1408

PayPal does not support cancelling old S-* subscriptions from code/api’s. This means that either you (as a merchant) or the customer has to log in to PayPal’s API and cancel these subscriptions manually. #Pain.

Luckily – it can be automated using Phantom.js. Phantom.js is basically a rock solid webbrowser without a UI which you can program (JS) to do stuff for you. I have made a PayPal.js script which lets you input Email, Password and the old S- SubscriptionID you want to cancel.

Here’s how to use it:

  1. Download Phantom.js (2.0.0) – and Unpack it to a new folder – http://phantomjs.org
  2. Download PayPal.js and place it in the same folder
  3. Run phantomjs.exe –ssl-protocol=any paypal.js paypalemail@gmail.com MySecretPass S-123455634545234
  4. While it’s running – keep an eye on the folder. PNG screenshots will appear there providing you a peepshow of the progress.
  5. When done – your website will receive a IPN Callback from PayPal.

 

by Njål

Install4j: Installing to the home directory of user

 

Install4j is a great installer that wraps Java application into a native installer package & launcher (executable). It can embed JRE, so you won’t have to worry about user that don’t have Java installed.

When releasing our application I wanted to offer our customers two installers:

  1. One standard installer which installs the application to the home directory of the user. This application auto updates itself. No admin privileges required.

  2. One Terminal Server version which installs the program for all users. Admin privileges are needed to install, and auto updates are disabled since normal users can’t update the application anyways.

(This is the way Chrome and a lot of other great apps do it)

Making a Terminal Server installer was very easy. Just enable “For All Users” and set “Elevation”.

Here’s how you make the installer install into a users home directory by default:

context.setInstallationDirectory(new File(System.getProperty("user.home") + "/ArgusClient"));

 

image

 

 

The installer now suggests your home folder:image

by Njål

Displaying Chinese Characters in Java Swing (JLabel)

 

When opening files with chinese characters in my Java 6 Application – the JLabel displayed squares instead of the proper filename:

image

 

log4j logged the filename correctly

Nytt 提供.docx

so I figured it was a font problem. I tried Arial, Verdana, Tahoma, Serif and so on. Nothing worked.

 

Then I tried this setting on the JLabel in Netbeans:

image

 

and this seems to resolve the issue!
image

 

The Java equivalent of the Netbeans setting is:

jlDesc.setFont(jlDesc.getFont().deriveFont(jlDesc.getFont().getSize()-1f));
by Degree Admin

Introducing Cucumber

Cucumber

A large part of developing a successful IT application is ensuring the customers demands are met, and minimizing bugs as the system goes live. A good place to start is using an agile development strategy, with heavy customer involvement throughout the development cycle. For those who wish to learn more about agile development I would recommend reading “Agile Software Development: Principles, Patterns and Practices” by Robert C. Martin and “Agile Estimating and Planning” by Mike Cohn. Both are excellent books.

Some may have the belief agile development removes the necessity of documenting the system. This could not be further away from the truth. The principal behind agile is to plan as little as possible up front, and plan and document your system as you go. A good way to plan and document is by using User Stories. A User Story usually follow the “As a, I want, So that” pattern.
As a Blog writer
I want to preview my post
So that I can proofread my post before posting it.

Each User Story has several acceptance criteria which defines when a User Story is to be considered feature complete. Each acceptance criteria is written in a “Given, When, Then” grammar. One criteria for each case to test.
Given I have written a post
When I navigate to the preview
Then I want to see my post as it would be shown in the blog

Given I have navigated to the preview
When I use the cancel function
Then I want to return to edit mode

An user story is considered complete when all of its acceptance criteria are met and accepted.

When developing a small system with few stories, this is manageable. But as the project increases in size, ensuring that a user story is met, and ensuring nothing breaks as the development continues gets increasingly difficult. Having a large dedicated test crew is one way of solving it, but as the project progress their workload increase as they have to test all completed tests to ensure regression. So there has to be a better way?

Cucumber is a behavior driven development testing platform. It is originally a Ruby project, but has been adopted to all major languages. The idea behind Cucumber is to create executable tests from your acceptance criteria. So instead of adapting your testing criteria to fit a testing framework, Cucumber makes the testing framework fit your criteria.

So how does Cucumber do this?

By regular expressions, and by adapting the Given When Then pattern of writing acceptance criteria. Let’s elaborate.

Let’s say you were making an calculator which should be able to do the basic operations. We would start by making a user story for the add operation.
To be able to get the sum of some number
I would like to input a series of numbers and get the correct sum
So that no errors

Given I want to add the numbers “10” and “15”
When I press equals
Then the result should be 25

Given I want to add the numbers “1”, “-6” and “5”
When I press equals
Then the result should be 0

This is how a potential User Story from your client could look like.

To make cucumber understand this, we have to write a couple of step definitions. Cucumber adds java support through the Cuke4Duke project. This project adds some annotations to write your steps.

@StepDefinition
public Class CalculatorSteps(){
private Calculator calculator = new Calculator();

@Given(“I want to add the number(s) \”(\d*)\” and \\”(+d*)”)
public void addNumbers(int number1, int number2){
calculator.add(number1, number2);
}

@When(“I press equals”)
public void callEquals(){
result = calculator.sum();
}

@Then(“the result should be \”(\d*)\”)
public void checkResult(int expected){
assertEquals(“the result does not match”, result, expected); //Junit functions.
}
}

That’s it. Now you can begin programming your calculator. Yes that’s right. You always write your tests up front. Cucumber and unit tests.

So check out Cucumber on cucues.info and start using it.

There is also a .NET version of cucumber called Cuke4Nuke

by Njål

Grafiske grensesnitt i Java – Utvikling, installasjon og vedlikehold

What to choose… what to choose..

Dersom man skal utvikle en applikasjon som skal kjøre på Windows, Mac, Linux, Solaris etc. så er det ikke så ekstremt mange teknologier å velge i mellom. Java, QT og Mono er noen av kandidatene. Adobe Air er også en mulighet, men denne platformen har ekstremt dårlig ytelse, mangler støtte for flere tråder og dårlige grensensitt mot minne/disk. Har prøvd og forkastet. Mono har jeg aldri testet noe særlig, selv om jeg daglig sitter og koder C#. Skal definitivt sjekkes ut. Norske QT og deres C++ bibliotek/verktøy ser også veldig bra ut. Rå ytelse og mye bra omtale – visste du at Photoshop er utviklet i QT? Anyways… gjett hvilken teknologi hva vi valgte… crazy!

Utvikling med Java

Valget falt altså på Java når vi skulle utvikle noen Filemail applikasjoner for Windows/Mac/Linux. Vi har levert en del løsninger med Java før og visste på forhånd at vi ikke kom til å få nevneverdige problemer med ytelse. Et ganske trygt (men ikke direkte spennende) valg.

Utvikling av komprimering, hashing, kommunikasjon og filoverføring via egne protokoller gikk som fot i hose. Men vi ble fort gjort oppmerksom på GUI drawbacket til Java. Det er absolutt mulig å lage gode grafiske grensesnitt med Java, men det er tidkrevende i forhold til Windows Forms, Adobe Air, QT etc. Det kan også være litt tricky å få en Java applikasjon til å se ut som en native applikasjon (dvs. når den kjører på Mac så skal det se ut som en Mac applikasjon).

Etter litt fikling kom vi ca. i mål med et akseptabelt GUI (Netbeans + matisse + div 3. parts biblioteker):

Ikke superfett, men greit nok. (Applikasjonen lar folk sende store filer på 1-2-3. Brukes bl.a. av NRK, TV2 og VG. Sjekk www.filemail.com)

Innpakking og installasjon

Videre kom spørsmålet om installasjon av applikasjonen. En mulighet var å gjøre brukeren oppmerksom på at Java kreves, og la han/henne laste ned applikasjonen i form av en JAR fil. Ikke akkurat superelegant.

En bedre løsning som har fungert bra for oss er install4j. Denne applikasjonen tar JAR filen (programmet) og lager native install pakker for Windows, OS X og Linux. Videre finnes det mulighet for å inkludere Java VM’en i installasjonsfilen, slik at brukeren ikke får problemer dersom han/hun ikke har Java installert.

Det blir også generert .exe (.app /.sh) filer og snarveier for å starte applikasjonen etter at den er installert. Det eneste disse små launcher’ene gjør er å kjøre igang JAR filen som også blir installert. Uninstaller etc. blir også lagd. Nice.

Et annet alternativ for windows/linux er å bruke Excelsior JET – dette rekompilerer java programmet og java VM’en til en .exe/.sh fil. En fordel med denne kompileringen er at koden blir obfuskert (nesten umulig å dekompilere), samtidig som det er en ulempe at .exe/.sh filen blir ganske stor ettersom java vm’en inkluderes.

Oppdateringer og vedlikehold

Ettersom det er JAR filen som er selve programmet, er det relative lett å implementere oppdateringsfunksjonalitet. Det er bare å få applikasjonen selv til å hente ned en ny JAR fil, starte på nytt – og vips så er den oppdatert til nyeste versjon – på alle platformer!

Final words

Neste gang faller kanskje valget på QT når vi skal utvikle en applikasjon for flere platformer. Dette virker veldig spennende, man har mange muligheter og få begrensninger. Det ser også produktivt ut.

Hvilke teknologier benytter du for å lage applikasjoner som skal kjøre på flere platformer? Tips og triks mottas med takk!

Tags: