Pesquisar neste blogue

sexta-feira, 13 de setembro de 2019

Xbox + Cxbx + Linux

Today i decided it would be the day i tried to fix the problems i had been having with Cxbx-Reloaded and Linux.
Armed with Duke and a 3 in 1 Magic Box there i went.


My first problem was that CDEMU did not mount the images of my games.
A bit of google-fu after i found xbfuse . Installed on Ubuntu libfuse-dev and after a little and very cleanly the program was compiled.

Next running CXBX-Reloaded itself was giving me issues, which from the debugger i could see were related to missing functions from Wine builtin dll.Using Winetricks i was able to install the vc2017 package.

And then


Now let's see if the controllers work..

terça-feira, 19 de março de 2019

Google Stadia - Glimpse of the future?





With the introduction of Google Stadia today the gaming world became a bit more confusing. Don't get me wrong from a technical standpoint Stadia is amazing. Running on next-gen AMD custom hardware, and on top of Google's infrastructure you have to accept that what was presented was something special (well the controller..).

However technology alone does not make a product successful. I'd like to focus on two points:

- How much revenue will this generate for the content creators? We've seen some games moving from Steam to Epic with the promise of a bigger slice of the cake.
With the onus on Google/Microsoft/Apple, how much will it have to cost to be profitable for the provider and its partners?  Microsoft has a winning point here as already as an installed base of users, owns several game studios and seems willing into the integrate better with what exists now than the vision Google is selling.
Apple is rumoured to enter this market (https://www.techradar.com/news/apple-is-reportedly-putting-together-a-netflix-for-games-streaming-service), however if they choose to do so, partners are a must. Valve with SteamPlay (https://support.steampowered.com/kb_article.php?ref=9439-QHKN-1308) , Steam RemotePlay (https://store.steampowered.com/streaming/) and the new Steam Link app (when they decide to unblock it ) Sony has recently announced streaming to iOS devices (https://itunes.apple.com/us/app/ps4-remote-play/id1436192460?mt=8).

- One thing i dislike about games with a big component on the cloud and multiplayer side, is that when the fanfare surrounding the game ends the company shutdowns the servers and boom no more game. Streaming for me has the potential to bring this to the whole catalog of games. As a gamer, even if i'm the only person on the world playing a given game i would like to have a chance to play it whenever i want and not have it removed from the catalog of available games because it is too old or just not good for business. And it is on this point i believe the existing game stores can thrive. Consider still the Nintendo Switch and the physical launch of games (https://www.gamesindustry.biz/articles/2017-11-17-nintendo-switch-is-dominated-by-physical-sales-game).

sexta-feira, 4 de janeiro de 2019

Validating XML against XSD in Java

There are several ways to do this however to most simplest way i came across is using XmlUnit

From the manual

Validator v = Validator.forLanguage(Languages.W3C_XML_SCHEMA_NS_URI);
v.setSchemaSource(new StreamSource("Book.xsd"));
ValidationResult r = v.validateInstance(new StreamSource(new File("Book.xml")));
 
StreamSource accepts more constructors as shown here StreamSource Doc 

Here is the API of ValidationResult so you can transverse the problems encountered.

I usually work with Oracle Databases so i found this thread to create a XSD file from a table.

So if you need to validate data coming your table from a given file (csv,xlsx etc..) my suggestions are :

  • Look into SimpleFlatMapper to load the data.  
  • Look into Jackson to convert into XML
  • Consider XmlUnit to do the validation.
All the best.

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:


quarta-feira, 20 de dezembro de 2017

When we didn't call it a blockchain




Blockchain seems to be one of the buzz words in the tech world right now - at WebSummit 2017 for sure one of the 3 top words i retained - and some hope with a bright future ahead.
For the non tech it's the way bitcoin works.
Trying to learn more about the technology i came across Learn Blockchains by making one.
And a sentence resonated with something i had done in the past
At this point, the idea of a chain should be apparent—each new block contains within itself, the hash of the previous Block
SAFT-PT (Standard Audit File for Tax purposes Portuguese Version) uses this method to easily identify and verify the correctness of a series of invoices and other tax related documents.
Part of my first job was implementing this on what was then OpenERP (now Odoo) in order to get the program certified by the DGCI (Portugal's main Institute of tax related matters). If you wish to take a closer look at file's structure it is available at SAFT-PT XSD.

Each block is formed by
  • InvoiceDate
  • SystemEntryDate
  • InvoiceNo
  • GrossTotal
  • Hash (hash of the former document thus creating a chain)

DGCI supplies a validator for the file given the public key and the SAFT-PT file.
On any invoice you will find a sequence of 4 characters (corresponding to the 1º, o 11º, o 21º e o 31º digits of the store signature) followed by the name of the certified company.
If you use Odoo and wish to take a look at a base implementation it can be found here - Odoo SAFT-PT- it is not complete and but it should be nice as a basis for a complete implementation.


PS: This article is also available at my LinkedIn.

sexta-feira, 15 de dezembro de 2017

Now for something completely different

It has been an eternity i have posted anything here, not that i have done anything in the meanwhile but simply life took the best of me.
I was lucky enough to get tickets for @WebSummit in Lisbon, and it was a humbling and motivating experience at the same time. Went with my friend and WordPress master and VR/AR enthusiast Pedro de Carvalho @ twitter and it sure opened my eyes and mind for many new things.



One of the projects i have setup my self for this year was to loose weight and take "Improvement Dedication Success" a bit more physical not just on tech side of things. I must recommend Nokia Body Cardio as it during these last past months it has allowed me to tailor my behaviour, exercise and eating habits to make sure it sticks.

Now a word from the man who inspired me the name this blog "Improvement.."

 I'll try to keep posting more frequently.


sábado, 22 de outubro de 2016

WxWidgets / GTK and Vulkan



There is a project called RPCS3 which aims to emulate the PS3 gaming console.
Being a Linux user and a someone who enjoys emulation i felt i could give a hand , limited to my knowledge and time, but something that would help.
After some time, too much in fact, and helped by the community surrounding the emulator - https://github.com/RPCS3/rpcs3/issues/2186#issuecomment-255329581 - i was able to achieve something.

Also due to take a look at https://gist.github.com/graphitemaster/e162a24e57379af840d4 if you are willing to start with Vulkan.

The application uses WxWidgets as its GUI lib, and it can have a lot of backends (GTK2,GTK3,Windows) etc.. so the main work was to retrieve the X11 surface id to create a swapchain and integrate it with all the amazing code the team had already made.
A snippet of the code, for GTK2, is below



1
2
3
4
5
GtkWidget * widget=(GtkWidget*)m_frame->handle();
    gtk_widget_realize(widget);
    Display* display = GDK_DISPLAY_XDISPLAY(gtk_widget_get_display(widget));
     xcb_connection_t * c=XGetXCBConnection(display);
    xcb_window_t w;    



More info can be found at http://stackoverflow.com/questions/14788439/getting-x11-window-handle-from-gtkwidget

Also GCC not being able to compile the code whereas Clang would was a nice surprise :) Go Apple Go i guess :)

