Monday, December 16, 2013

Automatic mount disk in Ubuntu


1) $ blkid
show the device file system (/dev/sda1) & UUID & TYPE.

2)

$ sudo mkdir /mnt/NewVolume
$ sudo cp /etc/fstab /etc/fstab.backup
$ sudo gedit /etc/fstab

在最後加上
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
e.g.
# 2T DataVolue was on /dev/sda1 during installation
UUID=e2878ada-c996-41d9-a91f-5ae803525355 /mnt/NewVolume  ext4   defaults              0       2
按照 /etc/fstab 的設定自動重新掛載一次 (不用重開機)      

$ sudo mount -a 
(if "unable to resolve host")
$ sudo -i
$ mount -a

Sunday, November 3, 2013

转载 Photoshop制作彩色素描人像效果

此教程为ps之家原创作品,如需转载请注明出处!http://www.3987.com/ps/photoshop/587.html
通过验证,NB!

素描人像效果有一种很独特的美感,今天我们就来将美女照片处理成素描的效果。当然,我们选择的照片,最好是头发占的比例较大的图片,因为头发最能体现出线条,而且不会让五官太过抢眼导致效果很怪异。
效果图
Photoshop制作彩色素描人像效果效果图
原图
Photoshop制作彩色素描人像效果原图

1:首先打开照片,复制出一个背景副本,然后执行调整-去色,变成黑白。
Photoshop制作彩色素描人像效果教程图-1
2:再复制一个黑白的副本图层出来。
Photoshop制作彩色素描人像效果教程图-2
3:将复制出来的黑白副本按Ctrl+I反相,然后将图层混合模式设置为颜色减淡。
Photoshop制作彩色素描人像效果教程图-3
4:设置了混合模式为颜色减淡之后,我们看见的画面是白色的。执行滤镜-其他-最小值,半径为2像素。
Photoshop制作彩色素描人像效果教程图-4
5:合并两个黑白图层,再复制出一个背景副本,放置于黑白图层的上方,将图层混合模式设置为亮光,不透明度43%。
Photoshop制作彩色素描人像效果教程图-5
6:按Shift+Ctrl+Alt+E盖印出一个图层,新建一个调整图层“色相/饱和度”,将饱和度降低为-20。
Photoshop制作彩色素描人像效果教程图-6
7:再新建一个“色彩平衡”调整图层,根据自己喜欢的调子调整一下。
Photoshop制作彩色素描人像效果教程图-7
8:再盖印出一个图层,执行调整-曲线,将图片拉暗一点。
Photoshop制作彩色素描人像效果教程图-8
9:再执行调整-色阶,分别设置80、1.5、225,让图片黑白更分明一些。
Photoshop制作彩色素描人像效果教程图-9
到此,最终效果就完成了。
Photoshop制作彩色素描人像效果教程图-最终效果图

Monday, October 28, 2013

The easy way to make link in linux


UI

1. right click the dirctory -> make link
2. cut & paste

Command

$ ln -s <real_dir> <shortcut>

Sunday, July 21, 2013

Adobe Premiere CS6 installation error (solved)


Installation error:
Exit Code: 34

-------------------------------------- Summary --------------------------------------

 - 1 fatal error(s), 0 error(s), 0 warning(s)



FATAL: Payload '{3F023875-4A52-4605-9DB6-A88D4A813E8D} Camera Profiles Installer 6.0.98.0' information not found in Media_db.

-

Solution:
Delete the .db files in “C:\Program Files (x86)\Common Files\Adobe\caps”

Wednesday, July 10, 2013

Kernel function

Source from wiki: 

Kernel functions in common use[edit]

Several types of kernel functions are commonly used: uniform, triangle, Epanechnikov, quartic (biweight), tricube, triweight, Gaussian, and cosine.
In the table below, 1{…} is the indicator function.
Kernel Functions, K(u)\textstyle \int u^2K(u)du\textstyle \int K^2(u)du
UniformK(u) = \frac12 \,\mathbf{1}_{\{|u|\leq1\}}Kernel uniform.svg  \frac13  \frac12
TriangularK(u) = (1-|u|) \,\mathbf{1}_{\{|u|\leq1\}}Kernel triangle.svg  \frac{1}{6}  \frac{2}{3}
EpanechnikovK(u) = \frac{3}{4}(1-u^2) \,\mathbf{1}_{\{|u|\leq1\}}Kernel epanechnikov.svg  \frac{1}{5}  \frac{3}{5}
Quartic
(biweight)
K(u) = \frac{15}{16}(1-u^2)^2 \,\mathbf{1}_{\{|u|\leq1\}}Kernel quartic.svg  \frac{1}{7}  \frac{5}{7}
TriweightK(u) = \frac{35}{32}(1-u^2)^3 \,\mathbf{1}_{\{|u|\leq1\}}Kernel triweight.svg  \frac{1}{9}  \frac{350}{429}
TricubeK(u) = \frac{70}{81}(1- {\left| u \right|}^3)^3 \,\mathbf{1}_{\{|u|\leq1\}}Kernel tricube.svg  \frac{35}{243}  \frac{175}{247}
GaussianK(u) = \frac{1}{\sqrt{2\pi}}e^{-\frac{1}{2}u^2}Kernel exponential.svg  1\,  \frac{1}{2\sqrt\pi}
CosineK(u) = \frac{\pi}{4}\cos\left(\frac{\pi}{2}u\right) \mathbf{1}_{\{|u|\leq1\}}Kernel cosine.svg  1-\frac{8}{\pi^2}  \frac{\pi^2}{16}

