Tuesday 30 December 2008

大家说说,GDP应该翻多少翻人民才有钱花

这个问题,我要问百度知道知道不知道知道就知道不知道就不知道不要知道说不知道不知道说知道到头来知道变成不知道不知道还是不知道天知道地知道百度知道知道若要问我知道不知道知道不知道也不知道。

晕了吧你!


null - Watch more free videos

Monday 22 December 2008

Php script to resize and add watermark

$xoffset=0;
$yoffset=0;
$opacitypercent = 80;
$scaling = 480;

$Photos=GetFileList();
foreach ($Photos as $original){
$watermark='logo.png';
AddWM($original,$watermark);
echo '*';
}


function AddWM($photo,$watermark){
//xoffset of the watermark
global $xoffset;
//yoffset of the watermark
global $yoffset;

//the original image to be watermarked
$originalimage=$photo;
//the watermark to apply
$watermarkimage = $watermark;

//top end opacity number (totally transparent)
$opacity0 = @MagickGetQuantumRange();

//bootom opacity (totally visible)
$opacity100 = 0;

//desired opacity percentage
// THIS IS THE ONE TO SET
global $opacitypercent;

//gather the actual opacity number
$opacity = $opacity0 * ( 1 - $opacitypercent/100 ) ;

//initialize the wands
$sourceWand = NewMagickWand();
$compositeWand = NewMagickWand();

//read in the images
@MagickReadImage($sourceWand, $originalimage);
@MagickReadImage($compositeWand, $watermarkimage);

//resize the original photo
global $scaling;
$PhotoWidth = MagickGetImageWidth($sourceWand);
$PhotoHeight = MagickGetImageHeight($sourceWand);
$WvsH = $PhotoWidth/$PhotoHeight;
if($WvsH>=1){
$resizeresult = MagickScaleImage( $sourceWand, $scaling, $scaling/$WvsH);
}else{
$resizeresult = MagickScaleImage( $sourceWand, $scaling*$WvsH, $scaling);
}

//setting the image index
MagickSetImageIndex($compositeWand, 0);
MagickSetImageType($compositeWand, MW_TrueColorMatteType);

//seting the opacity level
MagickEvaluateImage($compositeWand, MW_SubtractEvaluateOperator, $opacity, MW_OpacityChannel) ;

//combining the images
@MagickCompositeImage($sourceWand, $compositeWand, MW_OverCompositeOp, $xoffset, $yoffset);

//create a subdirectory to store photos with watermark
if(!is_dir("PhotosWithWaterMark")){
mkdir("PhotosWithWaterMark", 0755);
}
//generate the image
MagickWriteImage( $sourceWand, "PhotosWithWaterMark/"."WM_".$photo);
}

function GetFileList(){
$dir = "./";
$PhotoFormats = array('jpg','jpeg');
// Open a known directory, and proceed to read its contents
if ($dh = opendir($dir)) {
$PhotosList = '';

while (($file = readdir($dh)) !== false) {
$NameExt = explode(".",$file);
if (in_array(strtolower($NameExt[count($NameExt)-1]),$PhotoFormats)){
echo "filename: $file" . "\n";
$PhotosList[] = $file;
}
}
closedir($dh);
}
return $PhotosList;
}


?>

Sunday 21 December 2008

HOWTO: using Php to add watermark


makewatermark();

