2018-09-20

Updated Scala Stack With Angular

News

Updated Scala Stack with Angular and made it cleaner. It uses a servlet with a Scala JS compiler to compile ScalaJS code on the fly!

About

Scala Stack is using Google App Engine, Maven and AngularJS, but only with Scala code! Both backend and frontend is written in Scala. HTML and CSS is generated from Scala code.
Note that no pre-processors or SBT are used. Backend compiles at publish and Javascripts at startup.
You can read more at my earlier blog post:

Repository

Check it out:

2018-03-12

Bind from parent component to child (AngularJS)

Bind from Parent Component to Child

Simple example of how to one-way bind from parent component to child. The child component will be able to use the parent's data.


2018-01-02

Compiling JavaScript on Serverside With Scala and ScalaJS using Google Standard App Engine

Compiling JavaScript on Serverside With Scala and ScalaJS using Google Standard App Engine 

Since my experience with the JavaScript world and exploration of ScalaJS I felt compelled to move from Node and Grunt and try to fully utilize Scala for both front and back.
I reached a goal with Scala Stack, a concept of creating all web content on serverside using only Scala code. The concept is extended to keep everything in code including configuration to be fully testable.

Obvious Advantages

My main purpose was to skip the JavaScript world but it moved on to something much larger. If all code is shared there are quite a few advantages
  • Single, isomorphic source which ease work and can share logic
  • Share data by keeping it in code. For instance languages could be defined with a Enum type
  • Fully testable code
  • No JavaScript package manager like NPM or WebPack
  • No pre processor like Gulp or Grunt
  • No SBT since the compilation is with a simple Servlet  

Risks

There are some traps though 
  • Security, some code should not be shared between backend and frontend
  • Long term effects, demands an experienced architect 
  • Shared code needs to be ScalaJS compatible and cannot use backend dependencies since it's compiled and used on frontend

Scala Stack

Map of Scala Stack

I've made three implementations using Google Standard Environment with Java 8. Implemented in native JavaScript, jQuery and AngularJS.
Goal is to keep everything in code and to avoid configuration, annotations and settings in Strings.
By only using Scala on serverside, it produce HTML, CSS and JavaScript which is all components for a webpage. 

Scala Stack with Angular

You find links to code and running example below

Servlet Compiler

Scala Stack is using a Servlet compiler with different logging:

2017-12-12

Simple AngularJS Binding With Nested Components

Simple AngularJS Binding With Nested Components

This is a simple example of binding between two nested components.


2017-12-10

Servlet Using Google Vision API Sample

Servlet Using Google Vision API

A simple servlet with POST getting an image URL and performs a SAFE SEARCH check using Google Vision API.
Note that it doesn't contain authorization. You can do it locally on your machine or run it live at App Engine using it's service account (it does that automatic so you just deploy it).

2017-11-24

Authorize Jenkins to Google App Engine

Authorize Jenkins to Google App Engine

I usually want everything in the cloud including my Jenkins server. I've been using Bitnami for this but each time I've the same problem of authorize since in the middle of the build Google asks Jenkins to follow a URL and authorize and then paste a key.

Bitnami

Bitnami is an excellent cloud service where you can run services in the cloud. I choose an installation in Europe using Google Compute API and with a Jenkins Image.
When creating your Virtual machine with Jenkins you start an installation wizard where you can select the most common plugins like Maven.

Preparation

It's necessary to know where Maven is installed. This is a simple way to do it without using a console.
  1. Make sure you have installed "Maven Integration Plugin" 
  2. Create a Freestyle project and add a "Execute shell" buildstep with the following command:
    find / -name "mvn"
  3. Check the console for Maven installation folder

Maven Google App Engine Project

Let's create the Maven Google App Engine Project and authorize!
  1. Create a "Freestyle project"
  2. Enter project details like Source code and build triggers. At "Build step" add "Execute bash" as "Build step". Run maven with:
    /opt/bitnami/apps/jenkins/jenkins_home/tools/hudson.tasks.Maven_MavenInstallation/Maven/bin/mvn appengine:update
  3. This will fail since the App Engine plugin will stop for a authorization. It prints an URL which Jenkins cannot open. Follow the link in your browser and sign in using your Google account. Copy the key you receive.
  4. Update your project and change the command to:
    echo "key-you-got-from-your-browser" | /opt/bitnami/apps/jenkins/jenkins_home/tools/hudson.tasks.Maven_MavenInstallation/Maven/bin/mvn appengine:update
  5. Run the project and you should be authorized!
What happens is that your key is entered when Maven stops for input.

2017-06-08

Compiling JavaScript on Serverside With Scala and ScalaJS

Compiling JavaScript on Serverside With Scala and ScalaJS

Since my experience with the JavaScript world and exploration of ScalaJS I felt compelled to move from Node and Grunt and try to fully utilize Scala for both front and back.
I reached a goal with Scala Stack, a concept of creating all web content on serverside using only Scala code. The concept is extended to keep everything in code including configuration to be fully testable.

Future of Internet

If we try to look into the future of internet, I think we see two strong forces: Market and AI.
How will they alter the internet we use today?
  • Market want to extract most of its users and want to create webpages which are fully personalized in an effort to guide the users to their goals. Sites are personlizing the pages by user settings but why shouldn't all content including color and shape be adopted to the user in a effort to please the user as much as possible? 
  • AI and ML is on the uprising and if the server is thinking for itself it could create whatever as a response.

Obvious Advantages

My main purpose was to skip the JavaScript world but it moved on to something much larger. If all code is shared there are quite a few advantages
  • Single, isomorphic source which ease work and can share logic
  • Share data by keeping it in code. For instance languages could be defined with a Enum type
  • Fully testable code
  • No JavaScript package manager like NPM or WebPack
  • No pre processor like Gulp or Grunt

Risks

There are some traps though 
  • Security, some code should not be shared 
  • Long term effects, demands a experienced architect 
  • Shared code needs to be ScalaJS compatible and cannot use backend dependencies since it's compiled and used on frontend

Scala Stack

I've made three implementations using Google Flexible Environment. Implemented in native JavaScript, jQuery and AngularJS.
Goal is to keep everything in code and to avoid configuration, annotations and settings in Strings.
By only using Scala on serverside, it produce HTML, CSS and JavaScript which is all components for a webpage. 
Map of Scala Stack

Servlet Compiler

Scala Stack is using a Servlet compiler with different logging:
I discovered C and JavaScript in school 98-99 and have coded since.
As an individual the first problem is to be creative within the little time that is left of work and social life. Keeping goals through discipline and understand how to be efficient was fundamental. 2012 I discovered Google App Engine and within a single JSP-file kept HTML, CSS, JavaScript and Java with a database connection, I was hooked! This was all I needed to create a site. The PaaS handled publication, dashboard, configuration of services, hosting, logging and have a big library of API for the basic operation, which meant I could spend time on coding.
Mixing code with a subject are my main interests and when creating my first sites I understood that it's impossible to create content driven sites by myself. The solution was to give the users tools to modify the site as they witched and, as a community, create the site they wanted in a democratic way.