Tuesday, December 31, 2013

rename window title in tmux

ctrl-b , // to rename a window title in tmux

Note: use ctrl-h to delete characters.

pfSenese - Multiple IP Addresses on one interface

Firewall > Virtual IPs > Add:

Type: IP alias
CIDR: /29

Saturday, December 21, 2013

Thursday, December 19, 2013

mysql error ./mysql/host.frm

131219 22:51:39 [ERROR] /usr/local/libexec/mysqld: Can't find file: './mysql/host.frm' (errno: 13)
131219 22:51:39 [ERROR] Fatal error: Can't open and lock privilege tables: Can't find file: './mysql/host.frm' (errno: 13)
131219 22:51:39 mysqld_safe mysqld from pid file /usr/local/mysql/myhostname.local.pid ended

root@myhostname [/usr/local/mysql] # chown -R mysql:mysql /usr/local/mysql
root@myhostname [/usr/local/mysql] # find /usr/local/mysql -type d -exec chmod 700 {} \;
root@myhostname [/usr/local/mysql] # find /usr/local/mysql -type f -exec chmod 660 {} \;

Wednesday, December 18, 2013

get the svn unversioned filename

svn st | grep fr.php | awk -F ' ' '{print $2}' | xargs -I {} svn add {}

Note: use a space as the separator.

Saturday, December 7, 2013

enable open relay on sendmail on FreeBSD

# vim /etc/mail/access
Connect:192.168.0 RELAY

# cd /etc/mail ; make

This will allow all clients with an IP address of 192.168.0.xxx to relay.

Thursday, November 28, 2013

Changing Domain Name on your PrestaShop install

If you are moving PrestaShop to a different domain, or switching from server pathways to your domain name, then you must update PrestaShop with the new domain name. This article explains what changes need to carried out.

Log into cPanel, then go to "PHPMyAdmin" and log into your PrestaShop database. Go to the table "ps_configuration" and locate the records for PS_SHOP_DOMAIN and PS_SHOP_DOMAIN_SSL. Change these to the new domain name. Check the configuration table for any other entries that contain the old domain name and change accordingly.

SELECT * FROM ps_configuration WHERE name LIKE '%domain%'

Go to Admin Page
Go to Admin page > Advanced Parameters > Multistore > Canada > Actions > Edit:

Domain: ca.webstore.local
Domain SSL: ca.webstore.local
Physical URL: /
Virtual URL: store/

Repeat the same steps with USA store.

Via FTP or the file manager in cPanel, modify the PHP file /config/settings.inc.php. Look for the entry for PS_BASE_URI__ and modify as necessary. For a shop located in the root, it should read:

define('__PS_BASE_URI__', '/');

Delete (or rename) the .htaccess file on your site.

In our PrestaShop admin, you now need to re-generate the SEO URLs with the new domain name. Log into your PS admin, then go to "tools->generate->generate .htaccess".

If your site has a full SSL Certificate, then you can also enable this via your PS admin under "Preferences page -> Enable SSL: Yes".

Please note that PrestaShop won't work with our Shared SSL as the SEO URLs rewrite rules don't work with the server paths. For PS shops, you either need to have a Dedicated IP & your own Full SSL Certificate or you need to disable SSL.


How to reset the PrestaShop admin password

Log into your site's cPanel and go to "File Manager"
Open /config/settings.php and copy the _COOKIE_KEY_ value
In the same file, check the database name in use for your PS install. The name will show as the value of "_DB_NAME_"

In your site's cPanel, go to PHPMyAdmin and open the database for your PrestaShop install
Look for a table called "employee" or if you are using prefixes, "ps_employee"
Check what email address is being used for your login in this table


1. Still in the database, go to "SQL" at the top and run the following query, where you replace the $VAR with the correct information

UPDATE employee SET passwd = md5(concat('$COOKIE_KEY', '$PASSWORD'))
WHERE email = "youremailaddress";

