Scala: pass-by-value vs pass-by-name

pass-by-value: expressions as arguments to a function are evaluated once on passing to the function

pass-by-name: expressions are evaluated only when referenced, if they are not referenced they are not evaluated, and the expression is evaluated every time the expression is referenced

System.out.println("Calling squareCallByValue(): ")
squareCallByValue( doSomething() )

System.out.println("nCalling squareCallByName(): ")
squareCallByName( doSomething() )

System.out.println("nCalling callByNameNoReference(): ")
callByNameNoReference( doSomething() )
def doSomething() : Int = {
    System.out.println("doSomething() called")

    2
  }

  def squareCallByName(x: => Int) = {
    var result = x * x
    System.out.println("x in squareCallByName: " + result)
  }

  def callByNameNoReference(x: => Int) = {
  }

  def squareCallByValue(x: Int) = {
    var result = x * x
    System.out.println("x in squareCallByValue: " + result)
  }

Creating a Java SE Embedded 8 JRE using jrecreate.sh

Java SE 8 is the first Java release to incorporate JRE ‘profiles’, customized subsets of JRE libraries according to the needs of your app.

From the SE Embedded you need to create the JRE based on a selected profile and then copy it across to your device:

./bin/jrecreate.sh --help

to get a list of the options (more notes here).

To run the above on a Mac, you’ll need to set your JAVA_HOME first, assuming you already have an SE JDK installed. The Java install on Macs is different from other platforms, to handle having multiple versions installed. I have notes in a previous post on how to do this here.

Create a compact1 profile jre with:

./bin/jrecreate.sh --dest jre8 -p compact1

Zip the created dir with

zip -r jre8.zip jre8/*

Scp it over to your target device, unzip and you’re ready to go!

JSTL notes

A few notes for a few common JSTL things so I don’t forget:

taglibs:

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>

Conditionals:

<c:choose>
  <c:when test=””>
  </c:when>
  <!--other when conditions -->
  <c:otherwise>
  </c:otherwise>
</c:choose>

String replace using replace function:

${fn:replace(foo, '"', '\"')}

This next tip for using a loop varStatus to build HTML ids is from: http://stackoverflow.com/questions/6600738/use-jstl-foreach-loops-varstatus-as-an-id

<c:forEach items="${loopableObject}" var="theObject" varStatus="theCount">
  <div id="divIDNo${theCount}">
  </div>
</c:forEach>

This unexpectedly gives:

<div id="divIDNojavax.servlet.jsp.jstl.core.LoopTagSupport$1Status@5570e2">

To get the actual varStatus id you need to use:

${theCount.index} gives value from 0
${theCount.count} gives value from 1

For example:

<div id="divIDNo${theCount.index}">

 

Raspberry Pi Raspbian wifi dongle network config

There’s probably many ways you could configure a similar setup to this, but here’s what worked for me.

This is for static IP on wired, and a different static IP on wireless, where the wireless is using WPA2. I also have two different routers one for wired and for one wireless. Replace static_ip_here with your required ip addresses, and x and y with the IP addresses for your routers.

Edit /etc/network/interfaces:

auto lo
iface lo inet loopback
iface eth0 inet static
address 192.168.1.static_ip_here
netmask 255.255.255.0
gateway 192.168.1.x

allow-hotplug wlan0
iface wlan0 inet static
address 192.168.0.static_ip_here
netmask 255.255.255.0
gateway 192.168.0.y
wpa-ssid "your_ssid"
wpa-psk "your passphrase"
wpa-pairwise CCMP
wpa-group CCMP