function makewatermark()
{
///////////////
// php imagemagick test harness
//
// create a watermarked image
///////////////

//xoffset of the watermark
//yoffset of the watermark

//the original image to be watermarked
$rawimage = NewMagickWand();
MagickReadImage( $rawimage, 'cyclops.gif' );
MagickWriteImage($rawimage, 'new_image.jpg' );
$originalimage='new_image.jpg';
//the watermark to apply
$watermarkimage = "sphinx.gif";

//top end opacity number (totally transparent)
$opacity0 = @MagickGetQuantumRange();

//bootom opacity (totally visible)
$opacity100 = 0;

//desired opacity percentage
// THIS IS THE ONE TO SET
$opacitypercent = 50;

//gather the actual opacity number
$opacity = $opacity0 - ($opacity0 * $opacitypercent/100 ) ;

//validate the opacity number
if ($opacity > $opacity0){
$opacity = $opacity0;
}elseif ($opacity <0){
$opacity = 0;
}

//initialize the wands
$sourceWand = NewMagickWand();
$compositeWand = NewMagickWand();

//read in the images
@MagickReadImage($compositeWand, $watermarkimage);
@MagickReadImage($sourceWand, $originalimage);

//setting the image index
MagickSetImageIndex($compositeWand, 0);
MagickSetImageType($compositeWand, MW_TrueColorMatteType);

//seting the opacity level
MagickEvaluateImage($compositeWand, MW_SubtractEvaluateOperator, $opacity, MW_OpacityChannel) ;

//combining the images
@MagickCompositeImage($sourceWand, $compositeWand, MW_ScreenCompositeOp, 0, 0);

//print out the image
MagickWriteImage( $sourceWand, 'new_image.jpg' );
//header("Content-Type: image/jpeg");
//MagickEchoImageBlob($sourceWand);
}
?>

Tuesday 16 December 2008

Website Development Costs

Your website should look professional, be available all the time, and
be written to SELL so that you get some business out of it!
We can help you do it the right way - the way that gets results!
Below are some website development costs.

Initial Consultation - FREE!

* You can show us what you want, and we will suggest ways to do it
properly.
o How to take great pictures.
o How to write text that sells.
o How to save money in domain hosting and name registration.
o Then, you can decide whether you want us to help you.
o If you don't know anything about the Internet or marketing, we
will explain things in layman's terms, not in "tecky" terms!
Contact us.



Prices are approximate because of many variables. How
fast do you need it? How much development needs to be done? Who is going to
supply the text and photos? Don't forget that promotion of your website is as
important as having a website. In our opinion, there is little use for a
website that no one visits. We want to see your website succeed as much as
you do! Having visitors coming to your website in a buying mood - that is
what we want to happen for your website.

Website development costs:

Basic Package - $380


* 1 page, approximately 300 words

(Note: you provide the text)

* Your contact information

* 1 email link, 6 links within website, 6 links outside of website

* Your logo (provided by you in .jpg or .gif format)*

* 2 photos (provided by you in .jpg format)**

* Free tracker installed on website.
Contact us.



Bronze Package - $790


* 2 - 5 pages, approximately 300 words per page
.
(Note: you provide the text)
* Your full contact information
.
* Up to 5 email links, 12 links within website, 12 links outside of
website
.
* Your logo (provided by you in .jpg or .gif format) on all pages*
.
* Up to 10 photos (provided by you in .jpg format)**.

* Free tracker installed on website.
Contact us.




Promotion Package - $999

* For those who presently have a website, but it is not drawing
traffic. You need qualified visitors - ones that are in a buying mood
for your product or service.
* People searching on the web are looking for your product or service.
Have your website show at the top of the search engine results pile!
* Analysis of present log files, if any.
* Website pages optimized for search engines and directories

(including Meta Tags, Image Tags, and keyword "loading" of up to 6
pages).
* Locating suitable reciprocal linking websites - minimum 15
but we suggest 30.

(including finding appropriate websites, sending requests and answering
emails, and putting links with descriptions on site).
Example
* Hand submitting to top 10 free major search engines and
directories

(Google, Yahoo, MSN, HotBot, Lycos, Canada, etc. - package does not include
submission to search engines that charge for listings)***
Contact us.


Hosting

* Basic hosting starts at $12/month. We used to recommend a
cheaper hosting service, for about $5/month, but we found that they were
unreliable - a fair number of times the website would not be viewable.
You want 99% reliability, with fast connections, full backup in case of
power failure, daily backup of data, and other critical items.
Read more about hosting.


Maintenance/Promotion - $90/month

* Your website will be professionally watched over.
* Continuous promotion - resubmission to search engines if needed.
* We will answer your questions about or respond to link requests.
* You can have changes done easily.
Click here for more
* Your website will look fresh - put your press releases on, etc.
* We will answer requests for reciprocal links, if appropriate.
* We will be available to answer your questions.
* Up to 1.5 hours per month, not compounding.
* Note: price may vary with complexity of website.



Website Link-Building