2. If your PrestaShop install uses table prefixes such as "ps_", amend the command to include the prefix:

UPDATE ps_employee SET passwd = md5(concat('$COOKIE_KEY', '$PASSWORD'))
WHERE email = "youremailaddress";

Wednesday, November 27, 2013


In this article Serial Port buffering is explained. How to receive the serial port data without any loss if incoming data stream flow into seperate triggers is realized using c#.

Serial data flow through RS-232/RS-485/RS-422 has nothing to do with ‘packets’. It’s just a stream of bytes in and out. There is no guarantee that data arrives together. Data may come seperate triggers

Communication using Serial Port often used on monitoring the incoming data coming from electronic device that is designed on the bench, Commercial Off The Shelf device that we purchase for the use of as a part of our project, or electronic test instrument communication interface.

Since the bytes may come to computers Serial Port Communication Hardware(Serial Port of the Computer) in at any time, buffering the incoming data is important for not loosing any byte. For example, you may send a command out to your device, and the response back to the PC could trigger a single DataReceived event with all the 15 bytes of response data in the receive buffer. Or more likely, it could be any number of separate triggers of the DataReceived (up to the number of bytes received), like 4 triggers, first with 2 bytes, then 15 bytes, then 1 byte, then 12 bytes.

In the above case, someone do not know when will the complete response is completed. At this point buffering the data plays an important role on not loosing the incoming data. This is known as Serial Port Buffering.
Istead of looking a complete response in a single DataReceived Event to be finished by the sender one may follow the following rule to catch the data

1. buffer the incoming data
2. then scan your buffer to find complete data
3. remove the used data from the buffer

public void serialport_DataReceived(object sender, SerialDataReceivedEventArgs e)
// Use either the binary OR the string technique (but not both)
// Buffer and process binary data
while (com.BytesToRead > 0)

// Buffer string data
sBuffer += com.ReadExisting();

private void ProcessBuffer(string sBuffer)
// Look in the string for useful information
// then remove the useful data from the buffer

private void ProcessBuffer(List<byte> bBuffer)

// Look in the byte array for useful information
// then remove the useful data from the buffer
The above code samples catches all the data coming out of the device.

To make clear the buffering, follow the example case below:

Let us assume that we have connected the serial port of the PC to the external harware to communicate.We send a command byte [] cmd = new byte[]{command CRC} and expect a response as byte[]{messageLength b1 b2 b3 b4 b5 b6 b7 b8 b9 CRC}(here a messageLength is 11). And assume also that the response arrives to the PCs serial port into 5 seperate triggers as ;

fisrt trigger:messageLength b1 b2
second trigger:b3 b4
third trigger:b5 b6
fourth trigger:b7 b8
fifth trigger:b9 CRC

Here are the stpes to be followed to communicate the serial port device
1.Send the command message to the serial port device, serialport.send(cmd)
2.wait for the response using following code

public void seriport_DataAvailable(object sender, EventArgs e)
while (((SerialPort)sender).BytesToRead > 0)
serialPortReceivedData = new byte[((SerialPort)sender).BytesToRead];
((SerialPort)sender).Read(serialPortReceivedData, 0, serialPortReceivedData.Length);
if (bBuffer[0] == bBuffer.Count)
//send the response to the listeners


Saturday, November 23, 2013

send string key to a textbox in WPF

TextCompositionManager.StartComposition(new TextComposition(InputManager.Current, mybox, "Hello World"));

send keystroke in WPF


  new KeyEventArgs(Keyboard.PrimaryDevice, Keyboard.PrimaryDevice.ActiveSource, 0, Key.Down)
    RoutedEvent = Keyboard.KeyDownEvent

Friday, November 22, 2013

To get or set the position of a textbox or a button in WPF

To get the position of a textbox or a button

Point p2 = mybox.TransformToAncestor(Application.Current.MainWindow).Transform(new Point(0, 0))

Debug.WriteLine("here: " + p2.X + ", " + p2.Y);

