Jun 20, 2013

Use multiline strings with Go

 For decelerate the string that contain line breaks, you close back quart.
 If you use the double quart, it arise error.
// string of multiline
var str string
str = `Welcome!
Multi lines message!
Good job!`

You can put the back quart by Shift + @ if you use Mac.

Jun 19, 2013

Go can't looks static files on GAE

 My work was disrupted by the problem that can't read files in static_dir from Go scripts.

 Be careful to below points.
  • Set "static" to files that are readed by web browsers from a user.
  • Must not set "static" to files that are read by go scripts.
 Files in static_dir can not  read  by go scripts. these read by web browsers.

by Google App Engine documents
For efficiency, App Engine stores and serves static files separately from application files. Static files are not available in the application's file system. If you have data files that need to be read by the application code, the data files must be application files, and must not be matched by a static file pattern.

 Therefore, must not put html files to static_dir if you will output a html file dynamically by use of template package.

Jun 18, 2013

Color Go source codes in Xcode 4.x

By default, Xcode does not syntax hightlight.
But, we can configure in the following way.

  1. Download the shell script
  2. Config the path
  3. Execute the shell script
  4. Check

1. Download the shell script

The script that empower Xcode syntax highlighting is distributed.

Download go4xcode.sh  from here.

There is no need to download go.sclangspec, because it is contained in SDK of Google App Engine.
By default, it is here.

2. Config the path

The script uses the environment variable $GOROOT.
Check whether it is configured correct path.
$ su
$ echo $GOROOT
If displayed path to goroot, there is no problem.
If else, set the path to goroot.
$ export GOROOT=/Applications/google_appengine/goroot/

3. Execute the shell script

Let's execute the shell script.
$ sh go4xcode.sh
Backing up plugindata file.
Adding Go language specification entry.
Duplicate Entry Was Skipped: Xcode.SourceCodeLanguage.Go
Installing Go language specification file for Xcode.
Run 'sudo rm -rf /var/folders/*' and restart Xcode to update change immediately.
Syntax coloring must be manually selected from the Editor - Syntax Coloring menu in Xcode. 

Remove trashes according to message.
$ rm -rf /var/folders/*

it's complete.

4. Check

Launch the Xcode.
If installing is succeed, there is a new menu Editor -> Syntax Coloring -> Go.

When click this, Xcode syntax highlighting source code.
But this is not configure automatic.

Apr 21, 2013

Apply the MIT License to software

This is a method to publish software that applied the MIT License.
In order to declare the software license,

  • Describe license in the file header comment
  • Include license text as text file
  • Display license text on the installer

And so on.

An easy way is to include text file.
Template of the MIT license is open to the public at the following websites.

Open Source Initiative

Japanese translation by Open Source Group Japan

Copy the template and put your name in , and put also development year in
Save the file as "LICENSE.txt" and distribute software, and this method is complete.

Apr 20, 2013

Loop playback BGM with enchant.js

This is how to loop playback the BGM with enchant.js.

// Loop playback the bgm
game.assets['bgm.mp3'].src.loop = true;

Be careful because loop parameter must set after play.

// This case not loop playback the bgm
game.assets['bgm.mp3'].src.loop = true;

Apr 19, 2013

Trim images with Preview of Mountain Lion

This method is convenient to removing blank spaces from images.

Open the image with Preview.

Click the pencil icon to show tools.

Click the magical stick icon (instant alpha). If the icon is invisibility, widen window.

Drag area that you want remove, and make selected.

Press the Delete key and remove the area.

You can invert the selected area by command + shift + I.

Select the blank space with magical stick.

Press command + shift + I and invert the area.
You can remove the area that not selected by command + K.

Mar 13, 2013

Line-height is ignored on Canvas

    You can't set line-height on HTML5 Canvas. You can set the font of canvas in the same manner as CSS, but number of line-height is ignored.

    I bump into a this problem.

// output statements are skipped.
var message = 'Where is a pig! I am very hungry... Give me a pig!';
var label = new Label();
label.color = 'black';
label.text = message;

// both font-size and line-height are 75px, but those are ignored.
label.font = '75px/75px fantasy';


On Canvas API Specification, line-height number is automatically set 'normal'.
I done deal in such a way as to using array by hand.

var messages = [
    'Where is a pig!',
    'I am very hungry...',
    'Give me a pig!'
for(var i = 0; i < messages.length; i++) {
    var label = new Label();
    label.color = 'black';
    label.text = message;
    label.font = '75px fantasy';
    label.y = 75 * i;  // 手動で高さを調整

- W3C HTML Canvas 2D Context, Level 2 Nightly