* Reciprocal linking will increase your website
visitor numbers from other websites.
* Reciprocal linking will raise your profile
on the major search engines.
* Having other websites linked to yours will
benefit your traffic for years.
* 30 other websites linked to your site -
approximately $450 (depends on certain criteria).


Hourly rate
for website development costs:

* $60/hour (USD)
* Basically, we charge for our time. We have the
proper tools and experience to get your job done quickly and
professionally. We are a home-based business with low overheads. We
constantly keep up on the latest methods of promotion, as well as
purchasing tools (programs) that help us do our job faster and more
effectively - to your benefit. We have been in the website development
business since 2000. Call us
today. Toll free in North America 1- 866-726-0788.


* How do our prices compare to other
companies?


Master level Web Development costs from $75-120/hr.

Custom Graphics costs $65-$75/hr.

On-Site Digital Photography costs $80+/hr.

Maintenance Contracts are negotiated for around $55-$75/hr.

Web Design Consulting costs $100-$300/hr.

Some companies cost $95 - $120/hr. across the board.

Setting up a Link Directory - we charge about $12/link. Here's
the competition's rate (taken from this web page:
http://www.simplywebhosting.com/websitemanagement.shtml

Advertising and Marketing Services
Price
Custom reciprocal link directory with 100
targeted reciprocal links $3000 per directory
Additional reciprocal links added to an
existing reciprocal link directory $20 per link

Thursday 11 December 2008

SHELL: sed and tr

在文件某一行(这里是最后一行)加上abc

sed '$ w temp1' file1
sed '$a\abc' temp1>temp2
tr "\n" " "<temp2>temp3
newlastline=`cat temp3`
sed '$ d' test
sed '$a\'"$newlastline" file1

=======================
sed -i '$ s/$/abc/' file1 #更简单的方法

Wednesday 10 December 2008

Excel to read files then plot

1. File selection: to select which file you want to plot
##############################
Public i As Integer

Sub FileSelect()

' File dialog to select files
'==============================
Dim fd As filedialog
Set fd = Application.filedialog(msoFileDialogFilePicker)

'Declare a variable to contain the path
'of each selected item. Even though the path is aString,
'the variable must be a Variant because For Each...Next
'routines only work with Variants and Objects.
Dim vrtSelectedItem As Variant

ActiveSheet.Cells.Clear

With fd
If .Show = -1 Then
i = 1
For Each vrtSelectedItem In .SelectedItems
Cells(i, 1).Value = vrtSelectedItem
i = i + 1
Next vrtSelectedItem
Else 'The user pressed Cancel.
End If
End With
'Set the object variable to Nothing.
Set fd = Nothing

' Sort the file list as Ascending, otherwise it will be sorted by selecting sequence
'==================================
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range("A1"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Sheet1").Sort
.SetRange Range("A:A")
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With


End Sub



2. Main module: to re-arrange the data, format them then plot it.
##############################
Sub Main()


' Initialization
'=================
Dim LastCell As String
Dim wb_1 As Object
Dim ws_3 As Worksheet
Dim ws_plot As Worksheet
Dim FileName As String
Dim R_last As Integer
Set wb_1 = ActiveWorkbook
Set ws_3 = wb_1.Sheets(3)
Set ws_plot = wb_1.Sheets(2)
wb_1.Sheets(1).Activate

' Call the files inserted in worksheet(1), and variable i is public var, declared in module 2.
'=================================
Dim j As Integer
j = 1
R_last = 1
For j = 1 To i - 1
FileName = wb_1.Sheets(1).Cells(j, 1).Value
Call doloop(FileName, R_last, wb_1, ws_3, ws_plot)
Next j


' Delete some useless rows for plotting
'=========================================
Dim k, R_plot As Integer
For k = 2 To R_last
If Left(Cells(k, 1).Value, 1) = ":" Then
Range(Cells(k, 1), Cells(k + 3, 1)).EntireRow.Select
Selection.Delete Shift:=xlUp
R_plot = k - 1
End If
Next k


' Plot the chart
'=================
Dim xyRange, ErrAmount As String
xyRange = "A3:A" & R_plot & "," & "C3:C" & R_plot
ErrAmount = "=" & ws_plot.Name & "!N4:" & "N" & R_plot

ws_plot.Activate
ActiveSheet.Shapes.AddChart.Select
ActiveChart.SetSourceData Source:=Range(xyRange), PlotBy:=xlColumns
ActiveChart.ChartType = xlLine
With ActiveChart.SeriesCollection(1)
.ErrorBar Direction:=xlY, Include:=xlBoth, Type:=xlCustom, Amount:=ErrAmount, MinusValues:=ErrAmount
End With


End Sub

Function doloop(FileName As String, ByRef R_last As Integer, ByRef wb_1 As Object, ByRef ws_3 As Worksheet, ByRef ws_plot As Worksheet)

Dim wb As Object
Dim PosC, R_Str, C_Str As String
Dim R, C As Integer

' Open the text file and copy contents
'=======================================
Workbooks.OpenText FileName:=FileName, Origin:=936, StartRow:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, Tab:=True

ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell).Select
LastCell = Selection.Address(RowAbsolute:=True, ReferenceStyle:=xlR1C1)