To set the position of a canvas:
Canvas c = new Canvas();
c.Margin = new Thickness(X, Y, 0, 0);

To set the position of a button within a canvas:
Button b = new Button();
b.Content = "asdf";
b.Width = 50;
b.Height = 22;
b.Click += new RoutedEventHandler(b_Click);

Canvas.SetLeft(b, 20);
Canvas.SetTop(b, 40);

private void b_Click(object sender, RoutedEventArgs e) {

Thursday, November 21, 2013

Get Absolute Position of element within the window in wpf

You have to specify window you clicked in Mouse.GetPosition(IInputElement relativeTo) Following code works well for me
protected override void OnMouseDown(MouseButtonEventArgs e)
        Point p = e.GetPosition(this);
I suspect that you need to refer to the window not from it own class but from other point of the application. In this case Application.Current.MainWindow will help you.


Wednesday, November 20, 2013

Dynamically Loading XAML in WPF

Dynamically Loading XAML in WPF

Loading XAML at run time is really simple. I wrote a small sample to load the XAML at run time and than attach the event handler with the XAML object. I created following XAML page and copied it to the debug folder.
        <Button Margin="0,0,9,38" Name="button1" Height="82" HorizontalAlignment="Right" VerticalAlignment="Bottom" Width="132">Button</Button>
and here is the C# code
public partial class Window1 : Window
        public Window1()

        Button ButtoninXAML;
        public void LoadXAMLMethod()
                StreamReader mysr = new StreamReader("Page1.xaml");
                DependencyObject rootObject = XamlReader.Load(mysr.BaseStream) as DependencyObject;
                ButtoninXAML = LogicalTreeHelper.FindLogicalNode(rootObject, "button1") as Button ; 
                ButtoninXAML.Click += new RoutedEventHandler(Button_Click); 
                this.Content = rootObject;
            catch (FileNotFoundException ex)
        public void Button_Click(object sender, RoutedEventArgs e)
            MessageBox.Show("Hi WPF");  
do not forget to add following namespaces.

using System.IO;
using System.Windows.Markup;


Tuesday, November 5, 2013

C# cannot locate resource imagesource

C# cannot locate resource imagesource




Determine the mime type of a file based on the file header signatures not the extension

Most image file formats have unique bytes at the start. The unix file command looks at the start of the file to see what type of data it contains.


A comprehensive site of file formats is available at:

If you're using .NET Framework 4.5 or above, there is a now a MimeMapping.GetMimeMapping(filename) method that will return a string with the correct Mime mapping for the passed filename.

Documentation is at http://msdn.microsoft.com/en-us/library/system.web.mimemapping.getmimemapping

Windows DLL Urlmon.dll is capable of determining the MIME type of a given data stored in memory, considering the first 256 bytes of the byte array, where such data is stored.


Monday, November 4, 2013


Refers to client/server architectures in which the user interface runs on the client and the database is stored on the server. The actual application logic can run on either the client or the server. A newer client/server architecture, called a three-tier architecture introduces a middle tier for the application logic.



A special type of client/server architecture consisting of three well-defined and separate processes, each running on a different platform:

1. The user interface, which runs on the user's computer (the client).
2. The functional modules that actually process data. This middle tier runs on a server and is often called the application server.
3. A database management system (DBMS) that stores the data required by the middle tier. This tier runs on a second server called the database server.

The three-tier design has many advantages over traditional two-tier or single-tier designs, the chief ones being:

  • The added modularity makes it easier to modify or replace one tier without affecting the other tiers.
  • Separating the application functions from the database functions makes it easier to implement load balancing.
  • Refers to client/server architectures in which the user interface runs on the client and the database is stored on the server. The actual application logic can run on either the client or the server. A newer client/server architecture, called a three-tier architecture introduces a middle tier for the application logic.


Monday, October 28, 2013

PHP array to xml

#echo strtotime('2013-10-27 19:30:00');

$arr = array();

$arr['news'] = array(
array('nid' => 1, 'title' => 'test'),
array('nid' => 2, 'title' => 'test'),

$arr['news2'] = array(
array('nid' => 3, 'title' => 'test'),
array('nid' => 4, 'title' => 'test'),

$xml = new array2xml('root');
$xml->createNode( $arr );
echo $xml;
catch (Exception $e)
echo $e->getMessage();

* Array 2 XML class
* Convert an array or multi-dimentional array to XML
* @author Kevin Waterson
* @copyright 2009 PHPRO.ORG
class array2xml extends DomDocument

public $nodeName;

private $xpath;

private $root;

private $node_name;

* Constructor, duh
* Set up the DOM environment
* @param string $root The name of the root node
* @param string $nod_name The name numeric keys are called
public function __construct($root='root', $node_name='node')

/*** set the encoding ***/
$this->encoding = "utf-8";

/*** format the output ***/
$this->formatOutput = true;

/*** set the node names ***/
$this->node_name = $node_name;

/*** create the root element ***/
$this->root = $this->appendChild($this->createElement( $root ));

$this->xpath = new DomXPath($this);

* creates the XML representation of the array
* @access public
* @param array $arr The array to convert
* @aparam string $node The name given to child nodes when recursing
public function createNode( $arr, $node = null)
if (is_null($node))
$node = $this->root;
foreach($arr as $element => $value)
$element = is_numeric( $element ) ? $this->node_name : $element;

$child = $this->createElement($element, (is_array($value) ? null : $value));

if (is_array($value))
self::createNode($value, $child);
* Return the generated XML as a string
* @access public
* @return string
public function __toString()
return $this->saveXML();

* array2xml::query() - perform an XPath query on the XML representation of the array
* @param str $query - query to perform
* @return mixed
public function query($query)
return $this->xpath->evaluate($query);

} // end of class

Wednesday, October 23, 2013

How to find the mysql data directory from command line

mysql> SHOW variables WHERE variable_name LIKE '%dir%'

Sunday, October 20, 2013

pep talk 精神喊話

pep talk 精神喊話

spam control image code

A CAPTCHA is a challenge-response test most often placed within web forms to determine whether the user is human. The purpose of CAPTCHA is to block form submissions by spambots, which are automated scripts that post spam content everywhere they can. The CAPTCHA module provides this feature to virtually any user facing web form on a Drupal site.


Tuesday, October 15, 2013

create rounded corners with CSS

The CSS3 border-radius property allows web developers to easily utilise rounder corners in their design elements, without the need for corner images or the use of multiple div tags, and is perhaps one of the most talked about aspects of CSS3.
Since first being announced in 2005 the boder-radius property has come to enjoy widespread browser support (although with some discrepancies) and, with relative ease of use, web developers have been quick to make the most of this emerging technology.
Here’s a basic example:
This box should have a rounded corners for Firefox, Safari/Chrome, Opera and IE9.
The code for this example is, in theory, quite simple:
#example1 {
border-radius: 15px;
However, for the moment, you’ll also need to use the -moz- prefix to support Firefox (see the browser support section of this article for further details):
#example1 {
-moz-border-radius: 15px;
border-radius: 15px;

How it Works

Rounder corners can be created independently using the four individual border-*-radius properties (border-bottom-left-radius, border-top-left-radius, etc.) or for all four corners simultaneously using the border-radius shorthand property.
We will firstly deal with the syntax for the individual border-*-radius properties before looking at how the border-radius shorthand property works.

border-bottom-left-radius, border-bottom-right-radius, border-top-left-radius, border-top-right-radius

The border-*-radius properties can each accept either one or two values, expressed as a length or a percentage (percentages refer to the corresponding dimensions of the border box).
The Syntax:
border-*-*-radius:  | <%> ] [  | <%> ]?
border-top-left-radius: 10px 5px;
border-bottom-right-radius: 10% 5%;
border-top-right-radius: 10px;
Where two values are supplied these are used to define, in order, the horizontal and vertical radii of a quarter ellipse, which in turn determines the curvature of the corner of the outer border edge.
Where only one value is supplied, this is used to define both the horizontal and vertical radii equally.
The following diagram gives a few examples of how corners might appear given differing radii:
If either value is zero, the corner will be square, not round.


The border-radius shorthand property can be used to define all four corners simultaneously. The property accepts either one or two sets of values, each consisting of one to four lengths or percentages.
The Syntax:
 |  ]{1,4} [ / [  |  ]{1,4} ]?
