Simplicity is the ultimate sophistication

Time is a tangled web. Try not to dwell on all the loose ends..

Leap Motion

1
2
3
4
5
Hi Robert,

Your Leap Motion Controller has shipped.

Thank you for your purchase. We're excited to share this first step into the future of technology with you. You can also track your order here.

Web Sites

This is for designer to find job dribbble.

Free online store tictail.

Infinit Scrolling : http://nodejs.org/dist/v0.10.8/node-v0.10.8.tar.gz

Exit

Exisitng….

WCF Reference No Display on Object Browser

Today, my colleage add a WCF service for reference on visual studio 2010, but cannot found any change in web.config, also saw nothing on Object Browser.

The cause is Newtonsoft.Json.dll, remove it, add WCF reference, add the dll reference back, done.

Some Tips(4)

用MAC的Termail SSH遠端 看個中文或日文會賞一堆亂碼的解決方法

這是幹來的好招, 原始是簡體網站. 就跑下面這一行, 跑完就搞定了

sudo sed -ie -e "s/\ \ \ SendEnv\ LANG\ LC_*/#\ \ \ SendEnv\ LANG\ LC_*/g" /etc/ssh_config

獅子之後才會有這問題, 是Client Side issue…

有關IDE的Theme跟字型

Stack Overflow討論, The Official Zenburn Page.

字型就是Adobe出的免費好看程式碼字型, 這個則是新版.

怎麼上傳檔案到Ubuntu Server

Some Tips(3)

Get Img Src URL by HTMLAgilityPack

1
2
3
4
5
var document = new HtmlWeb().Load(url);
var urls = document.DocumentNode.Descendants("img")
  .Select(e => e.GetAttributeValue("src", null))
  .Where(s => !String.IsNullOrEmpty(s));
                                

C# Mongo Database Find with Sorting

1
2
3
db["collection"].Find(new Document().Append("query", 
new Document()).Append("orderby", 
new Document().Append(field1:1).Append(field2),-1))); 

強迫Application跑在某個NIC上面

Force an application to use a specific network interface

一句話 調整routing table, 試試netstat -rnetstat -nr

Macbook 拆按鍵

我後來去買了個塑膠膜, 當在laptop前吃飯時我就會裝上去, 以免要拆按鍵清. 拆按鍵可以看這個影片, 這個算是我找到最清楚的了…

怎麼知道裝了Apache了沒?

try this apache2 -v

Mongo Db Find Like

db.users.find({“name”: /.m./})

Windbging VirtualBox when host also another VirtualBox guest

When you are using MAC and want to doing kernal debug, maybe you can only using VM that inside another VM.

I am doing this way, built a VirtualBox VM with Windows 7, and install VirtualBox inside with Windows XP for debug target.

But the tartget VM hang when Windbg starting, although I aware that just very very slow but not hang. almost taken my 5 mins and windbg start working. and every behavior also caused same slow stuation.

Finally I install VirtualKD and that speed up the debug performance, almost real time. But must using VirtualBox 4.1 for the debug target, seems now still now support 4.2.

And also you can do nothing for debug, include setup com1 pipe, because VirtualKD will take care it.

我工作機器現在是一台Mac book, 但是最近要做 Windows Kernal Debug, 怎做呢? 我裝了一台Windows 7的Virtual Box VM, 然後再在裡面裝一台Windows XP的VM.

不過當打開Windbg的一瞬間, 裡面那台Windows XP瞬間卡住, 沒有任何反應. 本來我以為壞掉了, 結果過了五分鐘, Windbg動了. 真的只是慢到不行, 然後你隨便下個指令, 又再來一次, 這樣根本沒辦法做事.

後來找到一個工具, VirtualKD, 裝上去搞很久也沒辦法integrate, 老是得到Unable to cast COM object of type “VirtualBox.VirtualBoxClass” to interface type “VirtualBox.IVirtualBox”. This operation failed because the QueryInterface call on the COM componenet for the interface with … 的錯誤. 後來才發現要用舊的版本. 後來改裝VirtualBox 4.1就瞬間發現美好的世界, 一整個順到不行. 甚至也不用改boot.ini, 加開com1 for windbg, VirtualKD會通通幫你做掉.