PosC = InStrRev(LastCell, "C")

R_Str = Right(Left(LastCell, PosC - 1), Len(Left(LastCell, PosC - 1)) - 1)
C_Str = Right(LastCell, Len(LastCell) - PosC)

R = CInt(R_Str) ' total number of rows
C = CInt(C_Str) ' total number of columns

Range(Cells(1, 1), Cells(R, C)).Select
Selection.Copy
Set wb = ActiveSheet.Parent
ws_3.Activate
With ws_3
.Cells(R_last, 1).Activate
.Paste
End With
Application.CutCopyMode = False
wb.Close SaveChanges:=False

R_last = R_last + R

' Move the Standard Deviation part to the right side
'=====================================================
ws_3.Activate
Range(Cells(R_last - R, 1), Cells(R_last - R + R / 2 - 1, C)).Select
Selection.Copy
ws_plot.Activate
With ActiveSheet
.Cells((R_last - R - 1) / 2 + 1, 1).Activate
.Paste
End With

ws_3.Activate
Range(Cells(R_last - R + R / 2, 1), Cells(R_last - 1, C)).Select
Selection.Copy
ws_plot.Activate
With ActiveSheet
.Cells((R_last - R - 1) / 2 + 1, C + 2).Activate
.Paste
End With

End Function

Sunday 7 December 2008

HOWTO: vuze (azureus) playing flash plugin

Vuze apparently uses XulRunner as the browser, So copy or link this file:


/usr/lib/mozilla/plugins/libflashplayer.so



to



/usr/lib/xulrunner-1.9/plugins


Thursday 4 December 2008

HOWTO: packagekit to check update per login

PackageKit only checks once per the update interval, by default once every day.
It does not check on every desktop login.

You can change this behaviour by changing
/apps/gnome-packagekit/force_

get_updates_login to TRUE in gconf-editor. The
description of this key is: "Get the update list when the session starts, even
if not scheduled to. This ensures the user has up to date and valid data in the
tray at startup."

Tuesday 2 December 2008

iphone 安装 wedict

stardict主页中文字典
http://stardict.sourceforge.net/Dictionaries_zh_CN.php星际译王的巴比伦词库 http://reciteword.sourceforge.net/stardict/babylon.php
StarDict Lingvo Dictionaries http://reciteword.sourceforge.net/stardict/lingvo.php
金山词霸词库http://reciteword.sourceforge.net/stardict/powerword.php
下载tarball包,用7-zip解压,然后把dict.dz改为dict.gz再用7-zip解压,得到dict文件,然后把dict 和idx这两个文件拷到~/Library/weDict 即1.1.3为/var/mobile/Library/weDict 1.1.3以前为/var/root/Library/weDict/
安装正常后,应该为同名的两个文件 dict和idx,运行后会生成第三个同名文件idxc. 如果没有这个目录,而是在Library下有一个 weDict文件的话,请删除这个文件,重新安装。
推荐手动安装,使用winscp(windows)或 fugu(mac).

5.真人发音如何安装?

下载地址为:http://prdownloads.sourceforge.n … TS.tar.bz2?download
安装路径为 ~/Library/weDict下载后将解压好的 WyabdcRealPeopleTTS目录通过winscp(windows)或fugu(mac)上传到安装目录。
只支持单词发音,不支持词组发音。没有声音的话,请确认手机不是在振动模式。

