Wednesday, January 2, 2013

Fix "was unexpected at this time" and “not recognized as an internal or external command” when run batch script on Windows 7 64bit system

My company use DOS batch script to build project. We still need to maintain some legacy projects. When run the build script from legacy project on 64bit Windows 7 system, I saw error "xxx was unexpected at this time", then the building script exit.

I did some search online and found to change
set x=%path% to set x="%path%" will solve this issue.

But after the modification, i saw new error of "xxx not recognized as an internal or external command", the xxx can be as simple as cmd, ping

After quite some time of Googling, finally I found a solution, change all path contain Program Files (x86) to PROGRA~2 in the PATH environment variable. And that solved my problem.

I wrote it down and hope my experience can help other people facing similar issues.

Monday, December 31, 2012

2013

还有2个多小时就是2013年,自从成家有了小孩以后,时间总是过得飞快,眨眼小孩就会走,会跑,会说话,现在会提出自己的要求。回顾过去的一年,下班回家的时间基本上全部贡献给了小孩,看着孩子成长,懂得的东西日渐增多,懂得讲道理,懂得心疼爸爸妈妈。心里觉得时间画得特别值。

回顾2012年,事业上的变化就是我和老婆都换了新工作,两个人的新工作都比原来好,时间也比原来自由。

个人技能提升就是学习了Golang,Google的新的系统级的编程语言,语法跟C相似,不过比C多了一些高级功能,因为自己做嵌入式工作,主要编程语言是C,之前有学习Python作为平时的工具语言。Go结合了C和Python的优点,用来写一些小工具可以很快就搞定。

家庭的变化就是怀上了蛇宝宝,明年家里更加热闹了。

2013年,新的一年,列一下目标:
1. 学习绘画,铅笔画,或者在电脑上,总之要学习绘画。目标就是人物画像要到一个水平,自己已经申请了另外一个bloger账户,准备专门用来放自己的作品,跟踪自己的进步。
2. 学习游戏开发,用ActionScript来开发游戏,这个也就顺带要求学习ActionScript了,学习绘画也是因为觉得开发游戏是需要一些CG的基础的
3. 继续坚持上下班的时候在地铁上读书,自从买了Kindle后,自己的读书量的确增长不少,不管是技术类的书,还是小说,只要是在读书。

游戏开发

没有开发过游戏,想学习一下游戏开发。第一步当然是要确定选择什么开发平台,在网上做了一番搜索,因为自己初学,当然是先搞好2D的游戏开发,所以搜索范围就放在比较流行的一些2D游戏平台上。
因为现在手机OS有好几种,选择游戏开发平台的时候,首要就应该是要能够跨平台,我觉得这个对于我来讲是很重要的一个要求,还有一个要求就是免费。

初步筛选,比较中意的有3个平台

1. Starling-Framwork
优点:
  • 这个平台依靠Adobe AIR, 跨平台,很大的优点,支持桌面开发,网页开发和主流的移动平台Android,iOS,BlackBerry
  • 用ActionScript开发,开发起来速度会比较快,结合Adobe Flash,Adobe Ilustrator可以让游戏中的CG部分变得轻松一些。
  • Starling因为有GPU加速,速度方面不是问题
  • 跟着FlashBuilder 4.7推出的Scout能够帮助profile游戏运行的瓶颈
  • 新加入的worker引入了多线程操作,为游戏开发加分不少
  • 能很好的和流行的物理引擎结合(比如Box2D)
缺点:
  • ActionScript,需要学习多一门语言
  • 依靠Adobe AIR,发布的时候如果带上runtime,包会比较大。
  • 免费开发软件不是很多(FlashDevelop, FDT)
2. libGdx
JAVA开发,跨平台,对于iOS的支持还没有完成, 底层用Native code写,速度没问题

3. PhoneGap
基于HTML,JavaScript, CSS开发,真正的跨平台。最大的问题可能是速度
这个应该是以后APP的趋势吧

因为我自己有Adobe FlashBuilder 4.7 Standard的license,因为自己还是一个入门级的游戏开发人员,所以我选择Starling作为自己现在的起步开发平台。当熟悉游戏开发中的方方面面后,我或许会选择别的平台,不过那是以后的事情了。


Reference:

Thursday, October 25, 2012

给我的Sony Ericsson Arc S换成AOKP ROM Build 4

之所以要换ROM,是因为Sony Ericsson的ROM有点站空间,很多自带的APP我用不着也不让卸载,而Arc S的内置空间才只有可怜的400MB左右。每天都看到好几个update error的信息,因为空间不够。