All of the above Kernels in a Common Coordinate System[edit]

All of the above kernels in a common coordinate system

Wednesday, June 26, 2013

大陆学生香港签注办理详细流程


源地址: http://blog.renren.com/GetEntry.do?id=463435135&owner=242242124


由于每年要办一次,写下来给下次看。
港府最新规定,延期最多延期一年,也就是延期到去办的那一天后一年。所以最好提前4周再去办,提前办需要理由,(有理由就好,他们很好说话的),而且明年继续延期的时间也必须提前(因为只能延期到办的那一天的后一年)。
1、办理在读证明(科大版)
ARRO拿Testimony申请表,填好给学院(CSE给Connie),隔天拿回(快可以当天),去恒生交20 (或者网上student center交, 打印凭证),收据和表给ARRO,> 3个 工作日拿回。 也可以在student center -> payment上交,需要打印凭证。

2、办理香港签注
复印香港身份证、通行证姓名页、香港签注页、最后入境章页(现在是入境標籤)
港逗留期間應妥善保存入境標籤。如因遺失需申請補發標籤,可親身到灣仔告士打道七號入境事務大樓五樓入境處延期逗留組免費補領。
但補領只適用於最就近一次的入境紀錄,申請人須仍然在港及在有效獲准逗留期限內。
http://www.immd.gov.hk/pdforms/id91.pdf 下载id91申请表,在http://www.gov.hk/tc/residents/immigration/nonpermanent/bookextensionstay.htm 网上预约(也可以不预约,当场也会发筹)。地铁湾仔A5出口走尽天桥,入境事务处,6楼内地居民组接待处。三月之前另填表不另收费,不算当天第7个工作日再去拿签注。 有理由可以请求提前,我提前到5天过。当场也可以复印,就在那层楼,2元一张。

3、拿香港签证
拿签注无需预约,12号窗口交单和通行证,等约半小时会叫名字,去14号窗口交160元。 注意这时候出入境要空出签证反面那页,给逗留签。