There are some bugs to be handled, however

sábado, 28 de maio de 2016

PDF Signing with Smartcards without Applets.

One of my recent projects at work involved developing an alternative  to applets to digital sign PDF files.

After some search i came across open-eid and namely browser-token-signing a true great endeavour from the © Estonian Information System Authority.
You can download their official builds at installer.id.ee. This will install extensions on your browsers that will allow the communication with the smartcards.

https://github.com/open-eid/hwcrypto.js/wiki/ModernAPI

On the client side we will need hwcrypto.js . This lib makes use of Promises caniuse.com which are not available on all browsers however there is a legacy version and other dependencies which can be put in place if you need them.
As stated on their wiki:

    *Support for IE8-IE10 requires a Promises polyfill; IE8 and IE9 also require TypedArray polyfill. Complimentary code is bundled into hwcrypto-legacy.js:

        https://github.com/inexorabletash/polyfill (license: Public Domain / MIT)
        https://github.com/getify/native-promise-only/ (license: MIT)

    Distribution and installation of the necessary platform components is out of scope of this project.


Let's take a look at their example code

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
// NB! This sample uses the legacy `hex` property!
window.hwcrypto.getCertificate({lang: 'en'}).then(function(certificate) {
   // Do something with the certificate, like prepare the hash to be signed
   var hash = calculateSHA256SignatureHashAsHexForCertificate(certificate.hex);
   // Now sign the hash
   window.hwcrypto.sign(certificate,
 {type: 'SHA-256', hex: hash}, {lang: 'en'}).then(function(signature) {
      // Do something with the signature
      storeSignature(signature.hex);
   }, function(error) {
      // Handle the error. `error.message` is one of the described error mnemonics
      console.log("Signing failed: " + error.message);
   });
});



 As our framework is Java based, to handle the PDF the itextpdf lib was used - itextpdf 5.5.9. I would like to state that with in some work / adaptation pdfsign.js may become the best way to implement such a system. 
