Pesquisar neste blogue

segunda-feira, 31 de dezembro de 2018

Technical - Year review and looking forward

Technically wise this year was amazing , in terms of the technologies i had to either deal with or learn.
If i had to do a top 3, no order implicit, i would say:

  • Cisco Kubernetes Solutions - I had the opportunity to attend at WebSummit a presentation on  Cisco Container Platform and i must say it was the one that stuck with me. The way AI and Deep Learning is integrated with the whole platform really left an impression on me.  I recommend you see this video Cisco Artificial Intelligence at Cisco with Kubeflow . Deep learning will be my main learning focus in 2019.

  • SteamPlay - As a Linux user, this is one of those things i always craved for: Seamless integration of Wine and Steam .At this moment in time it is still not perfect, but its future potential is huge, even outside of Linux/SteamOS. In 2019 i am hoping for Stemplay to branch out to MacOS X and to Android based machines. The possibility of running Windows applications on ARM devices is something i feel a lot of people will be looking into, in the not so distant future (hint hint Snapdragon 8cx )

  •  Vulkan - If w« you have either a Nintendo Switch , a MacOS X /IOS machine , a Linux Desktop, Windows Machine, anything else, there is a chance a Vulkan Graphics API driver is available for your machine.  Having a single API to write against is something that cannot be undervalued. Saves you money, time and gives you a much greater user base.
       “The needs of the many outweigh the needs of the few” .


Hardware wise, i have to give it to Apple . My IPad Air is still rocking and the update to  IOS 12 just made it feel brand new.
Updated my desktop PC to a AMD Ryzen platform from an Core i5 - 3rd gen and i am happy. 😀


On the dark side, lays my Android phone Honor 8 for which OTA updates seem to have left me and gone on vacations. It is still a fully usable phone but the lack of security updates and platform updates makes me feel a bit "bah" on a 2 year phone with better specs than an Iphone Xr Compare Apple iPhone XR vs Honor 8 64GB
Have to do my research on terms of updates a bit more next time i buy a phone, or for that matter anything with Android (people talk up Xiaomi and oneplus  in this department)
My wish for 2019 is for a new contender to appear in this space (SailfishOS maybe).
 

sábado, 29 de dezembro de 2018

Non technical - Year review and looking forward

This year was a slow one , with some big highlights both my private life and professionally .

Having a chance to travel with my future wife this year helped stabilize my life. It is kinda funny how going places, even if they are not very different from your home town, broadens your horizons and makes you feel and notice things you would probably not care about when you come back home.
Had a chance to visit Berlin, amazing city loved it, for a opera show and came back with the German language so stuck on my head that when i landed in Lisbon i had this weird sense that everyone would still speak in German.
Of course i had to start learning the language. That is a must do point for me in 2019.
Also on my birthday i was given the chance to attend the F1 race in Barcelona and for a die hard F1 fan like me it was a experience i will cherish for a long long time. Even if today i look at Formula E with more interest (i love racing and engineering wise electric vehicles are a more daunting project)  than F1, i still wake up  before dawn to watch races. Can't wait for February to see new cars. Let's hope that Williams F1 (more on them a bit below) and Mclaren get up the ladder. Mclaren did that project with OnePlus so let's hope they can "warp charge" their season.
This year my main media comsuption platform was youtube.comDigitalFoundry was my main go to after work. A lot of work goes into their videos and it shows.
Latter on the year i came accross Vin and Sori on a reaction video  (they seem to have exploded on this year) and i must say it was one of my best findings of 2018.
There were some bad moments, the passing of one of my grandmothers, some people who revealed their true self and it was a bad sight.

Professionally still on the same job, however got chances of capitalizing on my knowledge elsewhere also. On 2019 i do plan on expanding that side. The post with more views on this blog was the PDF Signing without Java. and maybe i'll explore a bit more on that side. If there is something related to Java/Javascript that you would like to read about please let me know.
Also been looking into elementaryOS and the way they try to entice developers (you can leave an idea for an app on the comments section).
Also this year had a chance to attend the WebSummit at Lisbon and it was amazing. Saw a lot of tech stuff , i'll keep that for a future post, but was surprised me the most was the applications that Williams has developed for use outside F1. I was like "How come i don't this stuff" - for instance BabyPod .

A long post already, so more technical stuff for next post.
Have a nice entry into the new year.

segunda-feira, 17 de dezembro de 2018

CSV handling in Java

These past days i've been trying to load CSV files in Java. Used opencsv with some degree with success, however some fields were still misinterpreted .
Next an old friend by name of FasterXML/jackson came to the rescue, however i was still having some issues.
Last but not least on stackoverflow.com (where else) i came across https://simpleflatmapper.org/ and with something like:


CsvParser.separator(';')

   .mapTo(MyClass.class)

   .headers("my","headers","list")

   .iterator(new File(filepath));


I was up and running .

Note : If you find MalformedInputException check if your input is UTF-8 , more info here  http://biercoff.com/malformedinputexception-input-length-1-exception-solution-for-scala-and-java/

terça-feira, 13 de novembro de 2018