6. 1.0.2运行不了v0.8?

从目前情况来看,好像是运行不了,我的版本的是1.1.1,没有在102上测 。哪位老大愿意帮忙测一下的话,按以下步骤,把错误信息发给我。
6.1 iphone安装好openssh,weDict 0.8及相应字典。
6.2 putty联接到iphone运行如下命令:cd /Applications/weDict.app
./weDict
6.3 把错误信息发给我laoren@office.weiphone.com

7. 1.1.3查本地单词死机?

不是死机,是因为权限的问题。用ziphone破解的1.1.3后安装的installer的所有者还是root,所以建立的 /var/mobile/Library/weDict的目录仍为 root所有,而weDict用户权限为mobile, 当查询时,因为权限问题,没有办法建立缓存文件,所以很慢。解决办法:chown -R mobile:mobile /var/mobile/Library/weDict
可以用putty联上运行,也可以在iphone上安装mobileTerminal运行。

Monday 1 December 2008

Ubuntu smb.conf, supporting 'net usershare'=nautilus-share

[global]
usershare owner only = False
workgroup = workgroup
server string = %h server (Samba, Ubuntu)
dns proxy = no
log file = /var/log/samba/log.%m
max log size = 1000
syslog = 0
panic action = /usr/share/samba/panic-action %d
encrypt passwords = no
passdb backend = tdbsam
obey pam restrictions = yes
unix password sync = yes
passwd program = /usr/bin/passwd %u
passwd chat = *Enter\snew\s*\spassword:* %n\n *Retype\snew\s*\spassword:* %n\n *password\supdated\ssuccessfully* .
pam password change = yes
map to guest = bad user
usershare allow guests = yes
security = share
[printers]
comment = All Printers
browseable = no
path = /var/spool/samba
printable = yes
create mask = 0700
[print$]
comment = Printer Drivers
path = /var/lib/samba/printers
[test]
path = /home/cross/test
writeable = yes
; browseable = yes
guest ok = yes

lyx: insert unnumbered chapter/section to Table of Contents

Just like metioned here:
http://wiki.lyx.org/FAQ/Unsorted1#toc11

To insert unnumbered chapter:
\addcontentsline{toc}{chapter}{THECHAPTERNAME}

To insert unnumbered section:
\addcontentsline{toc}{section}{THESECTIONNAME}

First Apple Store and younger Steve Jobs

Review: pointer, reference in c++

A Reference Guide
Last updated Jan 1, 2004.from: http://www.informit.com/guides/content.aspx?g=cplusplus&seqNum=166

Unlike most other programming languages, C++ offers an unusual diversity of argument passing mechanisms: pass by value, pass by address, and pass by reference. Additional non-standard argument-passing mechanisms are also supported by certain compilers, such as passing arguments on a register. Today I will explain the semantics of the three standard argument passing mechanisms, and focus on reference variables.

A bit of History
Most high level programming languages offer only a single argument passing mechanism. In Pascal and Ada, for example, arguments are passed by reference and that's it. In Java, objects are passed by reference, whereas fundamental types such as int and boolean are passed by value.

The crucial point, however, is that programmers cannot intervene or control the actual argument passing mechanism that the language applies. C is different in this regard. Built on the foundations of BCPL and B, which were really nothing more than high-level assembly languages, it offered two argument passing mechanisms: pass-by-value and pass by address. Oddly enough, it didn't offer the more common notion of pass by reference.

Pass by Value
Pass by Value is the default argument passing mechanism of both C and C++. When a caller passes by value an argument to a function (known as the callee), the latter gets a copy of the original argument. This copy remains in scope until the function returns and is destroyed immediately afterwards. Consequently, a function that takes value-arguments cannot change them, because the changes will apply only to local copies, not the actual caller's variables. For example:

void negate(int n) //buggy version
{
n=-n;//affects a local copy of n
}
void func()
{
int m=10;
negate(m);//doesn't change the value of m
std::cout<<m<<std::endl; //diplay: 10
}
When negate() is called, C++ creates a fresh copy of m on its stack. negate() then modifies this private copy, which is destroyed immediately when it returns. The original variable m remains intact, though. Consequently, the cout expression displays 10 rather than -10. If you want the callee to modify its arguments, you must override the default passing mechanism.