border-radius: 5px 10px 5px 10px / 10px 5px 10px 5px;
border-radius: 5px;
border-radius: 5px 10px / 10px;
The first set of (1-4) values define the horizontal radii for all four corners. An optional second set of values, preceded by a ‘/’, define the vertical radii for all four corners. If only one set of values are supplied, these are used to determine both the vertical and horizontal equally.
For each set of values the following applies:
If all four values are supplied, these represent the top-left, top-right, bottom-right and bottom-left radii respectively. If bottom-left is omitted it is the same as top-right, if bottom-right is omitted it is the same as top-left, and if only one value is supplied it is used to set all four radii equally.

Browser Support

At present Opera (version 10.5 onward), Safari (version 5 onward) and Chrome (version 5 onward) all support the individual border-*-radius properties and the border-radius shorthand property as natively defined in the current W3C Specification (although there are still outstanding bugs on issues such as border style transitions, using percentages for lengths, etc.).
Mozilla Firefox (version 1.0 onward) supports border-radius with the -moz- prefix, although there are some discrepancies between the Mozilla implementation and the current W3C specification (see below).
Update:Recent Firefox nightly versions support border-radius without the -moz- prefix.
Safari and Chrome (and other webkit based browsers) have supported border-radius with the -webkit- prefix since version 3 (no longer needed from version 5 onward), although again with some discrepancies from the current specification (see this article for further details of how older versions of Webkit handle border-radius).
Even Microsoft have promised, and demonstrated in their recent preview release, support for border-radius from Internet Explorer 9 onward (without prefix).

