Finance Currency Convert

by GarciaPL on Tuesday 17 February 2015

After my last trip do Budapest with my wife (I really recommend going to this town! It's wonderful! not only building, but also people are very very nice to tourists), I had a little forints. There is not such much of them, but recently I was checking what is the current currency rate of forint to exchange those money. It was no such difficult to do it, I just did request to Google like '9000 HUF to PLN'. Then idea came to me, that I can wrote some script in Perl which can do it for me and additionally inform via email when there is a good opportunity to exchange those money.

For sending emails I used very nice API called Mandrill [2]. For currency convert from HUF to PLN I used module called Finance::Currency::Convert::Yahoo [3].

#!/usr/bin/perl -w
use strict;
use POSIX;
use WebService::Mandrill;
use Finance::Currency::Convert::Yahoo;
 
$Finance::Currency::Convert::Yahoo::CHAT = 1;
$_ = Finance::Currency::Convert::Yahoo::convert(9430,'HUF','PLN');
 
if (defined($_)) {
   if (floor($_) gt 135) {
      print "Sell HUF : ".floor($_)."\n";
      send_email('receiver@gmail.com', 'Sell HUF', 'Right now there is the time to sell HUF');
   } else {
      print "Keep HUF\n";
   }
} else {
   print "Error\n";  
}
 
sub send_email {
 
        (my $to, my $subject, my $body) = @_;
 
        my $mandrill = WebService::Mandrill->new(
                debug   => 1,
                api_key => 'YOUR_API_TO_MANDRILL',
        );
 
        my $response = $mandrill->send(
                subject      => $subject,
                from_email   => "sender\@gmail.com",
                text         => $body,
                track_opens  => 1,
                track_clicks => 1,
                to => [
                    { email => $to }
                ],
        );
}




Reference : [1] Pastebin Source Code Finance Current Convert [2] Mandrill.com [3] CPAN Finance::Currency::Convert::Yahoo

Launch4j - Generate exe from jar

by GarciaPL on Saturday 7 February 2015

Sometimes there is a some particular need that your program (of course mainly written in Java, that's obvious) must also be able to work under Windows environment (sic!). There is no such problem if you program will have still .jar extension, but recently business in my company demanded to create such program with .exe extension. I was convinced that it's not really possible. I was thinking how to mix different approaches to create applications under Windows and Linux environment.

But I finally found a very helpful and customizable tool called Launch4j [1]. This tool is mainly used by Graphical User Interface (GUI) where you define all configuration for instance Input (jar) and Output file (exe), some classpath, header, JRE version required by application to work, some custom environment variables, splash and of course information about version, copyright, product and company name etc.

Regarding to my case in company I must transform .jar to .exe file without using GUI. There was a need to create some REST interface which will receive some parameters like .jar file, .icon and other specified information to generate generic .exe file using of course launch4j.

To do so, you must include launch4j.jar to your project and use below Java code to generate .exe.

    public static void main(String[] args) {
        try {
            File file = new File("/home/lciesluk/configuration.xml");
            try {
                ConfigPersister.getInstance().load(file);
            } catch (ConfigPersisterException ex) {
                System.out.println("ConfigPersisterException " + ex.getMessage());
            }

            Config config = ConfigPersister.getInstance().getConfig();
            System.out.println("Input : " + config.getJar().getAbsolutePath());
            System.out.println("Output : " + config.getOutfile().getAbsolutePath());

            File baseDir = new File("/home/lciesluk/launch4j"); //extracted launch4j
            Builder b = new Builder(Log.getAntLog(), baseDir);
            File build = b.build();
            System.out.println("EXE location : " + build.getAbsolutePath());
        } catch (BuilderException ex) {
            System.out.println("BuilderException " + ex.getMessage());
        }
    }

I added also an additional sample of configuration file used by launch4j [2].
<launch4jconfig>
  <dontwrapjar>false</dontwrapjar>
  <headertype>gui</headertype>
  <jar>/home/lukasz/Motohurt.jar</jar>
  <outfile>/home/lukasz/Motohurt.exe</outfile>
  <errtitle>Please download and install Java</errtitle>
  <cmdline></cmdline>
  <chdir>.</chdir>
  <priority>normal</priority>
  <downloadurl>http://java.com/download</downloadurl>
  <supporturl></supporturl>
  <stayalive>false</stayalive>
  <restartoncrash>false</restartoncrash>
  <manifest></manifest>
  <icon>/home/lukasz/icon.ico</icon>
  <jre>
    <path></path>
    <bundledjre64bit>false</bundledjre64bit>
    <bundledjreasfallback>false</bundledjreasfallback>
    <minversion>1.7.0</minversion>
    <maxversion></maxversion>
    <jdkpreference>preferJre</jdkpreference>
    <runtimebits>64/32</runtimebits>
  </jre>
  <versioninfo>
    <fileversion>1.0.0.0</fileversion>
    <txtfileversion>1.0</txtfileversion>
    <filedescription>App</filedescription>
    <copyright>GarciaPL</copyright>
    <productversion>1.0.0.0</productversion>
    <txtproductversion>1.0</txtproductversion>
    <productname>App</productname>
    <companyname>GarciaPL</companyname>
    <internalname>GarciaPL</internalname>
    <originalfilename>App.exe</originalfilename>
  </versioninfo>
</launch4jconfig>

Reference : [1] Launch4j Home Page [2] Launch4j Configuration XML

Grand Prix BIHAPI

by GarciaPL

On 29th January in European Center of Solidarność in Gdańsk were announced results of BIHAPI competition. First winner of competition was "CoSieStao" which allows users access to various types of information related with town/district where they live. Application was created by Paweł Konieczny and Piotr Martyniak. There were also awarded such applications like "Via CRM the first passenger relationship management in the world", "Poczytaj mi", "Stacz kolejkowy" and "IfCity". More information about competition and awarded applications can be found under www.bihapi.pl.

Competition partners :

Oracle Communication (technology partner), Capital City Warsaw, Gdańsk, Poznań, Poznańskie Centrum Superkomputerowo-Sieciowe, IQ Partners, Black Pearls, SpeedUp Group, Investin, Fundacja TechSoup, Orange Foundation, Fundacja Pracownia badań i innowacji społecznych Stocznia, Centrum Cyfrowe Fundacja Projekt: Polska, geecon.org, Gdański Park Naukowo-Techniczny, Uniwersytet Ekonomiczny w Poznaniu, Warsaw University of Technology, Międzynarodowe Targi Poznańskie.



 BIHAPI Grand Prix