if File.exists? path_out
puts path_out+" exists"
else
# puts path_out+" doesn't exist"
Dir.mkdir(path_out)
end
Monday, December 21, 2009
[Work] Ruby, check directory folder existence
Wednesday, December 16, 2009
[work] gnuplot
file: plot_gather.pl
==============
set output "stoke_C_gather7.png"
#set terminal postscript eps color 22
set terminal png size 1200, 900
set xlabel "Roughness"
set ylabel "C"
plot [][] \
'curve.txt' using 1:2 with lines title "Roughtness-C"
[Work] Ruby, organize text file
files=["stokesCR025.txt",\
"stokesCR05.txt",\
"stokesCR10.txt",\
"stokesCR15.txt",\
"stokesCR20.txt",\
"stokesCR25.txt",\
"stokesCR30.txt",\
"stokesCR35.txt",\
"stokesCR40.txt",\
"stokesCR45.txt",\
"stokesCR50.txt"]
rough=[0.025, 0.050, 0.100, 0.150, 0.200, 0.250, 0.300,0.350,0.400,0.450,0.500]
num=files.size
fout=File.new("curve.txt", "w")
for j in 0..num-1
fname=files[j]
puts "fname "+fname
roughness=rough[j]
file = File.new(fname, "r")
i=0
while i<2 do
line = file.gets
i=i+1
end
value1=line.match(/^[0-9]* /)
puts value1.to_s
value2=line.match(/ [-,.,0-9]*$/)
puts value2.to_s
file.close
fout.puts roughness.to_s+" "+value2.to_s
end
fout.close
Wednesday, December 2, 2009
[Ruby] make thumbnails
require "FileUtils"
require "ftools"
filetype = ".jpg"
path_in = Dir.pwd
path_out=path_in+"/thumbnail"
if !FileTest::directory?(path_out)
Dir::mkdir(path_out)
end
dir=Dir.open(path_in)
a=Array.new(dir.collect.length)
num=0
dir.each do |file|
if(file.length>filetype.length)
if (file[file.length-4..file.length]==filetype)
a[num]=file
num=num+1
end
end
end
puts num
for i in 0..num-1
fold = path_in + "/" + a[i]
fnew_ppm = path_out + "/" + a[i][0..a[i].length-5]+".ppm"
fnew_jpg = path_out + "/" + a[i][0..a[i].length-5]+".jpg"
cmdline="convert -resize 200x -quality 100 "+fold+" "+fnew_ppm
puts cmdline
system("#{cmdline}")
cmdline="convert -quality 100 "+fnew_ppm+" "+fnew_jpg
puts cmdline
system("#{cmdline}")
puts "---------------------"
File.delete(fnew_ppm)
end
[Ruby] resize image (portrait or landscape)
require "FileUtils"
require "ftools"
filetype = ".jpg"
path_in = Dir.pwd
path_out=path_in+"/size2900"
if !FileTest::directory?(path_out)
Dir::mkdir(path_out)
end
dir=Dir.open(path_in)
a=Array.new(dir.collect.length)
num=0
dir.each do |file|
if(file.length>filetype.length)
if (file[file.length-4..file.length]==filetype)
a[num]=file
num=num+1
end
end
end
puts num
for i in 0..num-1
fold = path_in + "/" + a[i]
fnew_ppm = path_out + "/" + a[i][0..a[i].length-5]+".ppm"
fnew_jpg = path_out + "/" + a[i][0..a[i].length-5]+".jpg"
#check the image size, portrait or landscape
cmdline="identify "+fold+" >t.txt"
system("#{cmdline}")
file = File.new("t.txt", "r")
line = file.gets
m=line.match(/[0-9]*x[0-9]*/)
width=m.to_s.match(/^[0-9]*/)
height=m.to_s.match(/[0-9]*$/)
#resize to ppm
if(width.to_s.to_i>height.to_s.to_i)
puts "landscape"
cmdline="convert -resize 2900x -quality 100 "+fold+" "+fnew_ppm
puts cmdline
system("#{cmdline}")
else
puts "portrait"
cmdline="convert -resize x2900 -quality 100 "+fold+" "+fnew_ppm
puts cmdline
system("#{cmdline}")
end
file.close
#convert ppm to jpg
cmdline="convert -quality 100 "+fnew_ppm+" "+fnew_jpg
puts cmdline
system("#{cmdline}")
puts "---------------------"
#delete ppm
File.delete(fnew_ppm)
end
File.delete("t.txt")
[Ruby] file rename
filetype = ".jpg"
path = "."
prefix="slide_"
dir=Dir.open(path)
a=Array.new(dir.collect.length)
num=0
dir.each do |file|
if(file.length>filetype.length)
if (file[file.length-4..file.length]==filetype)
a[num]=file
num=num+1
end
end
end
puts num
count=0
for i in 0..num-1
fnew=prefix+"%05d"%count+a[i][a[i].length-4..a[i].length]
count=count+1
old_file = path + "/" + a[i]
new_file = path + "/" + fnew
puts "old "+old_file
puts "new "+new_file
puts "--------------"
File.rename(old_file, new_file)
end
[Ruby] is a number
def is_a_number(s)
s.to_s.match(/\A[+-]?\d+?(\.\d+)?\Z/) == nil ? false : true
end
Thursday, October 8, 2009
[Work] Gears
http://www.pslofamerica.com/worm-drives.htm
NEXEN ANNOUNCES ROLLER PINION GEAR SYSTEM
http://www.nexengroup.com/nexen/index.jsp
ring gear
http://www.plasticmachiningcompany.com/index.php?vid=20091009135215-39p
Align Trex 500 Main Drive Gear 162T (2 pcs) H50018-1
Main Drive Gear/164T HN7019-1
0412-259
Sceadu G Second Gear 80T (DTDS)
$29.99
0412-113
SD Main Gear 87T
$8.09
Tail Shaft With Pulley
Monday, October 5, 2009
[Work] Visual Studio Linker tools errors
defaultlib "library" conflicts with use of other libs; use /NODEFAULTLIB:library
You are trying to link with incompatible libraries.
Important The run-time libraries now contain directives to prevent mixing different types. You’ll receive this warning if you try to use different types or debug and non-debug versions of the run-time library in the same program. For example, if you compiled one file to use one kind of run-time library and another file to use another kind (for example, single-threaded versus multithreaded) and tried to link them, you’ll get this warning. You should compile all source files to use the same run-time library. See the Use Run-Time Library (MD, /ML, /MT, /LD) compiler options for more information.
You can use the linker’s /VERBOSE:LIB switch to determine which libraries the linker is searching. If you receive LNK4098 and want to create an executable file that uses, for example, the single-threaded, non-debug run-time libraries, use the /VERBOSE:LIB option to find out which libraries the linker is searching. The linker should print LIBC.LIB and not LIBCMT.LIB, MSVCRT.LIB, LIBCD.LIB, LIBCMTD.LIB, or MSVCRTD.LIB as the libraries searched. You can tell the linker to ignore the the incorrect run-time libraries by typing the incorrect libraries in the Ignore Libraries text box on the Link tab of the Settings dialog box in Developer’s Studio or by using the /NODEFAULTLIB:library option with LINK for each library you want to ignore. See the Ignore Libraries (/NODEFAULTLIB) linker option for more information.
The table below shows which libraries should be ignored depending on which run-time library you want to use.
To use this run-time library Ignore these libraries
Single-threaded (libc.lib) libcmt.lib, msvcrt.lib, libcd.lib, libcmtd.lib, msvcrtd.lib
Multithreaded (libcmt.lib) libc.lib, msvcrt.lib, libcd.lib, libcmtd.lib, msvcrtd.lib
Multithreaded using DLL (msvcrt.lib) libc.lib, libcmt.lib, libcd.lib, libcmtd.lib, msvcrtd.lib
Debug Single-threaded (libcd.lib) libc.lib, libcmt.lib, msvcrt.lib, libcmtd.lib, msvcrtd.lib
Debug Multithreaded (libcmtd.lib) libc.lib, libcmt.lib, msvcrt.lib, libcd.lib, msvcrtd.lib
Debug Multithreaded using DLL (msvcrtd.lib) libc.lib, libcmt.lib, msvcrt.lib, libcd.lib, libcmtd.lib
For example, if you received this warning and you want to create an executable file that uses the non-debug, single-threaded version of the run-time libraries, you could use the following options with the linker:
/NODEFAULTLIB:libcmt.lib /NODEFAULTLIB:msvcrt.lib /NODEFAULTLIB:libcd.lib /NODEFAULTLIB:libcmtd.lib /NODEFAULTLIB:msvcrtd.lib
Friday, October 2, 2009
[Work] compiling LuxRender
bison: W4: permission denied
To fix:
use Cygwin bison and flex
install and include all libraries
boost:
use installer
required components:
serialization
thread
date time
regex
filesystem
system
error C3861: 'isatty': identifier not found
add: #include
#ifdef WIN32
#define snprintf _snprintf
#define vsnprintf _vsnprintf
#endif
Thursday, October 1, 2009
[Work] How to set the path in Windows 2000 / Windows XP
How to set the path in Windows 2000 / Windows XP.
Question:
How to set the path in Windows 2000 / Windows XP.
Additional information:
Modifying the path statement will enable an MS-DOS window opened in Microsoft Windows as well as older programs to locate files that may be required to run the program.
Users familiar with MS-DOS will remember the PATH= statement that was in the autoexec.bat file. Additional information about the MS-DOS path command that is still usable in Windows 2000 and Windows XP can be found on our path command page, additional information about the MS-DOS command can be found on our set command page.
See our dictionary path definition for additional information about this term and related definitions.
Answer:
The path is now managed by Windows 2000 / Windows XP and not the autoexec.bat or autoexec.nt files. To change the system environment variables, follow the below steps.
1. From the desktop, right-click My Computer and click properties.
2. In the System Properties window, click on the Advanced tab.
3. In the Advanced section, click the Environment Variables button.
4. Finally, in the Environment Variables window, highlight the path variable in the Systems Variable section and click edit. Add or modify the path lines with the paths you wish the computer to access. Each different directory is separated with a semicolon as shown below.
C:\Program Files;C:\Winnt;C:\Winnt\System32
Thursday, May 14, 2009
[Work] ruby script for listing the folder sizes in a folder in reversed order
#ruby script for listing the folder sizes in a folder in reversed order
require 'find'
def sizer(dirname)
sum=0
Find.find(dirname) do |f|
sum=sum+File.size(f)
# puts f
# puts sum
end
sum
end
dir=ARGV[0]
sa=Array.new #size array
pa=Array.new
Dir.foreach(dir) do |path|
folder=dir+"/"+path
if FileTest.directory?(folder)
if(path!="." && path!=".." )
pa.insert(-1, path);
s=sizer(folder)
sa.insert(-1, s)
end
end
end
#sorting
len=sa.size
for i in 0..len-2
flag=0
for j in 1..(len-1)
if(sa[j]>sa[j-1])
flag=1
t=sa[j]
sa[j]=sa[j-1]
sa[j-1]=t
t1=pa[j]
pa[j]=pa[j-1]
pa[j-1]=t1
end
end
if(flag==0)
break
end
end
for i in 0..sa.size-1
s=sa[i]
g=(s/(1024*1024*1024)).to_i
m=(s-g*1024*1024*1024)/(1024*1024).to_i
k=((s-g*1024*1024*1024-m*1024*1024)/1024).to_i
b=s-g*1024*1024*1024-m*1024*1024-k*1024
#st="%03d"%g+"G "+"%03d"%m+"M "+"%03d"%k+"K "+"%03d"%b+"B "
st=""
if(g!=0)
st=st+"%03d"%g+"G "
else
st=st+" "
end
if(m!=0)
st=st+"%03d"%m+"M "
else
st=st+" "
end
if(k!=0)
st=st+"%03d"%k+"K "
else
st=st+" "
end
print(st)
print(" "+pa[i]+"\n")
end
Thursday, May 7, 2009
[work] Outlook zooming message
text size, font size
Sunday, April 19, 2009
[Work] Ubuntu Chinese input
英文Locale下使用中文输入法
出自Ubuntu中文
中文输入法的添加 | 中文输入法fcitx | 中文输入法scim | 英文Locale下使用中文输入法 |
如果你的locale设置为英文,并安装了中文输入法,但它工作不正常,那么本文是你需要的。本文只关注英文locale下的问题。
本文作者:chinakr
授权许可:
如果你在英文locale下,正确安装scim或fcitx后仍无法正常使用输入法,解决的方法如下:
sudo aptitude install im-switch
如果你用scim,运行
sudo im-switch -s scim -z all_ALL
im-switch -s scim -z all_ALL
如果你用fcitx,运行
sudo im-switch -s fcitx -z all_ALL
im-switch -s fcitx -z all_ALL
这样,以后你就可以任意locale(英文、法文、藏文、维吾尔文,等等)下使用你喜欢的输入法了。
其实im-switch不过是帮你修改了几个配置文件而已。如果你实在不想装im-switch,也可以手动修改配置文件(比如下面就是一个加入en locale支持的例子,不过小心,有省力的软件帮你配置不用,一定要自己手工改,会被别人说你在装B哦)。
编辑 /etc/gtk-2.0/gtk.immodules(如果存在的话) 或者 /usr/lib/gtk-2.0/2.10.0/immodule-files.d/libgtk2.0-0.immodules 文件,在xim 的 local 增加 en 也就是说:
"xim" "X Input Method" "gtk20" "/usr/share/locale" "ko:ja:th:zh"
改成
"xim" "X Input Method" "gtk20" "/usr/share/locale" "en:ko:ja:th:zh"
保存退出,重启后再进就ok了.
[编辑] fcitx输入法
1. 安装
sudo apt-get install fcitx
2. 设置环境变量
echo -e "export XMODIFIERS=@im=fcitx\nexport GTK_IM_MODULE=\"xim\"\nexport QT_IM_MODULE=\"xim\"\nfcitx &">>~/.profile
3. 重启X
4. 方块字
gedit --encoding gbk ~/.fcitx/config
显示字体(中)=*
改为:
显示字体(中)=AR PL UMing CN #填你喜欢的中文字体
在fcitx激活状态( Ctrl+Space )下按 Ctrl+5 启用配置,重启X亦可。
以下待整理
补充作者:aBiNg
声明:你必须知道你在执行什么,请慎重操作!
如果是像本人一样,在英文locale环境下,只使用fcitx作为默认输入法的五笔用户,可以考虑删除scim。
删除scim
sudo apt-get remove --purge scim-*
sudo apt-get autoremove
sudo apt-get install -f
注:系统自动清理时,会提示删除ubuntu-desktop以及个别语言包之类,请自行google,再作决定。
安装fcitx
sudo apt-get update
sudo apt-get install fcitx
注:有的源中的fcitx存有bug(能调出输入法,但中文无法输入),请自行到fcitx官网下载页下载,按照说明文档编译安装 。
设置中文输入环境
echo 'LC_CTYPE=zh_CN.UTF-8' | sudo tee - -a /etc/environment
保存你的所有工作,重启X(ctrl+alt+backspace)。
ctrl+space调出/隐藏fcitx界面。
注:有些桌面环境(比如Fluxbox)可能并不能自动启动fcitx,可以在相应的启动脚本中(比如Fluxbox的启动脚本位于 ~/.fluxbox/startup)加入启动命令(比如 fcitx &)。也有其它的启动方法,请google。
注意,在纯英文环境下(没有安装任何中文支持),可能做了如上修改后fcitx仍然显示方块,这就是你的电脑中没有生成cn环境,可能进行如下修改以生成cn环境。
sudo gvim /var/lib/locales/supported.d/zh
加入如下内容
zh_SG.UTF-8 UTF-8
zh_HK.UTF-8 UTF-8
zh_TW.UTF-8 UTF-8
zh_CN.UTF-8 UTF-8
zh_CN.GB2312 GB2312
zh_CN.GBK GBK
zh_CN.GB18030 GB18030
zh_HK.Big5 Big5
zh_TW.Big5 Big5
sudo locale-gen
生成可能要几分钟,等等就行了,这样的话,在纯英文环境中fcitx也可正常显示状态栏上的文字了。
Friday, April 17, 2009
Thursday, March 26, 2009
[WORK] life saving
I get much faster decompressing and much smaller file size.
I save storage and time at the beginning and in the further processing.
Friday, March 6, 2009
Thursday, March 5, 2009
[Work] Move the focused window
Alt+Space then M then Arrow Keys
http://en.wikipedia.org/wiki/Table_of_keyboard_shortcuts
[Work] multi-threaded
error C3861: '_endthread': identifier not found, even with argument-dependent lookup
change
from Runtime library: Single-threaded Debug (/MLd)
to Runtime library: Multi-threaded DLL (/MD)
Wednesday, March 4, 2009
[work] How to create libfftw3-3.lib?
Hi,
The instrauction is acually sayng that in order to use the library you have to produce a libfftw3-3.lib file. I think that in order to do so you need to do following:
1. Open command line, for instance type cmd in the Start->Run
2. in the command line you need to setup vs environment by runing a bat file:
C:\Program Files\Microsoft Visual Studio .NET 2003\Common7\Tools\vsvars32.bat
3. Then make sure that you are in the directory where libfftw3-3.def is located (to go there use "cd" command)
4. execute command "lib /machine:i386 /def:libfftw3-3.def"
As result you will get a libfftw3-3.lib file
put this name in the "additional dependecies" field in the options of linker, and add path of the lib file in the "additional library directories" in the options of the linker.
Max
Tuesday, February 24, 2009
[work] working with Canon 5D
I connected the 5D to the PC using USB.
I tried the slots on the back.
An error incured.
"No camera detected"
"not compatible"
I tried one slot in the front.
Failed again.
I reinstalled all the softwares.
Failed again.
I switched to another USB slot in the front.
There are totally two slots.
The error information changed.
I switched to using the EOS utility.
I succeeded!
Thursday, February 19, 2009
[Language] love Wikipedia or Encyclopedia
They are so concise and clear.
They are good examples for learning tell stories in English with clarity.
Wednesday, February 18, 2009
[Work] How to model asperity scattering
[IDEA] random modulation
How about using random modulation?
Modulate the pattern with random pattern and its complementary.
The idea is from dithering.
spatial and temporal dithering for direct/global component separation and 3D scanning of translucent objects
frequency analysis (projected onto a diffuse white/gray screen)
dithering calibration
High speed camera
DLP projector
How to conquer these two problems?
- finite resolution of the camera and projector
- narrow depth of field of the projector
A future avenue of research is to design 2D spatial intensity patterns that create temporal dithering codes that are optimal for the task at hand.
TODO:
find a collaborator
References:
S.G. Narasimhan, S. J. Koppal, and S. Yamazaki. Temporal Dithering of Illumination for Fast Active Vision. ECCV 2008
Tuesday, February 17, 2009
[work] high speed light
***NOTE***
The projector is fast.
The human eyes are slow.
2. Fast range scanning
3. Real-time geometrically corrected projection on deforming surfaces
4. Encoded light for the tracking, tagging and control of a robotic swarm
5. Multiple coincident personal views with camouflage layer
Twenty-four images were displayed at a 60 Hz rate to provide multiple, seemingly simultaneous
views on a single display surface. Viewers used time-encoded shutter glasses to see person-specific views. This was first tested with multiple stereoscopic views. It was then tested with negative
and camouflage images that allowed a view visible without shutter glasses, along with multiple seemingly invisible views. This could be used to create a secure information display.
*** NOTE***
A fast light cinema, where multiple films are displayed parallel on the same screen
and the audiences wear different glasses to watch their own favorites.
6. Very high resolution display
A shuttered array of lenses may be used to optically produce multiple copies of an image.
Each lens in the array can then be shuttered to be synchronized with a sequential series of images projected from the Mule. In this way, a very high resolution image can be produced with a correspondingly reduced bit depth.