Project Jigsaw for Java has been a long time coming – are we really going to see it in Java SE 9 this year?

Java SE 9 general availability date is 7/27/17, per the release schedule here. Project Jigsaw been a long time coming and been postposed from release to release (it was originally planned for SE7, pushed to SE8, and now SE9), but this year we’ll see Project Jigsaw come with SE 9.

It’s funny what you find unexpectedly when searching for stuff online – reading around for Jigsaw related articles I found this Jigsaw mailing list post by Mark Reinhold back in 2012 including a link to one of my blog posts, discussing the Jigsaw ‘plan A’ vs ‘plan B’ options back when Jigsaw was pushed out from SE 8 to 9. Hopefully we really will see Jigsaw in SE9 later this year.

BASIC 10liner 2017 contest entry – Boulder Jumper

I’ve seen posts about the BASIC 10Liner contest before, but this time I spotted posts for the 2017 contest with time to put an entry together. This weekend I spent a few hours putting together an entry using Sinclair BASIC on an emulated Spectrum, using Fuse for MacOS.

My entry is a take on the infinite runner style games, like Temple Run, but re-imagined in glorious 8 bit Sinclair BASIC style, I’ve called it ‘Boulder Jumper’.

If that’s not enough I went completely retro and implemented the graphics using only characters. This is my first entry to the BASIC 10Liner contest, and the first time I’ve written any Sinclair BASIC for maybe 33 or maybe more years.

My first thoughts were how can you possibly write a fully functioning game in 10 lines of code, but you can have multiple statements per line, and enter in either the 80 chars, 120, or 256 characters per line category. I think I’m just about squeezing into 120 per line.

Here’s a screenshot of the awesome gameplay:

Your character is a ‘b’ character, and rocks come from the right moving to the left, as ‘o’ characters. You press ‘m’ to jump and jump over the rocks or get squashed. You get points per rock you jump over, and have 3 lives.

Here’s the code in all it’s Sinclar BASIC glory:

10 CLEAR : PRINT AT 10,2;"Boulder Jumper, by @kevinhooke": PRINT AT 12,10;"b = you": PRINT AT 14,10;"O = rock"
20 PRINT AT 16,10;"M = to jump": INPUT "Press a key when ready!", a$
30 CLEAR : LET lives=3: LET score=0: LET jump=0: PRINT AT 2,10;"b"
40 FOR i = 30 TO 1 STEP -1: PRINT AT 2,i;"O": PRINT AT 2,i+1;" ": LET a$=INKEY$: IF i=1 THEN PRINT AT 2,1;" "
50 PRINT AT 0,0;"Lives: ": PRINT AT 0,6;lives: PRINT AT 0,15;"Score: ": PRINT AT 0,22;score: IF jump = 0 THEN PRINT AT 2,10;"b"
60 IF jump=0 AND i=10 THEN PRINT AT 1,10;"ouch!": LET lives=lives-1: BEEP 1,-2: PRINT AT 1,10;" ": PRINT AT 2,10;"b"
70 IF lives=0 THEN PRINT AT 1,15;"Game Over!": BEEP 2,-4: INPUT "PRESS A KEY";a$: GO TO 10
80 IF jump>0 THEN LET jump=jump - 1: IF jump=0 THEN PRINT AT 2,10;"b": PRINT AT 1,10;" "
90 IF a$="m" THEN PRINT AT 1,10;"b": PRINT AT 2,10;" ": LET jump=7: LET score=score+10: BEEP 0.1,4
100 NEXT i: GO TO 40

And here’s the 10 lines in the Fuse emulator:

It’s not great and you could do a lot better (this is probably better suited to a ZX-81 than the ZX Spectrum), but it’s my first attempt for the 10Lines contest, and I had run writing and playing it!

Adding React Router to a React App

react-router is a routing library for React, that allows you to declare which components render based on url paths. It’s similar to ng-route and ui-router in AngularJS.

To get started, install react-router npm module:

npm install react-router --save

Full docs are here.

While working on converting an existing web app to React, I ran into a few issues getting my react-router usage working as I wanted.

Here’s my first attempt adding the Router declarations into an existing Container component that renders NavigationComponent – this Component renders a set of navigation links that are common across each of the pages:

<div>
    <NavigationComponent/>
    <Router history={hashHistory}>
        <Route path="/" component={Home}/>
        <IndexRoute component={Home} />
        <Route path="new" component={AddNew} />
        <Route path="search" component={Search} />
    </Router>
</div>

The first error I ran into was this:

Uncaught Error: <Link>s rendered outside of a router context cannot navigate.

Ok, this makes sense, so I need to move the NavigationComponent that renders my Links within <Router> :

<Router history={hashHistory}>
    <Route path="/" component={NavigationComponent}/>
    <IndexRoute component={Home} />
    <Route path="new" component={AddNew} />
    <Route path="search" component={Search} />
</Router>

Routes at the same level replace each other when rendered. To keep the navigation component rendered with the AddNew and Search as child sections of the nav area, nest the Routes as child elements:

<Router history={hashHistory}>
    <Route path="/" component={NavigationComponent}>
        <IndexRoute component={Home} />
        <Route path="new" component={AddNew} />
        <Route path="search" component={Search} />
    </Route>
</Router>

Now, for the NavigationComponent to render it’s child elements, you need to tell it to render:

{this.props.children}

So now this becomes:

render() {
    return (
        <div>
            <div>
                <nav className="navbar navbar-default" role="navigation">
                    <div className="navbar-header">
                        <Link className="navbar-brand" to="/">AddressBook</Link>
                    </div>

                    <div className="collapse navbar-collapse navbar-ex1-collapse">
                        <ul className="nav navbar-nav">
                            <li className="active"><Link to="search">Search</Link></li>
                            <li><Link to="new">New</Link></li>
                        </ul>
                    </div>
                </nav>
            </div>

            <div>
                {this.props.children}
            </div>
        </div>
    )
}

Here’s a good reference for getting started: https://medium.com/reactspeed/create-basic-navigation-components-using-react-router-475bc55a517f#.itkvn5st9

 

 

Installed probably the last custom ROM update on my Galaxy S3 this year

I’ve been running custom CyanogenMod builds on my now aging Galaxy S3 for a while now (12.1, 13). Given that support for CyanogenMod ended at the end of last year, I thought it would be worth one last new ROM before I upgrade my phone this year, and installed the new LineageOS.

Using the already installed TWRP recovery that I already have installed, I downloaded the latest nightly LineageOS build from here, the latest Google Apps for Android 7.1 from here, booted into Recovery, deleted cache files etc, installed both new ROMs and now I’m up and running.

Even on my aging Galaxy S3, I have to say, this Android 7.1 build is surprisingly snappy, even faster than the last CyanogenMod build that I had that was pretty good.