The -moz- prefix

Mozilla’s Firefox browser has supported the border-radius property, with the -moz- prefix, since version 1.0. However, it is only since version 3.5 that the browser has allowed elliptical corners, i.e. accepting two values per corner to determine the horizontal and verical radii independently. Prior to version 3.5, the browser only accepted one value per corner, resulting in corners with equal horizontal and vertical radii.
The syntax, from Firefox 3.5 onwards, for the main part follows the current W3C specification, as described throughout this article, prefixed by -moz-. The only major difference is in the naming of the individual border-*-radius properties, with the -moz- prefixed properties following a slightly different naming convention as follows:
W3C SpecificationMozilla Implementation
The Mozilla implementation also behaves slightly differently from the specification when percentages are supplied. You can read more on the Mozilla Developer Center here.

Cross Browser Examples

Here’s a few basic examples that should work in current versions of Firefox, Safari/Chrome, Opera and even IE9:

#Example_A {
height: 65px;
-moz-border-radius-bottomright: 50px;
border-bottom-right-radius: 50px;
#Example_B {
height: 65px;
-moz-border-radius-bottomright: 50px 25px;
border-bottom-right-radius: 50px 25px;
#Example_C {
height: 65px;
-moz-border-radius-bottomright: 25px 50px;
border-bottom-right-radius: 25px 50px;
#Example_D {
height: 5em;
width: 12em;
-moz-border-radius: 1em 4em 1em 4em;
border-radius: 1em 4em 1em 4em;
#Example_E {
height: 65px;
-moz-border-radius: 25px 10px / 10px 25px;
border-radius: 25px 10px / 10px 25px;
#Example_F {
height: 70px;
width: 70px;
-moz-border-radius: 35px;
border-radius: 35px;

Additional Notes & Further Reading