JAVAMAIL: Cleaning temporary files used as attachments

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
private static void cleanAttachments(MimeMessage message) {
   try {
 if (message.getContent() != null) {
  MimeMultipart multi = (MimeMultipart) message.getContent();
  for (int j = 0; j < multi.getCount(); j++) {
   BodyPart bodyPart = multi.getBodyPart(j);
   if (bodyPart.getDataHandler().getDataSource()
     instanceof FileDataSource) {
    FileDataSource f = (FileDataSource)
    bodyPart.getDataHandler().getDataSource();
    f.getFile().delete();
   }
  }
 }
  } catch (MessagingException e) {
  e.printStackTrace();
  } catch (IOException e) {
  e.printStackTrace();
  }
}

For when you use File.createTempFile  to support the attachments of a mail message and cannot use deleteOnExit because the JVM will not exit.
Something i saw myself needing.

All the best.

sexta-feira, 29 de junho de 2018

Generating PDF from a webpage using JavaScript

A requisite for a project i was working on a while back was to generate a reader like version of a webpage and export it to PDF.
I started by getting a printable format for the webpage which was not that difficult, just removing some classes and adding some css with Jquery.

Now came the fun part.

What if i could do all of this on the client side, using JavaScript.



Imagine you're the server and your project manager is the browser. What a fine day it would be when a project manager interrupts you with something he/she could do.
Moreover i would save some cpu cycles on the server and learn something new in the process.

So with the help of stackoverflow my journey began.
What do i need :

  • Something to generate PDF in JavaScript -I came across jsPDF it has a very simple API and is really simple to use.
  • Now i need something that can make like a screenshot of the element . Again with the help of StackOverflow i came across  - html2canvas .

Using both together is really simple

        html2canvas($("#canvas"), {
            onrendered: function(canvas) {         
                var imgData = canvas.toDataURL(
                    'image/png');              
                var doc = new jsPDF('p', 'mm');
                doc.addImage(imgData, 'PNG', 10, 10);
                doc.save('sample-file.pdf');
            }
        });



From post at stackoverflow.com

I do recommend taking a look at the of jsPDF Examples
If your files are coming out a bit on the large size you may also compress it -jsPDF constructor has a flag to enable compression. My pdf came from about 14 megs to 240kb.




 The trickiest bit happens when your image is bigger than a page. In that case you must treat your image like a sliding window, effective splitting the image through several pages. A good example code can be found on

Hopefully you find this useful, i have tried to gather most of the sources i went through to learn.
Credit to the devs @ stackoverflow .


And thanks to those that :





sábado, 28 de abril de 2018

Thinking about the past , moving to the future



Image retrieved at wired

Some days ago on my 35th birthday, after a number of surprises from my future wife and my parents, i found myself digging into my past on some old boxes my parents had at their home. Found stuff ranging from  cheesy late 80's Portuguese music to 56k modem's and a passively cooled Riva TNT.
Gaming of course was already a big part of my life back then, even more so than today i regret to admit, so i had a good time going through my old gaming systems (Master System, Sega Saturn, Sega Dreamcast - yep i'm a Sega guy -  PC builds) and a lot of magazines.
A particular magazine from 1995 had a review of Phantasmagoria.  I must admit the FMV point and click genre always passed me by - not sure if the sheer amount of cds or the movie quality itself - but i was never drawn into it.
At that time some - Ripper  for instance - even had a cast that would make a wanna be movie director give some limbs for.
The general consensus at the time was that a mouse was not the best tool to experience such artistic achievements - "if i wanna read a book ,i'll read a book..if i wanna watch a movie, i'll watch a movie i don't see the need to click a mouse to go through it" was a quote i can't pinpoint exactly to whom said but seemed the general opinion.
Moving on to 2018, VR/AR is gaining more and more traction, gaming has become the number one entertainment in terms of revenue - nasdaq.com - so how really far are we from movie studios converting some movies into games - a side adventure on the universe of "Blade Runner 2049" would make this particular person pay without looking back.
A few examples i have found are

 Are there any more that you are aware of?

I usually like to write, think, listening to music. So if this post can be described by a song my choice goes to 

quinta-feira, 5 de abril de 2018

How to convert Pem certificate to Hex string in Java (a stackoverflow conglumerate)


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//*******************************************************************
// Welcome to CompileJava!
// If you experience any issues, please contact us ('More Info')  -->
//*******************************************************************

import java.lang.Math; // headers MUST be above the first class
import java.util.Base64;

// one class needs to have a main() method
public class HelloWorld
{
  public static String toHexString( byte[] bytes )
  {
      StringBuffer sb = new StringBuffer( bytes.length*2 );
      for( int i = 0; i < bytes.length; i++ )
      {
          sb.append( toHex(bytes[i] >> 4) );
          sb.append( toHex(bytes[i]) );
      }

      return sb.toString();
  }
  private static char toHex(int nibble)
  {
      final char[] hexDigit =
      {
          '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'
      };
      return hexDigit[nibble & 0xF];
  }
  // arguments are passed using the text field below this editor
  public static void main(String[] args)
  {
    String pemText="-----BEGIN CERTIFICATE-----"+
"blablabla"+
"-----END CERTIFICATE-----";
   byte[] certificateBytes = Base64.getDecoder().decode(
    pemText.replaceAll("-----(BEGIN|END) CERTIFICATE-----", "").replaceAll("\n", "").getBytes()
);
    System.out.println(toHexString(certificateBytes));
  }
}

quarta-feira, 4 de abril de 2018

That nice function you didn't know existed

Today while trying to solve a problem with PLSQL i came across  DBMS_UTILITY.FORMAT_ERROR_BACKTRACE  dba-oracle.com

This nice function gives you a more complete backtrace of where the exception ocurred.
Me afterwards: