Pesquisar neste blogue

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.