The W3C Backgrounds and Borders Specification goes into further detail on how the corner is shaped (especially in circumstances where two adjoining border have different widths), the effect of border-radius on background images, color and style transitions, what happens when curves overlap and the effect of border-radius on tables.
This is best explained in the following sections of the specification:


Friday, October 11, 2013

What Are False Positives and False Negatives?

While many of today's medical tests are accurate, false negative or positives do occur. What causes these erroneous results?

A false negative is a test result that indicates a person does not have a disease or condition when the person actually does have it, according to the National Institute of Health (NIH). False negative test results can occur in many different medical tests, from tests for pregnancy , tuberculosis or Lyme disease to tests for the presence of drugs or alcohol in the body.

Correspondingly, a false-positive test result indicates that a person has a specific disease or condition when the person actually does not have it. An example of a false positive is when a particular test designed to detect melanoma, a type of skin cancer , tests positive for the disease, even though the person does not have cancer.


Wednesday, October 9, 2013

Now with css3 you could try to use calc() to calculate the height

Now with css3 you could try to use calc() to calculate the height

height: calc(100% - 111px);

Monday, October 7, 2013



































Omit Zeros from the Average Function/Formula

Omit Zeros from the Average Function/Formula

Back to Excel Formulas . Got any Excel Questions? Free Excel Help
Excel Average Without Zeros
Excel has a built in formula/function that makes averaging a range of cells easy. If we assume your numbers are in A1:A100 you would simply use the Average formula like shown below;
There is however, one draw-back with this. That is, it includes cells that contain 0 (zeros). This can give you unexpected results. While the sum of values is not effected, the count of them is. Average is the sum of numbers divided by the count of numbers. So how do we omit zeros from our average?
This method is the most generic in that it ignores blank cells and will include negative numbers.
By far the most efficient method is to use the SUM formula and COUNTIF formula as shown below;
This method will not work should you have negative numbers unless you change ">0" to "<>0" The drawback is it will then count blank cells. Where as the one below wont.
=SUM(A1:A100) / (COUNT(A1:A100) - COUNTIF(A1:A100,0))
=SUMIF(A1:A100,">0")/COUNTIF(A1:A100,">0") Will also exclude negatives unless you use "<>0". However, it will then count blank cells.
If you do have negative numbers, and no blank cells, use;
The other method is via the DAVERAGE function. This function is part of the Database functions and all are extremely useful when/if you need specify multiple criteria. The DAVERAGE , in the case of numbers being in A2:A100 (A1 should be a heading) we could use the DAVERAGE like below;
Where "1" represents the relative column position to average in the range A1:A100
B1 has an exact copy of your heading in A1
B2 houses the expression >0
Array Average
This method is the least efficient. By creating an array formula we can use the Average formula as shown below to omit zeros;
=AVERAGE(IF($A$1:$A$100 <>0,$A$1:$A$100))
As these are array formulas they MUST be entered via Ctrl+Shift+Enter.


Sunday, October 6, 2013

Redo Backup and Recovery

Redo Backup and Recovery is so simple that anyone can use it. It is the easiest, most complete disaster recovery solution available. It allows bare-metal restore. Bare metal restore is not only the best solution for hardware failure, it is also the ultimate antivirus: Even if your hard drive melts or gets completely erased by a virus, you can have a completely-functional system back up and running in as little as 10 minutes.


Thursday, October 3, 2013

第34章 要教會孩子學會堅持,不輕易認輸






















Tuesday, October 1, 2013
















Sunday, September 29, 2013


Most folks are as happy as they make up their minds to be.
  • 壞習慣一:批判和衝突
  • 壞習慣二:一直想著還有多少難題要解決