这里把安装过程简单记下来,因为我走了一些弯路,所以想给那些要跟我一样换ROM的朋友一些帮助。

第一步,下载需要的软件,我用到了Android SDK (因为有些用到的工具里面会依赖adb,而工具包里面的adb又太旧了,所以要下载最新的adb来替代工具包里面的adb),flashtoolDooMLoRD_v1_Xperia-2011-ICS-ROOT-emu-busybox-su.zip(要用前面下载的SDK里面的adb和dll替换这个包里面的adb和dll,否则出出现“adb server is out of date, killing …”),ROM和Google Apps

第二步,解锁boot loader,具体步骤参考: http://unlockbootloader.sonymobile.com/instructions, 因为我不知道有这一步,所以浪费了很多时间摸索。

第三部,Root Device,做了第一步以后,这步就比较简单,参考 :http://talk.sonymobile.com/thread/41119?start=0&tstart=0 这个讲的一步一步,照着做就行了。如果需要安装driver,就运行C:\flashtool\drivers\Flashtool-drivers.exe来安装

第四部,备份,安装AOKP包,具体步骤参考:http://www.androidgadgematic.com/2012/09/install-android-41-jelly-bean-cm10-sony.html  这个里面讲的是安装CM10,不过同样适用于安装AOKP。

Tuesday, October 9, 2012

Install Android CM9 On HP TouchPad

I have bought HP Touchpad for more than 1 year, but I only use it in the first one month after bought it. Last week when I read the news about HP released Open WebOS 1.0, I suddently come out the idea to load my TouchPad with Android CM9 (since CM10 is not very usable at moment).

Reference Instruction Page: http://liliputing.com/2012/01/how-to-install-android-4-0-on-the-hp-touchpad-cyanogenmod-9-alpha.html

Steps:
1. Download all necessary files
* ACMEInstaller3 : http://goo.im/devs/jcsullins/cmtouchpad/tools
* moboot_0.3.5.zip : http://code.google.com/p/moboot/downloads/list
* UniversalNovacomInstaller-1.3.jar : https://code.google.com/p/universal-novacom-installer/downloads/list
* gapps-ics-20120429-signed.zip : http://goo.im/gapps/
* cm-9-20121007-NIGHTLY-tenderloin.zip : http://download.cyanogenmod.com/?type=nightly&device=tenderloin
* update-cwm_tenderloin-1012.zip : http://goo.im/devs/jcsullins/cmtouchpad/recovery

2. Install UniversalNovacomInstaller, it will be installed in to c:\Program Files\Palm, Inc

3. Place ACMEInstaller3 into same folder as UniversalNovacomInstaller, which is c:\Program Files\Palm, Inc

4. Connect TouchPad to PC, enable USB mass storage mode

5. Make new folder in root of Touchpad storage, folder name "cminstall"

6. Copy files into "cminstall"
* update-cm-9-20121007-NIGHTLY-tenderloin.zip (renamed, name must start with "update-")
* moboot_0.3.5.zip
* update-cwm_tenderloin-1012.zip
* gapps-ics-20120429-signed.zip

7. Reset Device (Setting -> Device Info -> Reset -> Restart)

8. As soon as the screen goes dark, press and hold the volume button, release the button when you see bit USB icon.

9. Wait for computer to install driver

10. Open cmd line, cd into c:\Program Files\Palm, Inc

11. Run ACMEInstaller3, “novacom.exe boot mem:// < ACMEInstaller3″

The whole installation process is very smooth. But I do encountered two problems for this Cm9 installation.

First issue is installation of google apps, ACMEInstaller3 didn't install gapps, so I must boot into ClockworkMod to instll zip from SD card.

Second issue is from Google Play Store, after I added Gmail account, gmail can sync, but when I run Play store, it always gave "Server Error" message. What I did is to run Google Talk and login, run Google Calendar and refesh to sync. After that, magically I was able to connect to play store.

Strange behavior.

Anyway, now I got a nice working (except camera) Android tablet to play with.

Wednesday, September 19, 2012

计算两个日期间隔,用X年X月X日表示

自己用golang写了一个短代码用来计算两个日期间隔,间隔用X年X月X日表示出来,比如2010-07-19到2012-09-18的间隔就是2年1月30天。写这个程序是用来具体算小孩的年龄,闰年也有考虑在内,比如 2010-07-19到2012-03-18是1年7个月28天,因为2012年2月有29天。

package main

import (
    "flag"
    "fmt"
    "os"
    "strconv"
    "strings"
    "time"
)

type DateDiff struct {
    years, months, days int
}