Some Tips(2)

.NET Binary Serialize and Deserialize

Serialize:

1
2
3
using(FileStream fs = new FileStream($fileName, FileMode.Create)){
  new BinaryFormatter().Serialize(fs, $object);
}

Deserialize:

1
2
3
using(FileStream fs = new FileStream($fileName, FileMode.Open)){
  $object = ($type)(new BinaryFormatter()).Deserialize(fs);
}

Mono access SQL server by Windows NT Authentication on Ubuntu/Linux environment

using following connection string:

1
Server=$hostname;Database=$databaseName;User ID=$windowsDomain\$windowsUserid;Password=$windowsPassword;Integrated Security=SSPI;

Mongo Database Operation on SSH/mongo client

查詢某個Collection的某個欄位有哪幾種不同的值(Distinct):

1
db.$CollectionName.distinct("$FieldName");

將Collection內某個欄位通通改成null:

1
db.$CollectionName.update({},{$set:{$FieldName:null}},false,true);

Mono Access SQL Server

不知道為啥, 大量批次的時候就會獲得下面這錯誤, 看來抓下來debug看看好了, 不過要先生一個Ubuntu Client…XD

1
2
3
4
5
6
7
8
9
10
11
System.Data.SqlClient.SqlException: Server closed the connection. ---> 

Mono.Data.Tds.Protocol.TdsInternalException: Server closed the connection. ---> 

System.IO.IOException: Read failure ---> 

System.Net.Sockets.SocketException: Connection reset by peer
  at System.Net.Sockets.Socket.Receive (System.Byte[] buffer, Int32 offset, Int32 size, SocketFlags flags) [0x00000] in <filename unknown>:0
   
at System.Net.Sockets.NetworkStream.Read (System.Byte[] buffer, Int32 offset, Int32 size) [0x00000] in <filename unknown>:0
  

Octopress to Heroku on MAC

如果寫了篇文一直都上不去Heroku, 看看$ (pwd)是不是不在 octopress root, 雖然這頗搞笑, 但是還是會發生…

公開資訊網站

說的真, 要是想要把東西放到internet, 還特別開一個網站, 就是希望能把資料散播出去. 如果希望能散播給特定對象, 那就是要多加能判斷使用者的功能, 不管是鎖IP, 要登入, 要用智慧卡登入都是方法. 如果要避免bot, 要就塞bot avoid的script, 要不就弄個功能去擋他.

怎麼會抱怨有人重製你的網站的資料然後去散播呢? 那不就是想要把東西放在網站上的目的嗎? 有人幫你分享頻寬不是很棒嘛? 要是覺得loading太重, 對方沒留cache, 難道加個cache或是限定query的頻率很難嗎?

說真的, 我覺得這個腦殘的單位根本不知道啥叫Open Data. 那些跳出來說用Bot去掃網站是不好的, 就更不知所云了.

看看人家米國的, 英國的, 順便看看Government Digital Service Design Principles…then http://www.opendata.tw/

Some Tips(1)

一些紀錄

SQL Server 時間

Error Message:

System.Data.SqlTypes.SqlTypeException: SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM..

SQL Server只吃1/1/1753 12:00:00 AM 到 12/31/9999 11:59:59 PM, 所以塞資料要小心 必要的話寫個inline code轉一下

SCP的用法

1
$ scp  -P  22  -pr  -l  1000  ~\test.dat aaa@10.4.4.4:~\data

送到10.4.4.4

1
scp  -P 22 -pr -l 1000  aaa@10.4.4.4:~\data\data.dat ~\data\

從10.4.4.4撈回來

當Select Max(a) from T1, 但T1是空的Table