To anyone implementing such a system i would like to leave the following notes:

  • If you use some objects to handle the PDF from the server side make sure they are the same all along the process. If not the PDF will still be signed but you may be faced with the "The document has been altered or corrupted since the signature was applied" error.
  • As Promises are  asynchronous take extra care when using it Ajax.

Taking the above into consideration just take a look at Bruno's amazing work/documentation itext-action-second-edition chapter-12  to proceed with the signature.

segunda-feira, 14 de março de 2016

On "New MIT Code Makes Web Pages Load 34 Percent Faster in Any Browser"

I would like to share some server side solutions that can speed up page and resource loading

https://github.com/galan/packtag - Have used this in Struts before and it does make a big difference
https://jawr.java.net/ -  Has Spring integration and seems really nice. A good starting point is showned on : http://memorynotfound.com/jawr-combine-minify-compress-javascript-css/

For .Net



With Apache/NGINX it is possible to develop a similar approach

https://www.nginx.com/resources/wiki/modules/concat/

RPCS3 + Ubuntu

This weekend i had some time to play around with a emulator ( RPCS3)  on my Ubuntu box.
After installing bison and libedit-dev and fiddling around with LD_LIBRARY_PATH i got it to build


What i don't understand is why i had to do"export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/x86_64-linux-gnu/" considering on "/etc/ld.so.conf.d/"   when there was already a conf file with that path. Permissions issue perhaps? Can someone with more Ubuntu experience shed some light?
Now to the fun part of fidding with Asmjit and LLVM.

quarta-feira, 10 de fevereiro de 2016

Quartz Scheduler

A while back i had to work with Quartz (the scheduler) - Quartz - not to be confused with - Quartz (graphics_layer)  and i would like to share a website that helped me CronMaker.
Thanks to who had the work of making my life easier :)

terça-feira, 22 de dezembro de 2015

Struts 2 and TLD issues.


According to TLD or attribute directive in tag file, attribute value does not accept any expressions

I have been rather plagued by this error on the last few days when using Struts2 till. By chance i came across https://almeidamike.wordpress.com/2010/03/12/struts-solving-according-to-tld-or-attribute-directive-in-tag-file-attribute-value-does-not-accept-any-expressions/ .
So if you are having some difficulties accessing parameters of the request or other values be sure to enable debug as specified in https://struts.apache.org/docs/debugging-struts.html and find the correct path to your value.
Credits to the owner of https://almeidamike.wordpress.com/author/almeidamike/.

Examples:
${someField} becomes %{#attr.someField}. Acessing request parameters would be for instance  %{#parameters.someField}.

quarta-feira, 28 de outubro de 2015

New job new life new projects.

It seems i have left this place a bit scarse on news for a while now. Starting a new job and getting used to new routines made me neglect this place a bit.
That does not mean i have not been busy :) :

  • Working on Spring + JPA + AOP and learning how to deal with some strange errors (if you follow this blog and wish some tutorials and/or to get around common errors please let me know)
  • A project i have started in between jobs, leveraging odoo to implement tracking of e-procurement contracts (adapted to the Portuguese reality as that is the one i am more familiarized with) . Connecting those with Odoo projects allows for some really nice features ( https://www.odoo.com/page/project-management. ). 
  • Working with my good friends at https://www.linkedin.com/company/good-omens-webstudio (if you do work in Morocco do check them out, they are great at what they do).
  • Uploading "Templo dos Jogos" to the Youtube (https://www.youtube.com/channel/UC3QNejga3cw69-NvmFvjyWA/videos )

On a side topic, are there any UK citizens following this blog? I have received some jobs offers from the U.K and i do have a passion for that country, more than for my own country Portugal sometimes (and god knows how it is decreasing), so moving to the  U.K would be a long time project with hopefully citizenship involved. How is it like to be an UK citizen?