2014年4月2日 星期三

Using lambda expression to read a csv file

An old fashion way: using BufferedReader
For example, read a csv file, using first column as key and second column as value

Map<String, String> map=new HashMap<>();
BufferedReader br = new BufferedReader(new FileReader(PATH_TO_YOUR_FILE));
String line="";
while((line=br.readLine())!=null){
  String tmp[] = line.split(",");
  map.put(tmp[0],tmp[1]);
  ... THINGS YOU WANT TO DO ... 
}
br.close();


A fancy way: using Stream

Map<String, String> map = Files.lines(Paths.get(PATH_TO_YOUR_FILE))
.map(line -> line.split(","))
.collect(Collectors.toMap( 
      array -> array[0], 
      array -> array[1] 
));

2013年7月8日 星期一

Hadoop on Rocks Cluster

build hadoop from source
chmod -R 755 /state/partition1/data/hadoop/

conf/master
light

conf/slave
light
compute-0-1
...
compute-0-10


==> conf/core-site.xml <==
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>

<!-- Putsite-specificpropertyoverridesinthisfile. -->

<configuration>
 <property>
  <name>fs.default.name</name>
  <value>hdfs://light:54310/</value>
 </property>
 <property>
  <name>df.permissions</name>
  <value>false</value>
 </property>
</configuration>

==> conf/hdfs-site.xml <==
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>

<!-- Put site-specific property overrides in this file. -->

<configuration>
<property>
<name>dfs.name.dir</name>
<value>/state/partition1/data/hadoop/name</value>
<description> </description>
</property>
<property>
<name>dfs.data.dir</name>
<value>/state/partition1/data/hadoop/data</value>
<description> </description>
</property>
</configuration>

==> conf/mapred-site.xml <==
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>

<!-- Put site-specific property overrides in this file. -->

<configuration>
<property>
<name>mapred.job.tracker</name>
<value>light:54311</value>
</property>
</configuration>


2013年6月16日 星期日

透過 mac os x internet sharing 讓 PC 使用網路連線

目的:因為 pc 無法連線到 vpn server,但 mac 可以,所以想利用 mac 的網路連線,讓 pc 也能連入 vpn。
做法:因為 Mac Pro 有二個網路孔,所以讓 pc 能透過 mac 的第二個網路孔連線到 vpn

假設 mac 上的 vpn 設定已經完成。


  1. Open "System Preferences"
  2. Select "Sharing"
  3. Select your VPN connection from the list of "Share your connection from:"
  4. Select "Ethernet 2" in the checkboxes of "To computers using:"
  5. Turn on "On" checkbox of "Internet Sharing" from the Service list.
  6. Connect Ethernet cable between Mac's Port 2 and PC's port
  7. Connect VPN server in Mac
  8. Ping a VPN server, to make sure the connection between PC and VPN server is working




2012年5月2日 星期三

在 Java runtime exec 裡使用 pipe


String[] cmd = {
"/bin/sh",
"-c",
"ls /etc | grep release"
};
Process p = Runtime.getRuntime().exec(cmd);