不知道你是否聽過 Marcus Luttrell 的故事,他是美國特種部隊 —— 海豹突擊隊的隊長,曾經深入阿富汗偏遠地區擒獲塔利班重要幹部,他分享自己訓練底下隊員的方式:「學員必須背負重物跑過實彈射擊的場合,還得游過數英里,而在潛水訓練中,我們會把水肺的管子打結,他們必須在緊急的狀況下按照步驟解救自己。」
Candidates who focused on how many days of excruciating training they had left inevitably dropped out. As one of his instructors put it, “The body can take damn near anything. It’s the mind that needs training.”
這之中我發現一件事,所有無法通過訓練的學員,都有個共同點,就是他們會一直去算這個訓練過了多少天,還有多少天,導致意志力越來越薄弱,最後放棄。「其實這些訓練都在身體可以承受的範圍內,最需要被鍛鍊的是心智。」 Marcus 說。
  • 壞習慣三:不斷和別人比較
「人比人,氣死人。」 這個道理你應該就很能體會了,之前〈看朋友一路走向人生勝利組,你就不開心?研究:FB 讓我們善妒、愛比較,感覺空虛感覺冷〉一文中,有談到 FB 會讓人善妒且沮喪,一直看到朋友們精采的照片、生活,實在很容易產生自我質疑:怎麼朋友都是溫拿(Winner),比起來我好像魯蛇(Loser) 一樣。
  • 壞習慣四:花費過多時間在會議上
Learn Vest 和 Inc.的執行長 Alexa Von Tobel 曾發表一篇關於會議時間控制的文章,他說:
“Most people think in terms of 30-minute chunks, but I’ve found that when I free up more time, I waste it. Of course, some tasks do require more time so if a meeting needs to take 30 minutes, it will take 30 minutes. But otherwise, I try not to schedule meetings to last that long.”
「大部分人會把開會時間用半小時為單位來做區隔,但就我長久觀察下來,半小時對於許多會議來說都有些太長了,不知不覺中會浪費很多寶貴的時間。當然比較重要的、需要詳細討論的事情會需要半小時以上的時間,但大多數比較小的會議,我建議用 15 分鐘解決,否則常常一天就這樣過了。」
  • 壞習慣五:完美主義者
完美主義是焦慮的根源,它通常來自於小時候所建立起的防禦機制,為了不讓別人批評自己所形成,Shelley Prevost 最近在 Inc. 的一篇文章中指出,完美主義者無謂的堅持經常會讓他們產生焦慮的毛病。
  • 壞習慣六:感嘆自己的不如意
不要把自己的不開心一直放大,你該放大的是視野和格局,我們都讀過歷史,回想人類在這個世界上所經歷過的一切,戰爭、瘟疫、飢荒…… 都是過往的人們所承受過的苦難,而你現在能坐在辦公室吹冷氣、回家有冰箱用、還能洗個熱水澡,其實都是很幸運的事。
(資料來源:Inc.;封面圖片:mugley , CC Licensed)


Excel Fill Down Command hotkey

If you need to input the same data - text or numbers - into a number of adjacent cells in a column, the Fill Down command can quickly do this for you by just using the keyboard.

  • select a cell
  • Press and hold down the Shift key on the keyboard
  • Press and hold down the Down Arrow key on the keyboard to extend the cell highlight from cell D1 to D7 (or press Shift, Ctrl-home to the bottom of the content).
  • Release both keys.
  • press Ctrl-d


Thursday, September 26, 2013

Optional Parameters in C#

A parameter is optional if it specifies a default value in its declaration.

The default value of an optional parameter must be specified by a constant expression, or a parameterless constructor of a value type. Optional parameters cannot be marked with ref or out.

default value examples:

// use default() keyword to obtain the default value of any type.
public void Problem(Guid optional = default(Guid)) {


// a parameterless constructor of a value type.
public void Problem(Guid optional = new Guid()) {

Note: new Guid(), which is equivalent to default(Guid).

Note: the new Guid() value is only applicable when:

  • You're really calling the parameterless constructor
  • Foo is a value type

Mandatory parameters must occur before optional parameters in both the method declaration and the method call (the exception is with params arguments, which still always come last).

C# 5.0 in a Nutshell: The Definitive Reference