How can you backup your SD cards for your Raspberry Pi?

Given that SD cards have a limited lifetime for writes, using an SD card for a harddrive for Pi may not be the smartest idea in terms of reliability or longevity, so asking how you back up your SD card is a good question. There’s some good answers here.

Specifically on the Mac, find out the disk number of the attached sd card with :

diskutil list

then use the dd command:

dd if=/dev/rdiskx of=/path/to/image bs=1m

where x is the disk number listed from diskutil.

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}">