[Jersey] disable decode the URL path

use annotation “@Encoded”

Ex:

@Path("{first}/get")
public Response getYouWant(@Context HttpHeaders httpHeaders, @PathParam("first") String first, @QueryParam("second")  @Encoded String second);
Posted in Java | Leave a comment

Linux command to get time in milliseconds

src: Linux command to get time in milliseconds

date +”%T.%N” returns the current time with nanoseconds.
date +”%T.%6N” returns the current time with nanoseconds rounded to the first 6 digits, which is microseconds.
date +”%T.%3N” returns the current time with nanoseconds rounded to the first 3 digits, which is milliseconds.

Posted in Linux | Leave a comment

open external program from java for mac os x

String[] cmds = {"open",  tempFile.getAbsolutePath(), "-a", "/Applications/Microsoft Office 2011/Microsoft Excel.app"};
Runtime.getRuntime().exec(cmds);
Posted in Java, Mac, Office | Leave a comment

Add git branch name to bash prompt

edit ~/.bash_profile

if [ -f $(xcode-select -p)/usr/share/git-core/git-completion.bash ]; then
    . $(xcode-select -p)/usr/share/git-core/git-completion.bash
    . $(xcode-select -p)/usr/share/git-core/git-prompt.sh
fi

#enables color in the terminal bash shell
export CLICOLOR=1

#sets up the color scheme for list
export LSCOLORS=ExFxCxDxBxegedabagacad

#sets up the prompt color (currently a green similar to linux terminal)
export PS1='\n\[\e[1;30m\]┌─\[\e[0m\]\[\e[01;343m\]\u@\h\[\e[00m\]:\[\e[01;34m\]\w\[\e[00m\]\n\[\e[1;30m\]└──\[\e[0m\]\$ \[\e[00;33m\]$(__git_ps1 "(%s)")\[\e[00m\]'

#enables color for iTerm
export TERM=xterm-color

Posted in CentOS, Git, Linux, Mac, Ubuntu | Leave a comment

Install Hbase 5.9 in Mac OS X

  1. Download hbase package tar.gz file from https://www.cloudera.com/documentation/enterprise/release-notes/topics/cdh_vd_cdh_package_tarball_59.html

  2. Untar tar.gz file

  3. edit conf/hbase-env.sh

    export JAVA_HOME={{JAVA_HOME Directory path}}

  4. edit conf/hbase-site.xml

  <property>
    <name>hbase.rootdir</name>
    <value>file:///{{location}}/data</value>
  </property>
  <property>
    <name>hbase.zookeeper.property.dataDir</name>
    <value>{{location}}/zookeeper</value>
  </property>
  <property>
    <name>hbase.zookeeper.quorum</name>
    <value>{{hostname}}</value>
  </property>
  1. start hbase service

    bin/start-hbase.sh

  2. run hbase shell

    bin/hbase shell

  3. stop hbase shell service

    bin/stop-hbase.sh

Posted in HBase, Mac | Leave a comment

Gson usage : formJson

avoid to face the exception ‘java.lang.ClassCastException With com.google.gson.internal.LinkedTreeMap cannot be cast to…’, we use the TypeToken to convert json to List

public class Object {
    @SerializedName("n")
    private String name;
    @SerializedName("i")
    private String id;

    public String getName() {
        return name;
    }

    public Object setName(String name) {
        this.name = name;
        return this;
    }

    public String getId() {
        return id;
    }

    public Object setId(String id) {
        this.id = id;
        return this;
    }
}

// [{"n":"cowman","i":"cowman@xxx.com.tw"}, {"n":"cowman1","i":"cowman1@xxx.com.tw"}]

List<Object> ObjectList = new Gson().fromJson(targets, 
new TypeToken<List<Object>>(){}.getType());

Posted in Java | Leave a comment

Redirect stdout to logFile in shell script

exec > >(tee -i logfile.txt)

source: stackoverflow: redirect COPY of stdout to log file from within bash script itself

Posted in Shell Script | Leave a comment

protect data validation to fail while copy and paste data

Private Sub Worksheet_Change(ByVal Target As Range)
    'Does the validation range still have validation?
    Set range1 = Range("B2:B6500")
    If HasValidation(range1) Then
        Exit Sub
    Else
        Application.Undo
        MsgBox "您的操作將會被取消, " & vbCrLf & "請使用下拉選單進行選擇", vbCritical
    End If
End Sub

Private Function HasValidation(r) As Boolean
'   Returns True if every cell in Range r uses Data Validation
    On Error Resume Next
    x = r.Validation.Type
    If Err.Number = 0 Then HasValidation = True Else HasValidation = False
End Function

source: Ensuring That Data Validation Is Not Deleted

Posted in Excel | Leave a comment

Get timestamp in milliseconds


echo $(($(date +%s%N)/1000000))

in Mac OS X, the command date does not support the %N flag, we can install coreutils using homebrew.

brew install coreutils

Then use gdate to get which we want.

echo $(($(gdate +%s%N)/1000000))

Posted in Linux, Mac | Leave a comment

find unused files and delete them

find /var/log/radius/radacct -type f -name "reply*" -mtime +60 -exec rm -rf {} \;

-mtime N — more than N days without being edited
-exec CMD {} \; — comands, {} means the files which be found.

Posted in Linux, Shell Script | Leave a comment