2016-10-23

Rains Poncho (gul) 890kr

Jackor & Ytterplagg, stl. 50 (M), herr 
Supersnygg poncho i gult av Rains. Säljes i befintligt skick för 890kr. 

Stripe byrå (Sara Larsson) 9 990kr

Supersnygga designbyrån Stripe finns i nyskick! Säljes i befintligt skick för 9 990kr. Nypris cirka 13 000kr.

Från den exklusiva möbelkedjan Svensson i Lammhult: Stripe är en vacker, uppseendeväckande byrå som bär tydliga kännetecken av formgivare Sara Larssons kärlek till det färgstarka. Som vanligt när det gäller A2 Designers är det hantverksmässig tillverkning och hög kvalitet som är ledorden.

Kartell Optic (kub, förvaring) 1000kr



Som nya! Tre i färgerna lila och röd. Dörrar ingår (360kr) men med trasiga fästen.

Säljes i befintligt skick. 500kr/st

Från Kartell: Denna mångsidiga kub är ett spännande inredningsobjekt. Optic är en förvaring i form av en kvadratisk box med antingen en öppen sida eller med dörr. Tack vare att man kan stapla dem på varandra uppstår möjligheten att skapa en vacker hylla, pelare eller ett enstaka litet bord. Ytan är utformad med kvadratiska låga pyramider, vilket skapar en mycket vacker visuell effekt och en "relief" i ytan. Går även att ha utomhus.

Mått: 41 x 41 x 41 cm

2016-10-13

Scala Request Uri Combinator Parser

URI Combinator Parser

In my last blog I created a URL parser but the HttpServletRequest is providing only path and query with the method getRequestUri() so I made a request URI parser too.

Code

This code needs the URL parser, see below.

See

Link to the URL parser:
https://gist.github.com/AIMMOTH/b9903387cdf6b9377e9a7f6ca8887281

2016-10-12

Scala URL Parser Combinator

URL Parser Combinator

(updated 2016-10-16)
It has bugged me that there is no parser of an URL so I made one.

Parser Combinator

Scala provides an excellent tool of parsing using a mix of code in DSL (domain specific language) and regular expressions. Together with unapply it's easy to match and take out the matching pieces.

URL