4、中旅办大陆逗留签
复印香港身份证、国内身份证、通行证姓名页、旧签注页、旧逗留签页、新签注页。地铁旺角E2直走,过大约3条街,到洗衣街62-72号,可明显看到转角处中旅香港。上三楼,在询问处排队,拿申请表和号码。任何其他地方照相无效,必须在旁边照相,40元。1号窗口可以复印,2元一张。等叫号。等待时间要看当天有多少人。叫到号码后,出示上述复印件,香港身份证,大陆身份证,通行证,交275元,通行证不需留下。不算当天10个工作日后带通行证来取。 如果多交钱可以5天,如果再多交可以2天。
填表注意:户口所在地写身份证地址,签注号码是签注上很长的字母+数字串,非右上角数字。
中旅要早去,否则要等很长时间。照相要求蓝底(和和返乡证不同,所以,所以最好不要穿蓝色衣服。

5、中旅取证
带回条,通行证。直接去3号窗口排队,他会当场贴好逗留签。至此全部搞定。

Thursday, June 13, 2013

A easy way to sort based on boost::bind


std::sort( first, last, bind( &X::name, _1 ) < bind( &X::name, _2 ) ); // sort by name

Example:

    //  find score difference Sort the vector by the first element increasingly


    std::vector<std::pair<int, ColorCategory> > labelColorPairs;
    std::sort(labelColorPairs.begin(), labelColorPairs.end(),
              boost::bind(&std::pair<int,ColorCategory>::first, _1) <
              boost::bind(&std::pair<int,ColorCategory>::first, _2));
Other bind functions (overload operators)

std::remove_if( first, last, !bind( &X::visible, _1 ) ); // remove invisible objects
and compare the result of bind against a value:
std::find_if( first, last, bind( &X::name, _1 ) == "Peter" );
std::find_if( first, last, bind( &X::name, _1 ) == "Peter" || bind( &X::name, _1 ) == "Paul" );
You can find them in details:

Monday, June 3, 2013

Building multiple binaries in one qt project


Use subdirs template. You can create a dir for each program. Here is an example how to use multipule pro in 1 dir.
  1. TEMPLATE = subdirs
  2. SUBDIRS = app1 app2
  3.  
  4. app1.file = src/app_1.pro
  5. app2.file = src/app_2.pro

Wednesday, May 22, 2013

Debug: undefined reference to 'vtable for XXXClass'

undefined reference to 'vtable for XXXClass'

If a class defines virtual methods outside that class, then g++ generates the vtable only in the object file that contains the outside-of-class definition of the virtual method that was declared first:
//test.h
struct str
{
   virtual void f();
   virtual void g();
};

//test1.cpp
#include "test.h"
void str::f(){}

//test2.cpp
#include "test.h"
void str::g(){}
The vtable will be in test1.o, but not in test2.o
This is an optimisation g++ implements to avoid having to compile in-class-defined virtual methods that would get pulled in by the vtable.
The link error you describe suggests that the definition of a virtual method (str::f in the example above) is missing in your project.

Wednesday, May 15, 2013

Problem solved: Why doesn't Chrome remember its window size settings?

Position of the window is only saved if the state (maximized/minimized/restored) is changed.
So, move the window to where you want it, then size it a little (this can be done before the move), and then shut down Chrome and restart. This is still really a bug, but at least there is an easy work around. 
Note: in fact, needn't to restart the Chrome.

Emacs on windows 7, setting up color themes


  1. Create this folderC:\Users\your_user_name\AppData\Roaming\.emacs.d\color-theme-6.6.0 (change or remove the version number as you like)
  2. Go to color-theme homepage and get the latest.  I got color-theme-6.6.0.zip
  3. Unzip and dump the file color-theme.el and the folder themes into the folder you created in step 1
  4. As per the references for ColorTheme and emacs Load Path, add the following to your.emacs (you may have to strip out any previous color theme settings yourself):
         (add-to-list 'load-path "~/.emacs.d/color-theme-6.6.0") 
         (require 'color-theme)
         (setq color-theme-is-global t)
         (color-theme-initialize)
         ;; A nice dark color theme
         (color-theme-lawrence)

Wednesday, May 8, 2013

Virtual destructors for base class


Always forget to do this....mark!

Virtual destructors are useful when you can delete an instance of a derived class through a pointer to base class:
class Base 
{
    // some virtual methods
};

class Derived : public Base
{
    ~Derived()
    {
        // Do some important cleanup
    }
}
Here, you'll notice that I didn't declare Base's destructor to be virtual. Now, let's have a look at the following snippet:
Base *b = new Derived();
// use b
delete b; // Here's the problem!
Since Base's destructor is not virtual and b is a Base* pointing to a Derived object, delete bhas undefined behaviour. In most implementations, the call to the destructor will be resolved like any non-virtual code, meaning that the destructor of the base class will be called but not the one of the derived class, resulting in resources leak.
To sum up, always make base classes' destructors virtual when they're meant to be manipulated polymorphically.
If you want to prevent the deletion of an instance through a base class pointer, you can make the base class destuctor protected and nonvirtual; by doing so, the compiler won't let you call delete on a base class pointer.
You can learn more about virtuality and virtual base class destructor in this article from Herb Sutter.

A virtual constructor is not possible but virtual destructor is possible. Let us experiment....
#include <iostream>
using namespace std;
class base
{

public:
    base(){cout<<"Base Constructor Called\n";}
    ~base(){cout<<"Base Destructor called\n";}

};
class derived1:public base
{

public:
    derived1(){cout<<"Derived constructor called\n";}
    ~derived1(){cout<<"Derived destructor called\n";}

};
int main()
{

    base* b;
    b=new derived1;
    delete b;

}
The above code output the following....
Base Constructor Called
Derived constructor called
Base Destructor called
The construction of derived object follow the construction rule but when we delete the "b" pointer(base pointer) we have found that only the base destructor is call.But this must not be happened. To do the appropriate thing we have to make the base destructor virtual. Now let see what happen in the following ...
#include <iostream>
using namespace std;
class base
{

public:
    base(){cout<<"Base Constructor Called\n";}
    virtual ~base(){cout<<"Base Destructor called\n";}

};
class derived1:public base
{

public:
    derived1(){cout<<"Derived constructor called\n";}
    ~derived1(){cout<<"Derived destructor called\n";}

};
int main()
{

    base* b;
    b=new derived1;
    delete b;

}
the output changed as following
Base Constructor Called
Derived constructor called
Derived destructor called
Base Destructor called
So the destruction of base pointer(which take an allocation on derived object!) follow the destruction rule i.e first the derived then the base. On the other hand for constructor there are nothing like virtual constructor. Thanks (Write Code and have fun!!!)

Monday, April 22, 2013

Emacs copy rectangle


1. select the rectangle
2. M-w (Esc w), copy
3. C-x r r (copy the register) -> Enter
4. go to the other buffer
5. C-x r i  (insert the register) -> Enter


Friday, March 29, 2013

Batch rename files in Bash


$ rename s/"SEARCH"/"REPLACE"/g *
This will replace the string SEARCH with REPLACE in every file (that is, *). The /g means global, so if you had a "SEARCH SEARCH.jpg", it would be renamed "REPLACE REPLACE.jpg". If you didn't have /g, it would have only done substitution once, and thus now named "REPLACE SEARCH.jpg". If you want case insensitive, add /i (that would be, /gi or /ig at the end).
With regular expressions, you can do lots more. For example, if you want to append something to every file: $ rename s/'^'/'MyPrefix'/ * That would add MyPrefix to the beginning of every filename. You can also do ending: $ rename s/'$'/'MySuffix'/ *
Also, the -n option will just show what would be renamed, then exit. This is useful, because you can make sure you have your command right before messing all your filenames up. :)

Thursday, March 28, 2013

How does one write code that best utilizes the CPU cache to improve performance?


The cache is there to reduce the number of times the CPU would stall waiting for a memory request to be fulfilled (avoiding the memory latency), and as a second effect, possibly to reduce the overall amount of data that needs to be transfered (preserving memory bandwidth).
Techniques for avoiding suffering from memory fetch latency is typically the first thing to consider, and sometimes helps a long way. The limited memory bandwidth is also a limiting factor, particularly for multicores and multithreaded applications where many threads wants to use the memory bus. A different set of techniques help addressing the latter issue.
Improving spatial locality means that you ensure that each cache line is used in full once it has been mapped to a cache. When we have looked at various standard benchmarks, we have seen that a surprising large fraction of those fail to use 100% of the fetched cache lines before the cache lines are evicted.
Improving cache line utilization helps in three respects:
  • It tends to fit more useful data in the cache, essentially increasing the effective cache size.
  • It tends to fit more useful data in the same cache line, increasing the likelyhood that requested data can be found in the cache.
  • It reduces the memory bandwidth requirements, as there will be fewer fetches.
Common techniques are:
  • Use smaller data types
  • Organize your data to avoid alignment holes (sorting your struct members by decreasing size is one way)
  • Beware of the standard dynamic memory allocator, which may introduce holes and spread your data around in memory as it warms up.
  • Make sure all adjacent data is actually used in the hot loops. Otherwise, consider breaking up data structures into hot and cold components, so that the hot loops use hot data.
  • avoid algorithms and datastructures that exhibit irregular access patterns, and favor linear datastructures.
We should also note that there are other ways to hide memory latency than using caches.
Modern CPU:s often have one or more hardware prefetchers. They train on the misses in a cache and try to spot regularities. For instance, after a few misses to subsequent cache lines, the hw prefetcher will start fetching cache lines into the cache, anticipating the application's needs. If you have a regular access pattern, the hardware prefetcher is usually doing a very good job. And if your program doesn't display regular access patterns, you may improve things by adding prefetch instructions yourself.
Regrouping instructions in such a way that those that always miss in the cache occur close to each other, the CPU can sometimes overlap these fetches so that the application only sustain one latency hit (Memory level parallelism).
To reduce the overall memory bus pressure, you have to start addressing what is called temporal locality. This means that you have to reuse data while it still hasn't been evicted from the cache.
Merging loops that touch the same data (loop fusion), and employing rewriting techniques known as tilingor blocking all strive to avoid those extra memory fetches.
While there are some rules of thumb for this rewrite exercise, you typically have to carefully consider loop carried data dependencies, to ensure that you don't affect the semantics of the program.
These things are what really pays off in the multicore world, where you typically wont see much of throughput improvements after adding the second thread.
share|edit
+1, this is excellent, thank you. – Antony Vennard Dec 29 '10 at 22:10

I recommend reading the 9-part article What every programmer should know about memory by Ulrich Drepper if you're interested in how memory and software interact. It's also available as a 104-page PDF.
Sections especially relevant to this question might be Part 2 (CPU caches) and Part 5 (What programmers can do - cache optimization).
share|edit