var DAYS = map[time.Month]int{
    time.January:   31,
    time.February:  28,
    time.March:     31,
    time.April:     30,
    time.May:       31,
    time.June:      30,
    time.July:      31,
    time.August:    31,
    time.September: 30,
    time.October:   31,
    time.November:  30,
    time.December:  31,
}

func LeapYear(year int) bool {
    ret := false
    if year%4 == 0 {
        if year%100 != 0 {
            ret = true
        } else if year%400 == 0 {
            ret = true
        }
    }
    return ret
}

// passed in strings hould be in either of the following two format:
//    yyyy-mm-dd
//    yyyy/mm/dd
func ParseDate(s string) time.Time {
    var it []string
    if strings.Index(s, "-") > 0 {
        it = strings.Split(s, "-")
    } else if strings.Index(s, "/") > 0 {
        it = strings.Split(s, "/")
    } else {
        fmt.Printf("Error: wrong date format\n")
        flag.Usage()
        os.Exit(-1)
    }
    y, err := strconv.ParseInt(it[0], 10, 64)
    if err != nil {
        panic(err)
    }
    m, err := strconv.ParseInt(it[1], 10, 64)
    if err != nil {
        panic(err)
    }
    d, err := strconv.ParseInt(it[2], 10, 64)
    if err != nil {
        panic(err)
    }
    return time.Date(int(y), time.Month(int(m)), int(d), 0, 0, 0, 0, time.UTC)
}

func main() {
    var ds, de string
    flag.StringVar(&ds, "start", "", "[*]Start Date in format of yyyy/mm/dd or yyyy-mm-dd")
    flag.StringVar(&de, "end", "today", "End Date in format of yyyy/mm/dd or yyyy-mm-dd")
    flag.Parse()
    if ds == "" {
        fmt.Printf("Error: No start date is specified\n")
        flag.Usage()
        os.Exit(-1)
    }

    var start, end time.Time
    start = ParseDate(ds)
    if de == "today" {
        end = time.Now()
    } else {
        end = ParseDate(de)
    }

    var diff DateDiff
    var borrowed bool = false
    var daysBorrowed int = 0
    // Days difference
    if end.Day() >= start.Day() {
        diff.days = end.Day() - start.Day()
    } else {
        daysBorrowed = DAYS[end.Month()-1]
        if LeapYear(end.Year()) && end.Month() == time.March {
            daysBorrowed++ // February in leap year is 29 days
        }
        diff.days = end.Day() + daysBorrowed - start.Day()
        borrowed = true
    }

    // Month Difference
    endMonth := end.Month()
    if borrowed == true {
        if endMonth == time.January {
            endMonth = time.December
        } else {
            endMonth--
        }
        borrowed = false
    }
    if endMonth >= start.Month() {
        diff.months = int(endMonth) - int(start.Month())
    } else {
        diff.months = int(endMonth) + 12 - int(start.Month())
        borrowed = true
    }

    // Year difference
    if borrowed {
        diff.years = end.Year() - 1 - start.Year()
    } else {
        diff.years = end.Year() - start.Year()
    }

    // Output
    if diff.years < 0 || diff.months < 0 || diff.days < 0 {
        fmt.Printf("Error: end date should after start date\n")
    } else {
        fmt.Printf("Difference of %d Years %d Months %d Days\n", diff.years, diff.months, diff.days)
    }
}

Friday, August 24, 2012

用golang生成key不是大写的json数据

前一段时间用go写了一个查看perforce的history的小程序,go没有什么成熟的ui包,所以我选用web界面,程序本身做两件事情,一个后台更新perforce的history到本地的sqlite数据库,另外一个后台当作web服务器,处理client的request,生成json数据。

在写这个程序的时候,发现要生成json数据的结构里field名字首字母要大写。因为是一个自己用的小程序,也没有去深究到底可不可以生成首字母是小写的json数据。今天逛stackoverflow的时候看到有人问这个问题,看了看,原来go的json包有解决办法,只是自己看文档的时候没有怎么注意罢了。要加tag来做这件事情。

下面这段示例代码就的output:

{"field_a":1234,"field_b":"hello"}

package main

import "fmt"
import "encoding/json"

func main() {
    type Test struct {
        A int `json:"field_a"`
        B string `json:"field_b"`
    }
    A := Test{1234, "hello"}

    b, _ := json.Marshal(A)
    fmt.Println(string(b))
}

Thursday, August 23, 2012

个人第一个github项目

今天终于在github上有了一个真正的自己的项目,虽然是一个很简单,很小的项目,不过还是值得纪念一下。

项目地址: https://github.com/yongzhy/goploticus

