Year: 2018

.NET Core And Angular at CodeCamp Bucuresti

I have presented on Saturday at https://bucuresti.codecamp.ro/ a technical talk about how to make a fast POC that can run on Web, Desktop and Mobile , The presentation will show a clear example of code that is necessary for that ( code at https://github.com/ignatandrei/angNetCoreDemo/  ).

You can see working demo without CORS at https://ang-net-core.herokuapp.com/ , with CORS at https://ignatandrei.github.io/AngNetCoreDemo/ and a Mobile app at https://app.bitrise.io/artifact/9332781/p/ef7a0b7e945d69e01697390dcef867de

It was a good opportunity to learn something new at the conference – many good technical tracks and old friends that is an opportunity to see again.

Literary awards–part 5 – interactive

Part 1: http://msprogrammer.serviciipeweb.ro/2018/10/08/literary-awardspart-1/

Part 2: http://msprogrammer.serviciipeweb.ro/2018/10/15/literary-awardspart-2/

Part 3: http://msprogrammer.serviciipeweb.ro/2018/10/22/literary-awardspart-3/

Part 4: http://msprogrammer.serviciipeweb.ro/2018/10/29/literary-awardspart-4/

Part 5: http://msprogrammer.serviciipeweb.ro/2018/11/05/literary-awardspart-5/

 

I was wandering how to make more attractive the application – and also gain some interactivity. I was thinking of the possibility  to can say what authors / books did you have read – and make some charts from it.

And here was the principal problem: how, between 2 versions of the data, to remember the authors read ? How to make the authros the same between the various awards ?

Turns out it is not so complicated – the only thing is to not version the “read” database .

So I turn out with just a database per table : one for Nobel, one for Booker, one for Bill Gates books, one for my books, one for reading list and one for all authors. Not a good thing, but this happens when you want to keep the database into the browser and updatable…

The source code is at github:https://github.com/ignatandrei/LiteraryAwards

Literary awards–part 4 – publish

Part 1: http://msprogrammer.serviciipeweb.ro/2018/10/08/literary-awardspart-1/

Part 2: http://msprogrammer.serviciipeweb.ro/2018/10/15/literary-awardspart-2/

Part 3: http://msprogrammer.serviciipeweb.ro/2018/10/22/literary-awardspart-3/

Part 4: http://msprogrammer.serviciipeweb.ro/2018/10/29/literary-awardspart-4/

Part 5: http://msprogrammer.serviciipeweb.ro/2018/11/05/literary-awardspart-5/

 

The publishing part is the tricky one. I wanted Web and Mobile ( could someone help me with the Windows/Linux part  ? )

Github let’s you have the gh-pages  as an website – see https://help.github.com/articles/configuring-a-publishing-source-for-github-pages/ .

What this means in practice ? Menas that , if you deploy the Angular AOT to the gh-pages ( https://github.com/ignatandrei/LiteraryAwards/tree/gh-pages ) , then it should be visible to this url : https://ignatandrei.github.io/LiteraryAwards/

There is also a plugin, angular-cli-ghpages , that does this for you: takes the dist folder ( resulting from AOT Angular build ) and put in gh-pages. You can see the result at https://ignatandrei.github.io/LiteraryAwards/

For Mobile Android I just install the Cordova, copy the dist folder into Cordova and modify the start page in order to point to the Angular results.

But how can I compile Cordova into an Android application ? Turns out that there is a site – https://www.bitrise.io/ – that takes your code ( not only from GitHub, but for free app it is free  ) and compiles it – and it gives you back the apk. Also , it can sign the application – something that Google Play requires. ( For this, I have had some problems with generating keys:

“C:\Program Files\Java\jdk1.8.0_171\bin\keytool.exe” -genkeypair -alias upload -keyalg RSA -keysize 2048 -validity 9125 -keystore keystore.jks
“C:\Program Files\Java\jdk1.8.0_171\bin\keytool.exe” -export -rfc -alias upload -file upload_certificate.pem -keystore keystore.jks

)