1
2
3
4
5
object ob = pfcmd.ExecuteScalar();
if (ob != DBNull.Value)
  maxsolutionid = Convert.ToInt32(ob.ToString()) + 1;
else
  maxsolutionid = 1;

這樣可以保證有值

Sublime, Replace “\r\n” as newline

Ctrl+Enter in Replace textbox. yes, you cannot see anything there, but it work!

About Gitolite

Gitolite

What is gitolite?

Gitolite是一個架在git上面的Access Control Layer.主要特點有:

  • 在Server只有一個account(user)
  • 用那個Account轉出多個Gitolite user, 只存在Gitolite, 不存在server, 所以可以access Git, 但是無法存取Shell
  • 可以控制多個Git Repository, 控制權限在讀的方面可以控制到repo level, 寫的方面可以到branch, tag, file, directory. 包含可以控制到誰可以rewind, create, delete branches跟tags.
  • 當git跟perl已經存在系統時, 可以不透過root安裝.
  • 大部分是用sshd驗證, 但是也可以用http. (http也許需要root的權限)

How does gitolite work

建議你先看看這個try it and see… 中文-沒事試試看. (很短, 別害怕)

what does a “gitolite repo” look like?

gitolite repo跟一般的git repo沒兩樣, 只是多了幾個”gl-“開頭的檔案, 另外在hooks這個子目錄下有一個update hook. 大部份的狀況下, 就只有這兩個. 換句話說, 你怎麼用git, 就可以怎麼用gitolite.

conventions used

圖示範例:

1
2
3
--//-->       network connection 網路連線
------>        exec() or system() 
--??-->        conditional exec() 有條件地執行

conditional指在執行時會有檢查 看看是不是不跑或是放棄執行.

git over plain ssh

如果你有在遠端ssh裡面用過rsync或是類似的軟體, git 在 ssh上面就是類似的狀況.

下面是過程的描述

for read operations (讀取)

1
2
git clone ------> ssh --//--> sshd ------> git-upload-pack
git fetch ------> ssh --//--> sshd ------> git-upload-pack

for write operations(寫入)

1
git push  ------> ssh --//--> sshd ------> git-receive-pack

git over gitolite

gitolite-shell

update hook

Add Content Into Heroku(Git)

Got error message as

! No such app as XXXApp

Fix: Type this and I think you’ll see the problem:

git remote -v Fix it like this:

git remote rm heroku

git remote add heroku git@heroku.com:electric-meadow-15.git

Get Connection refused when Installing Git

Error Message is :

errno=Connection refused fatal: unable to connect a socket (Connection refused)

this URL no avaiable any more

git clone git://eagain.net/gitosis.git

using following to replace

git clone https://github.com/res0nat0r/gitosis.git

Force Compatibility Mode in IE10

We knoe we can using “Document Compatibility” http://msdn.microsoft.com/en-us/library/cc288325(v=vs.85).aspx to force client using specific IE version to browse our page, but in IE10, there has a trick there.

For example, we can using

1
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />

to force client using IE7 compatibility mode, but some page failed on IE10, why? because this meta tag must first one after <head>.

Although this no many cases verifying, but seems a workaround for IE10.

If you want to force IE10 open your site on Desktop Style but not Metro Style, you can using

1
<meta http-equiv="X-UA-Compatible" content="requiresActiveX=true,IE=EmulateIE7" />

Which Application Pool Using CPU/Memory?

Sometime we found the CPU usage so high but only can know was using by w3wp.exe, but there are many application pool there, how to find out which one eating CPU/memory.

Install Process Monitor in Microsoft Sysinternals on server, then you can deal with this, beside this, you can also using this to found out which process lock the file that you cannot access.

  • Which Application Pool: Right Click the high CPU usage w3wp.exe, select “Properties”, the applicaiton pool name was on APP_POOL_ID field.
  • Which process lock the file: Click Find Handle or Dll… on Find, type the locked file name, and click Search