这个是libploticus的Go语言封装。

ploticus的主页

A free, GPL, non-interactive software package for producing plots, charts, and graphics from data. It was developed in a Unix/C environment and runs onvarious Unix, Linux, and win32 systems. ploticus is good for automated or just-in-time graph generation, handles date and time data nicely, and has basic statistical capabilities. It allows significant user control over colors, styles, options and details. Ploticus is a mature package, available since 1999, and version 2.40 has more than 12,000 downloads to date. Ploticus was discussed in this 2008 review on Linux.com.

因为是第一次封装C的API,折腾了一阵子才发现要让cgo编译代码,import “C” 必须是单独一行.

可以编辑的代码:

  1. //#cgo LDFLAGS: -lploticus

  2. //#include <libploticus.h>

  3. //#include <stdlib.h>

  4. import "C"

不可以被编辑的代码:

  1. //#cgo LDFLAGS: -lploticus

  2. //#include <libploticus.h>

  3. //#include <stdlib.h>

  4. import (

  5. "C"

  6. )

什么东西,都要试了才真正知道。

Friday, August 10, 2012

TextMate开源了

Mac下面无比NB的文件编辑器TextMate开源了,代码已经放在github上了。
因为TextMate只支持Mac,曾经让我这个只有Linux和Windows的用户无比羡慕。在羡慕加嫉妒TextMate用户的时候,我发现了Sublime Text 2,这个也是一个强大的编辑器,很容易上手,也很容易定制。因为TextMate作者长时间没有更新,Sublime Text 2已经慢慢的蚕食了很多TextMate的市场。
现在TextMate开源了,希望有高手可以赶快移植到Linux,Windows上,我们选择编辑器的时候就又多了一个选择。

Wednesday, August 8, 2012

putty + tmux 结合实现命令行多窗口

最近要远程登录Linux系统做一些东西,用putty一次 只能够执行一个程序,要在不同的目录运行不同的东西,要打开几个putty,很是麻烦。Google了一下,找到tmux这个小程序,参考了别人的配置,自己稍加改动,现在使用起来真的很爽。

我的配置文件:

##########################################################
# STATUS BAR
set -g status-utf8 on
set -g status-key vi
set -g status-interval 1
set -g status-attr bright
set -g status-fg white
set -g status-bg black
set -g status-left-length 20
set -g status-left '#[fg=green][#[fg=red]#S#[fg=green]]#[default]'
set -g status-justify centre
set -g status-right '#[fg=green][%m/%d %H:%M:%S]#[default]'
setw -g window-status-current-format '#[fg=yellow](#I.#P#F#W)#[default]'
setw -g window-status-format '#I#F#W'


##########################################
## TERMINAL EMULATOR TITLES
set -g set-titles on
set -g set-titles-string "#(tmux ls | awk -F: '{print $1}' | xargs | sed 's/\ / | /g')"


##########################################
## KEy BINDINGS
unbind C-b
set -g prefix C-s

# - = vertical split
unbind '"'
bind - split-window -v

# | = horizontal split
unbind %
bind \ split-window -h

# VIM Style movement
bind k selectp -U   # choose top panel
bind j selectp -D   # choose bottom panel
bind h selectp -L   # choose left panel
bind l selectp -R   # choose right panel

# bind ALT+Arrow to select panel
bind -n M-Up selectp -U   # choose top panel
bind -n M-Down selectp -D   # choose bottom panel
bind -n M-Left selectp -L   # choose left panel
bind -n M-Right selectp -R   # choose right panel


# Keys for resize panel
bind -n F9 resizep -U 1   # up
bind -n F10 resizep -D 1  # down
bind -n F11 resizep -L 1  # left
bind -n F12 resizep -R 1  # right

##########################################
## BASIC CONFIG
## utf8 ability
setw -g utf8 on
#
## vi Style Editing
setw -g mode-keys vi
#
## Make mouse useful in copy mode
#setw -g mode-mouse on

#
## Allow mouse to select which pane to use
#set -g mouse-select-pane on
#
## Allow xterm titles in terminal window, terminal scrolling with scrollbar, and setting overrides of C-Up, C-Down, C-Left, C-Right
set -g terminal-overrides "xterm*:XT:smcup@:rmcup@:kUP5=\eOA:kDN5=\eOB:kLFT5=\eOD:kRIT5=\eOC"
#
## Scroll History
set -g history-limit 30000
#
## Set ability to capture on start and restore on exit window data when running an application
setw -g alternate-screen on
#
## Lower escape timing from 500ms to 50ms for quicker response to scroll-buffer access.
set -s escape-time 50