From Wikipedia there are the following parts of an URL (some are optional):
scheme:[//[user:password@]host[:port]][/]path[?query][#fragment]

Code

Enjoy, I won't go into detail other than it breaks down the URL in the following order:
  1. Split URL by
    1. Mandatory scheme
    2. Optional domain
    3. Mandatory path
    4. Optional query and fragment
  2. Domain is split by
    1. Authorization
    2. Domain
    3. Port
Usually a greedy regexp matcher is used until a delimiter.

2016-10-11

Javascript monad Maybe with Monet



The Monad Maybe

Maybe aka option or optional is very useful for preventing null. Using the Javascript library Monet it's quite easy to use this monad.

Preventing null

You have a variable but don't know if it's null. With Maybe, you wrap it and test if it is "some".

Transform or map

Monads are also useful to transform a value to another. Think of this example:
Each step is instancing a variable and making a "halt". With a monad, you can "go with the flow" and do it all in one step:

Sample

https://jsfiddle.net/yapdd5xv/15/

2016-10-07

Monad implementation in Scala with example

Monad in Scala

Monad

Difficult to explain but useful for nice code.

Implementation in Scala

This is a simple implementation of a monad in Scala which makes Any able to use monad's definition called flatmap (>>=).
/**
 * Monad implementation
 */
final case class Monad[T](val value : T) {

  def >>=[S](f : T => S) : Monad[S] = {
    new Monad(f(value))
  }

  override def toString = String.valueOf(value)
}

/**
 * Implicit wrap Any to a Monad.
 */
implicit def anyToMonad[T](value : T): Monad[T] = new Monad[T](value)

Example

Using this implementation, Any can use flatmap wihch could be used as follows.
// Example
"10" >>= Integer.parseInt >>= (_ + 10) >>= (0 to _) >>= println
Prints
Range(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20)

Fiddle

Try it out at Scala Fiddle!

2016-09-01

Scala Stack with Google Flexible Environment

Scala Stack with Google Flexible Environment

(this article is not yet completed)
(updated 2016-11-11)

I've created a few Maven projects based on Google Flexible Environment and Scala backend which produces HTML, CSS and JavaScript without any files (.html, .css, .sass, .less, .js) and without any frontend builder like Gulp or Grunt.

Goal

To produce all frontend from Scala backend utilizing shared code and to be fully tested.

Infographic

Scala servlets creates HTML with CSS and JavaScript.
This is a graphic representation of how it works.
  • All code is written in Scala
  • Code may share
    • Resources
    • Validation
    • Routes
    • Logic
    • Translations and other data
    • Structure of
      • HTML
      • CSS
  • A servlet can read Scala JS source code and compile a JavaScript
    • This includes the shared code
  • A servlet can build HTML with CSS 
  • Other servlets can provide REST API and also use the shared code
  • All code can be unit tested and all code can be tested in the same test
This means that the Scala stack covers both frontend and backend.

Code

There is a repository called Scala Stack at Github. There is one branch for jQuery in development and one branch for Angular which is only started:
*Unfortunately I can't afford Google Compute Engine running 24/7 and was forced to shut them down. If Google Compute Engine would scale from 0 to minimize expense I could start them again.

Examples

I'm currently working on a example using jQuery (in progress) and one using Angular (started).
Note that Scala JS source is placed in webapp, an alternative could be resources



2016-07-20

Migration from Google App Engine to Flexible Environment

Migration

Google App Engine is great since it's reliable and have tons of services free to use. Compared to a platform like Heruko, you get search, database, image and other services for free. But as a javaite, it's unfortunate that it only supports Java 7. The only way to move forward is to migrate to Flexible Environment. But be aware, not all services can migrate!

Start: App Engine

Let's start with a simple App Engine Maven project and then migrate it.

Prerequisites

Use the following guide to install Java 7 SDK and Maven.

Create Artifact

Use Maven to create the simple appengine skeleton artifact.
  1. Run
    $ mvn archetype:generate -Dappengine-version=1.9.38 -Dapplication-id=whatever -Dfilter=com.google.appengine.archetypes:
  2. Select "1"
    1: remote -> com.google.appengine.archetypes:appengine-skeleton-archetype (A skeleton application with Google App Engine)
  3. Select "6"
    6: 2.1.0-1.9.38
  4. Enter group id (same as your Java package name for the project)
    Define value for property 'groupId':
  5. Enter your name for your project
    Define value for property 'artifactId': :
  6. Enter first version
    Define value for property 'version':  1.0-SNAPSHOT:
  7. Enter Java package (same as group id)
    Define value for property 'package':
  8. Enter gcloud version (find latest here)
    Define value for property 'gcloud-version': 2.0.9.111.v20160527
  9. Confirm your selection
     Y:
Maven have now created an App Engine project in a subfolder. Start it with $ mvn appengine:devserver
Notice the layout and the few files needed.
Simple layout with few files

Migration: Flexible Environment

Let's go for Flexible Environment and Java 8!

Prerequisites

  • Install Java 8 SDK and never look back!
    Note: that App Engine uses Jetty which need Java 7 to work with JSP. If you install Java 8 it will be difficult for you to run your old App Engine projects.
  • Install Google Cloud SDK. Make sure Python is on path after installation!
    https://cloud.google.com/sdk/
  • Install the app-engine component to GCloud
    gcloud components install app-engine-java
    https://cloud.google.com/appengine/docs/flexible/java/maven

Migration

Follow the steps in the following guide.
  1. Add the following line in appengine-web.xml
    <vm>true</vm>
  2. Add the following two plugins in pom.xml.
    1. The first one to be able to run with GCloud maven goals
    2. And the second to set Java 8 compilation.
  3. <plugin>
       <groupId>com.google.appengine</groupId>
       <artifactId>gcloud-maven-plugin</artifactId>
       <version>2.0.9.106.v20160420</version>
    </plugin>
  4.       <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <version>3.3</version>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
              <source>1.8</source>
              <target>1.8</target>
            </configuration>
          </plugin>
  5. Run with
  6. $ mvn gcloud:run

2016-07-12

Google Flexible Environment with Virtual Scala JS Compiler

Google Flexible Environment with Virtual Scala JS Compiler

After several months I managed to translate Scala JS Fiddle to Google Java Flexible Environment 

Goal

To create a project with Scala backend which generates JavaScript in a virtual compiler.

Live Demo

The live demo uses a Scala Servlet to generate HTML (Scala Tags) with a JavaScript. A second Scala Servlet is responding to "/javascript.js" and is using a virtual compiler to compile a String with simple Scala JS code to a JavaScript

Environment

It's a Maven project using Google Flexible "Compat" Environment which includes some App Engine features (not used) and Java 8 with Servlet API 3.1.

Source

Check out my Github

2016-07-02

My AirBnB

Mariabergets topp

Stockholm, Stockholms län, Sverige
Mitt ställe ligger nära Monteliusvägen, Ivar Los park, The Bishops Arms, Akkurat restaurang & bar, Rival, Mariatorget, Mariaberget, Tavastgatan, Brännkyrkogatan, Slussen, Bysistorget, Münchenbrygge...

2016-06-29

H1Z1 King of the Kill: Art of Camping

Art of Camping

Check my new tactic for the current (new) map

This is the tactic I usually use. It started with me trying to get to top 10 in the most safe way and now I regularly accomplish that. But to win you always need to win duels.
It has three phases:
  1. Parachute Dive down to a safe area and loot
  2. Movement Approach the circles close to the edge to avoid players
  3. Final Win duels to win the game!

Parachute

Go as far out to the edge as possible. You can fly further by strafing, using A and D. It's possible to cover two squares.
There are plenty of safe places but if you start in the middle it can be difficult reaching them

These areas usually empty from players and have plenty of loot. Notice that from F-G 5-6 it's quite difficult to parachute into a safe area!

Movement

Timing

Each circle appear in intervals and the gas move in between. The first circle appears after 5 minutes, then there's a delay of 5 minutes and then shrinks for 5 minutes. After coming circles shrinks during 1 minute.
The first circle have 5 squares in radius and the next four shrinks it's radius with 1 square. Then they are halved.
They are named after their square radius.
  1. The first circle is called "the five" since it's radius is 5 squares.
  2. The next three circles shrinks after 3min
    1. The four
    2. The three
    3. The two
  3. The next circles shrinks after 2min
    1. The one covering one square and shrinks relatively fast!
    2. The half
    3. The quarter
    4. The eighth
    5. ...

Speed

It's really useful to know how fast you travel to measure how long it will take you to reach the circle
  • Barefoot ~2:05/square
  • Shoes ~2:00/square
  • Sneakers ~1:50/square
  • Car
    • Full throtle ~30s/square
    • No throtle ~40s/square
Since the first circle shrinks after 5min and during 5min then you have 10min to run into it, and with shoes you can cover 5 squares during this time.

Healing and Gas Damage

If you're late and need to run through gas, make sure to have health packs. Each pack heals 1hp/s during 1min (60hp in total) and bandages heals 1hp/s during 10s (10 in total).
Gas make 1hp/s damage. This means you can use a health pack and run through the gas for 1min which covers a half square!
During the final the gas becomes stronger and reaches 2-3hp/s.

Approach

When heading towards a circle, try to avoid areas with lots of players and try to move around them and into an area which is in the outskirts.
Outside the roads are safe. Cities and fields are hazardous

Example

Run around the hazardous areas and only if necessary, try to run between those areas and move towards the edge of the map.
Move around the center and continue to the edge

Videos

You can watch some videos I've recorded here Art of Camping Playlist

Final

At the one and onward, there's usually around 10 players left and this is called the final. The gas damage is about 2-3 per second. You need to win duels at this point!
"The one" appear and it could be a good idea to take a chance and camp on the island!


2016-06-21

Logging with Flexible Environment and Jetty

Logging with Flexible Environment and Jetty

Problem

Logging was not available for Google Flexible Environment with Java 8 and Jetty 9. But after reading Jetty documentation all needed was added SLF4J as dependency and use it's Logger.

Solution

Add SL4FJ as dependencies in pom:

    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-api</artifactId>
      <version>1.7.21</version>
    </dependency>
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-simple</artifactId>
      <version>1.7.21</version>
    </dependency>

Use org.slf4j.LoggerFactory and org.slf4j.Logger to log:

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private static Logger logger = LoggerFactory.getLogger(JavaServlet.class);
logger.info("Info logging!");

Deployed

When deployed, the logging is shown in STDERR

2016-06-01

Flexible Environment with Scala

Flexible Environment with Scala

Started a new Maven project with Google's Flexible Environment including Java 8, Scala and Web Servlets 3.1.

Source code

You can find it here:
https://github.com/AIMMOTH/scala-js-compiler/tree/java8-scala-flexible-environment-web-servlet-3.1

2016-05-30

Uppdated! "Cannot determine the default location of the Google Cloud SDK" Solved

Error

Got a really annoying error while trying to run my local Flexible Environment with GCloud 
$ mvn -Dgcloud.gcloud_directory="c:\path\to\gcloud-sdk\" gcloud:run
[ERROR] Cannot determine the default location of the Google Cloud SDK.
[ERROR] If you need to install the Google Cloud SDK, follow the instructions located at https://cloud.google.com/appengine/docs/java/managed-vms
[ERROR] You can then set it via <gcloud_directory> </gcloud_directory> in the pom.xml
[ERROR]
org.apache.maven.plugin.MojoExecutionException: Unkown Google Cloud SDK location:C:\...\gcloud_sdk
        at com.google.appengine.gcloudapp.AbstractGcloudMojo.setupInitialCommands(AbstractGcloudMojo.java:170)
        at com.google.appengine.gcloudapp.GCloudAppRun.getCommand(GCloudAppRun.java:306)
        at com.google.appengine.gcloudapp.GCloudAppRun.execute(GCloudAppRun.java:292)
        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
        at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.441 s
[INFO] Finished at: 2016-05-30T20:21:34+02:00
[INFO] Final Memory: 24M/380M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.google.appengine:gcloud-maven-plugin:2.0.9.74.v20150814:run (default-cli) on project scala-js-compiler: Execution error: org.apache.maven.plugin.MojoExecutionException: Unkown Google Cloud SDK location:C:...\gcloud_sdk -> [Help 1]

Solution

It was much easier to solve! Just add Python to path (which is bundled in the Gcloud SDK).
But managed to use the locally installed python to run the python script which starts development server:
$ cd project
$ c:\...\gcloud_sdk\google-cloud-sdk\platform\bundledpython\python.exe c:\...\gcloud_sdk\google-cloud-sdk\bin\dev_appserver.py src\main\webapp

2016-05-28

Majorca Picture with the Golden Spiral

In April me and my mom visited Majorca. There was an interesting formation. I shoot it and found out that the picture had a criss-cross composition. I made a crop with the Golden Spiral and this is the result.

Reference

2016-04-02

Webapp with HTML, CSS and JavaScript written in Scala

ISO Scala

This is an example of HTML, CSS and JavaScript written in Scala.

Technics

Different parts are written in different ways
  • Backend, Scala implementation of a Java Servlet
  • HTML and CSS, using ScalaTags to generate HTML in a String
  • JavaScript, built with ScalaJS

Two Builds

There are two different builds
  1. Backend, using plain Maven to build and setup the project
  2. JavaScript, built with SBT and using ScalaJS dependencies

Example

View a whole example at