當伺服器CPU或記憶體被吃掉很多的時候, 只靠工作管理員我們只能知道被w3wp.exe吃掉了, 但是我們沒辦法判斷哪個Application Pool是罪魁禍首, 尤其是當有n百個Application Pool的時候, iisreset又會整個都影響到.

這時候可以下載 Process Monitor 到伺服器, 透過它找出罪魁禍首. 這個是Microsoft Sysinternals的一個工具, 它還可以拿來找出哪個Process咬住檔案, 整個鎖死.

  • 找Application Pool: Right Click the high CPU usage w3wp.exe, select “Properties”, the applicaiton pool name was on APP_POOL_ID field.
  • 找咬住檔案的Process: Click Find Handle or Dll… on Find, type the locked file name, and click Search

Commands for Add New Disk in Ubuntu Server

Samba

Configuration is on /etc/samba/smb.conf

1
2
3
4
5
6
7
8
[share name]
valid users = xxx
comment = info you want to input
writeable = yesbrowsable = yesguest ok = noread only = no```
#####Create the shared folder```mkdir -p /share```


#####grant permission

chown nobody.nogroup /srv/samba/share/“`

restart service

“` restart smbd restart nmbd

1
2
3
4
5
6
##Get Information##
Memory
```free -m```
Displays a line containing the totals memory in MB:
```
free -t -m

Report virtual memory statistics

1
vmstat

top - display top CPU processes

1
top

New Disk

disk free - Human-readable

1
df -h

show disk

1
ls /dev/[sh]d*

double confirm with fdisk -l =>List the partition tables for the specified devices and then exit. If no devices are given, those mentioned in /proc/partitions (if that exists) are used.

1
fdisk -l /dev/sdb

then

1
2
3
4
5
6
fdisk /dev/sdb 
n (new partition)
p (primary partition)
(Partition number) => as default by sequence
+XXXG  => assign XXX GB spave
w => write

confirm again

1
fdisk -l /dev/sdb

format disk

1
mkfs -t ext4 /dev/sdb1

blkid - command-line utility to locate/print block device attributes

1
2
3
4
5
6
blkid
/dev/sdb1: UUID="9924e024-3efd-46a5-ae14-263faa55f6b9" TYPE="ext4"/dev/sdb2: UUID="f22c1654-af69-4985-bc9b-9571cf0859e3" TYPE="ext4"/dev/sdb3: UUID="98bb2080-e8ea-473b-8488-9d6c7396080d" TYPE="ext4"/dev/sdb4: UUID="c744581c-a6a6-4278-adbd-792053a89f53" TYPE="ext4"```

edit ***/etc/fstab***

The syntax of a fstab entry is :

[Device] [Mount Point] [File System Type] [Options] [Dump] [Pass]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

fields description:

#####device

The device/partition (by /dev location or UUID) that contain a file system.

#####mount point

The directory on your root file system (aka mount point) from which it will be possible to access the content of the device/partition (note: swap has no mount point). Mount points should not have spaces in the names.

#####file system type

Type of file system (see LinuxFilesystemsExplained).

#####options

Mount options of access to the device/partition (see the man page for mount).

#####dump

Enable or disable backing up of the device/partition (the command dump). This field is usually set to 0, which disables it.

#####pass num

Controls the order in which fsck checks the device/partition for errors at boot time. The root device should be 1. Other partitions should be 2, or 0 to disable checking.

UUID=9924e024-3efd-46a5-ae14-263faa55f6b9 /download /dev/sdb1 ext4 defaults 0 0UUID=f22c1654-af69-4985-bc9b-9571cf0859e3 /data /dev/sdb2 ext4 defaults 0 0UUID=98bb2080-e8ea-473b-8488-9d6c7396080d /data/temp /dev/sdb3 ext4 defaults 0 0UUID=c744581c-a6a6-4278-adbd-792053a89f53 /data/ext /dev/sdb4 ext4 defaults 0 0 “`

and then, mount /data2