You can find the Google Play application at https://play.google.com/store/apps/details?id=com.msprogrammer.com

 

The source code is at github:https://github.com/ignatandrei/LiteraryAwards

Literary Awards–part 3–data

Part 1: http://msprogrammer.serviciipeweb.ro/2018/10/08/literary-awardspart-1/

Part 2: http://msprogrammer.serviciipeweb.ro/2018/10/15/literary-awardspart-2/

Part 3: http://msprogrammer.serviciipeweb.ro/2018/10/22/literary-awardspart-3/

Part 4: http://msprogrammer.serviciipeweb.ro/2018/10/29/literary-awardspart-4/

Part 5: http://msprogrammer.serviciipeweb.ro/2018/11/05/literary-awardspart-5/

 

The data – this was the difficult part. As I said, I wanted the data to be local – but how can I put the first time ? And where ? I cannot be cookie, since the authors are a large database for cookies…

There are 3 options : LocalStorage, WebSql and IndexedDB . You can read about those at https://nolanlawson.com/2015/09/29/indexeddb-websql-localstorage-what-blocks-the-dom/ . I choose LocalStorage because it was simpler – however, this is making the startup of the application slower!

Now, how can I store the data ?  For me, a database with select it was fine – but can I find one that works in the browser ? And with javascript ? Apparently, yes! There is a port from C to js of SQLite – https://github.com/kripken/sql.js/ . That means , I can have a SQLIte database and access via Select. Add I can persist too – see https://github.com/kripken/sql.js/wiki/Persisting-a-Modified-Database .

 

With all those, now I am ready to have the Nobel authoirs in my application – but how can I introduce to my application ? The list exists on Wikipedia( https://en.wikipedia.org/wiki/List_of_Nobel_laureates_in_Literature)  and at Nobel site (https://www.nobelprize.org/prizes/literature/) . How can I load those into my SQLite LocalStorage database ?

Here comes another pet project of mine, stankins  . With this I can transform the wikipedia page into this:


db.run("INSERT INTO tableAuthors (Year,Laureate,Languages,Citation,Genres,PictureUrl,LaureateFullWiki,name) VALUES (?,?,?,?,?,?,?,?)", [

"1901",

"Sully Prudhomme",

"French",

'"in special recognition of his poetic composition, which gives evidence of lofty idealism, artistic perfection and a rare combination of the qualities of both heart and intellect"[12]',

"poetry, essay",

"//upload.wikimedia.org/wikipedia/commons/thumb/3/39/Sully-Prudhomme.jpg/75px-Sully-Prudhomme.jpg",

"https://en.wikipedia.org/wiki/Sully_Prudhomme",

"Sully_Prudhomme"

]);

db.run("INSERT INTO tableAuthors (Year,Laureate,Languages,Citation,Genres,PictureUrl,LaureateFullWiki,name) VALUES (?,?,?,?,?,?,?,?)", [

"1902",

"Theodor Mommsen",

"German",

'"the greatest living master of the art of historical writing, with special reference to his monumental work, A History of Rome"[13]',

"history, law",

"//upload.wikimedia.org/wikipedia/commons/thumb/e/e9/T-mommsen-2.jpg/75px-T-mommsen-2.jpg",

"https://en.wikipedia.org/wiki/Theodor_Mommsen",

"Theodor_Mommsen"

]);

Obvious, it is not perfect – but it works!

What can I do with upgrades * because , obvious, each year I should add the Nobel authors ? Nothing simpler: I will modify the name of the database with the application version from package.json

 

In environement.ts ( and in prod)


VERSION: require('../../package.json').version

In the typescript class:


public version: string = environment.VERSION;

Finally , in the create database


this.dbPers = new SQL.PersistentDatabase(

"nobel_v"+this.version,

async function(sender) {

// Initial creation of database if not found

self.createDatabase(sender).then(()=>{

sender.save();

});

},

function(e) {

// Initialization of existing database failed

alert("database failed" + e);

}

);

The source code is at github:https://github.com/ignatandrei/LiteraryAwards