Pass by Address
In C, the only way to achieve this is by passing the argument's address to the callee. This passing mechanism is traditionally called pass by address.

In the literature, this often called pass by reference too, although it's is a misnomer -- C++ uses this term to denote a radically different passing mechanism. For example,

void negate(int * pn)
{
*n=-*n;
Similarly, the caller must also be adjusted:

void func()
{
int m=10;
negate(&m);//pass m's address<
std::cout<<m<<std::endl; //display: -10
}
Pass by Reference
This is all well and good. The problem with this technique is that it's tedious and error-prone. My impression is statistically, most C/C++ function calls don't use pass by value so forcing programmers to override the default passing mechanism using the &, * and -> operators is an example of a bad language design choice. C++ creators were aware of this. They introduced a new type of argument passing, namely pass by reference. The addition of reference variables and arguments to C++ was only a means of fixing an historical accident made in C about a decade earlier rather than a genuine innovation. However, the introduction of references did affect fundamental programming idioms in C++.

Most textbooks will tell you that a reference is "an alias for an existing object." For example,

int m=0;
int &ref=m;
The reference ref serves as an alias for the variable m. Thus, any change applied to m is reflected in ref and vice versa:

++m;
std::cout<<ref<<std::endl;// output 1
++ref; //increment m
std::cout<<m<<std::endl;// output 2
In other words, ref and m behave as distinct names of the same object. In fact, you may define an infinite number of references to the same object:

int & ref2=ref;
int & ref3=m;
//..and so on
Here ref2 and ref3 are aliases of m, too. Notice that there's no such thing as a "reference to a reference;" the variable ref2 is an alias of m, not ref.

Usage
In most cases, references are used as a means of passing arguments to a function by reference. The nice thing about references is that they function as pointers from a compiler's point of view, although syntactically they behave like ordinary variables. They enable a callee to alter its arguments without forcing programmers to use the unwieldy *, & and -> notation:

void negate(int & n)
{
>n=-n;//modifies caller's argument
}
void func()
{
int m=10;
negate(m);//pass by reference
std::cout<<m<<std::endl; //diplay: -10
}
Advantages of Pass by Reference
Passing by reference combines the benefits of passing by address and passing by value. It's efficient, just like passing by address because the callee doesn't get a copy of the original value but rather an alias thereof (under the hood, all compilers substitute reference arguments with ordinary pointers). In addition, it offers a more intuitive syntax and requires less keystrokes from the programmer. Finally, references are usually safer than ordinary pointers because they are always bound to a valid object -- C++ doesn't have null references so you don't need to check whether a reference argument is null before examining its value or assigning to it.

Passing objects by reference is usually more efficient than passing them by value because no large chunks of memory are being copied and constructor and destructor calls are performed in this case. However, this argument passing mechanism enables a function to modify its argument even if it's not supposed to. To avert this, declare all read-only parameters as const and pass them by reference. This way, the callee will not be able to modify them:

void display(const Shape & s)
{
s.draw();
}
Summary
The introduction of references to C++ initially caused a bit of confusion, especially among ex-C programmers who weren't sure which passing mechanism to use when (and in those days, virtually all C++ programmers were former C programmers). Even illustrious gurus offered to use the following dichotomy: when a function modifies its arguments, pass them by address and when it doesn't, pass them as references to const.

Today, using bare pointers is a thing of the past. In most cases, C++ offers superior alternatives that are both safer and cleaner. Similarly, when you decide how to pass arguments to a function, use references by default (except when you truly need to pass them by value) and avoid passing by address, unless there's a compelling reason to do so. If the function in question shouldn't modify its arguments, they should be declared const and passed by reference; the lack of the const qualifier indicates that the function is allowed to modify an argument. When should you pass arguments by address? Only when the function deals with real pointers. For instance, a function that allocates raw storage, or when a null pointer is a valid option. Otherwise, use references.

My photo
London, United Kingdom
twitter.com/zhengxin

Facebook & Twitter