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
Address: 1.2.3.4
CIDR: /29

Saturday, December 21, 2013

Thursday, December 19, 2013

mysql error ./mysql/host.frm

Problem:
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

Solution:
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.

UPDATING YOUR DATABASE
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.

UPDATING YOUR CONFIG SETTINGS
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__', '/');

UPDATING SEO-FRIENDLY URLS
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".

ENABLING SSL
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.

Reference:
https://support.terranetwork.net/web/knowledgebase/125/Changing-Domain-Name-on-your-PrestaShop-install.html

How to reset the PrestaShop admin password

GET YOUR _COOKIE_KEY_
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_"

CHECK YOUR DATABASE
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

RESET PASSWORD

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

SERIAL PORT BUFFERING C#.NET

SERIAL PORT BUFFERING C#.NET
ШАБЛОНЫ САЙТОВ ОНЛАЙН-МАГАЗИНЫ
ФАЙЛОВЫЕ МЕНЕДЖЕРЫ JOOMLA
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)
bBuffer.Add((byte)com.ReadByte());
ProcessBuffer(bBuffer);

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

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);
bBuffer.AddRange(serialPortReceivedData);
if (bBuffer[0] == bBuffer.Count)
{
//send the response to the listeners
bBuffer.Clear();
break;
}
}
}

http://www.miltest.com/articles/application-notes/59-serial-port-buffering-csharp.html

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

lb.Focus();

InputManager.Current.ProcessInput(
  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);
c.Children.Add(b);

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

private void b_Click(object sender, RoutedEventArgs e) {
Debug.WriteLine("good");
}

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)
    {
        base.OnMouseDown(e);
        Point p = e.GetPosition(this);
        MessageBox.Show(p.ToString());
    }
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.

Reference:
http://stackoverflow.com/questions/386731/get-absolute-position-of-element-within-the-window-in-wpf

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.
<Page 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Page1">
    <Grid>
        <Button Margin="0,0,9,38" Name="button1" Height="82" HorizontalAlignment="Right" VerticalAlignment="Bottom" Width="132">Button</Button>
    </Grid>
</Page>
and here is the C# code
public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();
            LoadXAMLMethod(); 
        }

        Button ButtoninXAML;
        public void LoadXAMLMethod()
        {
            try
            {
                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)
            {
                MessageBox.Show(ex.Message.ToString());    
            }
        }
        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;

Reference:
http://blogs.msdn.com/b/ashish/archive/2007/08/14/dynamically-loading-xaml.aspx

Tuesday, November 5, 2013

C# cannot locate resource imagesource

C# cannot locate resource imagesource

pack://siteoforigin:,,,/Subfolder/test.png

pack://siteoforigin:,,,/SomeAssembly;component/ResourceFile.xaml

http://msdn.microsoft.com/en-us/library/aa970069.aspx
http://stackoverflow.com/questions/12982889/cannot-locate-resource

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.

http://en.wikipedia.org/wiki/List_of_file_signatures
http://magicdb.org/

A comprehensive site of file formats is available at:
http://www.wotsit.org

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.

http://stackoverflow.com/questions/58510/using-net-how-can-you-find-the-mime-type-of-a-file-based-on-the-file-signature?rq=1
http://stackoverflow.com/questions/15300567/alternative-to-findmimefromdata-method-in-urlmon-dll-one-which-has-more-mime-typ/15595571#15595571
http://stackoverflow.com/questions/52739/is-there-a-way-to-infer-what-image-format-a-file-is-without-reading-the-entire

Monday, November 4, 2013

two-tier

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.

http://www.webopedia.com/TERM/T/two_tier.html

three-tier

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.


http://www.webopedia.com/TERM/T/three_tier.html

Monday, October 28, 2013

PHP array to xml

<?php
#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'),
);

try
{
$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')
{
parent::__construct();

/*** 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));
$node->appendChild($child);

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.

https://drupal.org/project/captcha

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:  | <%> ] [  | <%> ]?
Examples:
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:
border-radius-diagram-1
If either value is zero, the corner will be square, not round.

border-radius

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} ]?
Examples:
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
border-radius-moz-border-radius
border-top-left-radius-moz-border-radius-topleft
border-top-right-radius-moz-border-radius-topright
border-bottom-right-radius-moz-border-radius-bottomright
border-bottom-left-radius-moz-border-radius-bottomleft
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:
A
B
C
D
E
F

#Example_A {
height: 65px;
width:160px;
-moz-border-radius-bottomright: 50px;
border-bottom-right-radius: 50px;
}
#Example_B {
height: 65px;
width:160px;
-moz-border-radius-bottomright: 50px 25px;
border-bottom-right-radius: 50px 25px;
}
#Example_C {
height: 65px;
width:160px;
-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;
width:160px;
-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:

Reference:
http://www.css3.info/preview/rounded-border/

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.

http://www.livescience.com/32767-what-are-false-positives-and-false-negatives.html

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

.main{
height: calc(100% - 111px);
}

Monday, October 7, 2013

一個已婚男人的經驗之談

我的婚姻很幸福,我也有把握延續這種幸福。我寫這篇文章的目的,就是希望有更多的人能把握自己的婚姻。就算我說的都是廢話,如果能引起朋友們在婚前對婚姻多一些思考,也算是達到目的了。

今天晚上,得知我最好的朋友離婚了。孩子才1歲,同樣身為父親的我感到難過,離婚對孩子來說影響太大。所以想勸勸還沒結婚的兄弟對待婚姻再慎重一些。本來,我結婚也沒幾年,沒資格以過來人的身份說這些。不過,至少我的婚姻很幸福,我也有把握延續這種幸福。我寫這篇文章的目的,就是希望有更多的人能把握自己的婚姻。就算我說的都是廢話,如果能引起朋友們在婚前對婚姻多一些思考,就達到目的了。

每個人對婚姻的態度都是不同的,隨便找個人湊合過日子的,找個女人幫自己生孩子的,找個過夜不收錢的,這些所謂的「婚姻」就不在討論範圍了,這裡和大家討論的,是高質量的婚姻。

什麼是高質量的婚姻?每個人的理解都不一樣,在我看來,婚姻的狀態有很多種,但是讓人舒服的婚姻,一定都是有愛的。所以,我給還沒結婚的兄弟第一個忠告:如果想擁有幸福的婚姻,一定要相信愛情。

有人說,愛情是有保質期的。我說,有保質期的不叫愛情。那叫激情,激情夾雜的東西太多,性慾、感動、內疚、憧憬,有太多太多的雜質,這樣的情感確實難以持久。何況,激情往往是精心呵護起來的,一旦丟失了精心呵護的動力,褪色太快。

泡妹的時候,激情是最好的工具。然而面臨結婚選擇時,作為男人,一定要理清自己的頭腦,祛除激情的成分。這個思考的過程非常重要,婚姻是沒有回頭路的。別以為大不了還可以離婚。離婚不是解脫,是又一個麻煩的開始。

愛情是雙方面的,先說說男人對女人的。和一個自己不愛的女人過一輩子。絕對是折磨。

如何確定自己愛不愛一個女人,這是非常關鍵的一步。別以為這是廢話,我很肯定的說,很少男人清楚這個問題。男人的生理天性決定了對女人的選擇很大因素是外貌。但是婚姻是反人類天性的。所以當男人選擇了婚姻,就注定要克服自己的生理天性。

男人的生理天性,說白就是希望保質保量的遺傳自己的基因,比如盡可能的和更多女人上床,盡可能的選擇更漂亮,基因更優秀的女人上床。而婚姻,恰恰相反,男人只能選擇一個女人。而且要知道,眼前這個將要嫁給自己的美女,不幾年就會生孩子,眼角會有皺紋,乳房會下垂,乳頭會變的很黑,屁股會變形,小肚子會出來,還會有難看的斑紋。更可怕的是,男人的生理天性決定了男人老和同一個女人上床,是會膩的。所以,沒有愛的婚姻是危險的。因為沒有克服生理慾望的信念。

據我觀察,很多失敗婚姻的元兇就是性!性對男人的誘惑是致命的,不少男人就是因為和女人上了床就順理成章的結婚了。是好是壞全看運氣。壓根不思考有沒有共同語言,遇到問題雙方的溝通方式彼此能否接受,這些關鍵的問題不去想。就因為上了床就結婚。這是很多悲劇的來源。用人性本能來適應反人性本能的婚姻制度。這是非常愚蠢的。更愚蠢的是很多女人以性為工具來對待婚姻。

說到這裡才發現,婚姻實在是個大話題。每個人去領證的時候,都沒想過有一天會離婚。可惜,離婚的人越來越多。一個男人,只有把性慾、感動等因素全拋開,才能真正認識自己對一個女人的感情是不是愛。愛不能解決所有問題,但是能給男人解決問題的動力。沒有動力經營的婚姻,麻煩很多。因為婚姻的問題很多。

千萬別把結婚看成是好事。結婚對男人而言,純粹是責任。有了承擔責任的決心,才敢談婚姻,所以,結婚一定要找一個自己愛的女人,湊合不得。自己餘下的生命全部為之付出的家庭,女主人不是自己真正愛的,太悲劇了。因為婚姻唯一能回報給男人的,僅僅是一隻能牽著自己走向死亡的手。千萬別奢望婚姻回報給自己什麼,任何奢望只會添加雙方的壓力。做好丈夫該做的,自然得到應得的。

選擇結婚對象,我覺得有幾點一定要仔細思考:

1、雙方溝通方式彼此能否接受
這是最重要的一點,不是平時有沒有共同語言,而是有分歧和問題的溝通。說白了,如果男人是個講道理的人,女人也得是個懂道理的人;如果男人是個喜歡用拳頭說話的人,女人也得是個肯挨拳頭的人;女人如果喜歡嘮叨,男人就得聽得慣。總之,兩個人必須得有個拿出統一意見的程序,且雙方都能接受。最好是都樂意接受。其實這一條對於真正相愛的人來講不是問題,真正相愛的兩個人永遠是站在對方立場思考問題的。

夫妻意見的統一,是家庭和睦的基石。

2、兩人結合帶來的壓力是否可控
有情飲水飽,可惜只飽一頓。男人沒結婚,是瀟灑的,一結婚,負擔就來了。兩個人的結合所帶的壓力肯定是巨大的,必須要考慮雙方的承受能力,自己沒有能力負擔,就不要害人害己了。女朋友如果喜歡錢,有錢就娶,沒錢就不要砸鍋賣鐵娶回家了。有些負擔,背上就是一輩子的。對婚姻而言,肯陪自己一起奮鬥的女人,才真正應該珍惜。單單是兩個人一起改善生活的過程,就已經是婚姻寶貴的財富了。別說現在這樣的女人少,不少。老盯著花枝招展想靠嫁人改變命運的年輕女人,就別怪女人現實。自己從未規劃過未來,就別怪女人不肯陪自己一起奮鬥。

性生活得到滿足的男人,才更容易發現女人其他的魅力。而現實的情況是,不少好女人還剩著,男人卻在追逐性的過程中迷失了自己。因色而結合,出了問題湊合,女人色衰之後,沒本事的男人繼續湊合,有本事的換個女人湊合。這樣的風氣還有個很煩的影響,女人越來越在意自己的形象,化妝時間越來越長,衣領越來越低,裙子越來越短。而充電的時間越來越少,獨立意識越來越淡。男人一邊追逐女色,一邊抱怨女人素質越來越低。女人呢?一邊抱怨男人膚淺,一邊不斷迎合膚淺的審美。

3、雙方是否是對方的助力
婚姻不是人生的全部,兩個人攜手一生,相助則利,相阻則損。性格互補也好,志同道合也好,彼此成為對方的助力,真的很重要。如果和一個女人婚前就感覺疲憊,相信我,別接了。家是港灣,是一個讓男人快到家門就會不自覺加快腳步的地方。是一個一回家就會徹底放鬆,卸下所有偽裝的地方。是一個所有笑容都發自真心的地方。

結婚,一定娶一個讓自己感到輕鬆的女人。真的!

說了這麼多,肯定有兄弟說這麼多條件的女人難找。其實真的不難,第一條和第三條,只要女人愛你都不是問題。第二條,只要在和自己同一層次的女人中間找也不是問題。

有朋友問到區分激情和愛情,其實很好區分的,當你不見她時茶飯不思,是激情。老想見到她,想和她一起玩,一起上床,一起做白日夢,是激情。每天短信電話多的沒完,是激情。為了生日節日費盡心思想浪漫的點子,是激情。當你和她在一起時腦子裡不自覺的規劃實實在在的將來,是愛情。當你們爭吵到很凶,火很大時,也不忍心說一句傷害她的話,是愛情。當你們有分歧時,你總是能清楚的知道她是怎麼想的,能理解她的初衷,是愛情。

現在很多人談戀愛很短時間就結婚了,當然,不是說時間短就不好。而是要清楚的知道,婚前的考察對這一生的影響。失敗的家庭是任何成功都彌補不了的。縱然是家產萬貫,頂一頂綠帽子也是沒臉的事。再大的房子,妻離子散的日子也難過。人,一旦離過一次婚,再尋找幸福的難度就更大了。因為,離過婚的人更難相信愛情。更何況離婚對子女的影響,太大太大。人,真正能留在這個世界上的,也就是子女這點血脈而已。為子女營造一個好的成長環境,是父親的責任。

前面說這麼多其實都是說面對婚姻的態度要理性,要慎重。

態度端正以後,技巧也有很多需要注意的地方。明明相愛的兩個人互相傷害的事情太多了。如果犯錯,也要積極想辦法補救爭取。

傷心散伙的也多,而且婚姻生活,男人還有個重要技術要掌握,就是老媽與老婆的關係。

婚後生活瑣碎的事情太多,先說說處理婆媳關係。所有還沒結婚的兄弟一定不要把這不當一回事。一邊是生你養你為你付出所有的母親,一邊是將要相伴你一生的老婆。雙方都有責任要照顧。這個關係弄順了,少很多麻煩。

有人說男人在婆媳之間是雙面膠,夾在中間兩面討好。這是錯的。男人必須是一手拿棒一手拿潤滑油。小事居中調節,原則問題對事不對人,道理絕不能歪,既不能縱容媳婦,也不能慣壞了老媽。堅決不要在老媽面前說媳婦不對,多包涵之類,也不能在媳婦面前說,這都是縱容。把握一個原則,絕不允許媳婦在自己面前說老媽的壞話,有事說事。該怎麼解決怎麼解決,是老媽不對也要和老媽把事情講清楚,同樣的,老媽說自己媳婦的時候也要分清是非。居中討好的後果是兩面不是人,矛盾還越來越深。

總之,絕對的公平是處理婆媳關係的唯一方式,委屈任何一方,都會使矛盾激化。媽也好,老婆也好,底線都給她們畫好。人都是有選擇性的,既然要不到特權,自然會注意彼此相處。一開始可能男人日子不太好過,兩邊都要鬥上幾次。但是慢慢的,家庭秩序就會走上正軌。如果一開始圖省心,哄過去,兩邊脾氣都養大了就夠自己受了。(前面忘了說了,找女人一定要找個聰明的,笨女人大多麻煩,聰明的女人自己會處理,自己只用打打下手,關係就處的很好了。

還有個問題,就是子女,現在的孩子才真叫一個寶貝,一大家人圍著轉,各有各的主意,很多矛盾都是因此而起,在這一點上,男人一定要強硬,從一開始就絕對不能讓步,要給出明確的信號,孩子是自己的。雙方父母肯幫忙,感謝。但是涉及孩子的一切決定,必須是自己拿主意。(這一點背地裡可以多聽老婆的,畢竟,媽媽是最愛孩子的。)這一點申明尤其重要,相當於自己一個人把所有炮火攬了。否則,孩子一點點小感冒家裡可以鬧翻天。(我那今天離婚的朋友就是因為這個)。

婚姻確實是個大話題,一時反而不知道說什麼好了,我是真心想和大家交流一下。因為我自認為自己的婚姻真的是種幸福。我是真心希望有更多的人能愉快的享受婚姻。有人說不吵架不算夫妻,說真的,我和我老婆真還吵不起來架,就像我前面說的,傷彼此的話確實不忍心講出口。何況一旦清楚彼此都是出於愛,又有什麼好吵的?有幾次剛進入狀態,看見彼此裝腔作勢生氣的樣子就都笑了。

戀人時刻只有甜蜜和浪漫,而婚姻則更多是責任和平淡,這個轉化的過程,是需要雙方有充足思想準備的。其實只要兩個人肯一起面對,婚姻生活平淡中的幸福並不輸給熱戀時的浪漫。

願意花時間看這文章的男生女生們,光是這一點就足以說明你們對待婚姻對待愛情的態度是充滿誠意的。有這樣的態度你們一定會收穫屬於你們的幸福。真心的。

http://myshare.url.com.tw/note/587875

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;
=AVERAGE(A1:A100)
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?
SUMPRODUCT & SUM
=SUM(A1:A100)/(SUMPRODUCT((A1:A100<>0)*1))
This method is the most generic in that it ignores blank cells and will include negative numbers.
COUNTIF & SUM
By far the most efficient method is to use the SUM formula and COUNTIF formula as shown below;
=SUM(A1:A100)/COUNTIF(A1:A100,">0")
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;
=SUM(A1:A100)/COUNTIF(A1:A100,"<>0")
DAVERAGE
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;
=DAVERAGE($A$1:$A$100,1,$B$1:$B$2)
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,$A$1:$A$100))
=AVERAGE(IF($A$1:$A$100 <>0,$A$1:$A$100))
As these are array formulas they MUST be entered via Ctrl+Shift+Enter.

http://www.ozgrid.com/Excel/average-without-zero.htm

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.

http://redobackup.org/

Thursday, October 3, 2013

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

俗話說:「天道酬勤。」命運掌握在那些勤勤懇懇地工作的人手中。天賦過人的人,如果沒有毅力和恆心做基礎,他只會成為轉瞬即逝的火花;許多意志堅強、持之以恆而智力平平乃至稍稍遲鈍的人,都會超過那些只有天賦而沒有毅力的人。正如一句西方民諺所云:「走得慢且堅持到底的人,才是真正走得快的人。」

人人都渴望成功,人人都想得到成功的秘訣,然而成功並非唾手可得。我們常常忘記,即使是最簡單最容易的事,如果不能堅持下去,成功的大門絕不會輕易地開啟。那些最能持之以恆、忘我工作的人往往是最成功的。因此,一定要讓孩子充分認識到:除了堅持不懈,成功並沒有其他秘訣!如果暫時面對不利的局面,只要不放棄努力,就不算輸。

阿邁爾參加紐約市的演講比賽,沒能進入決賽,爸爸和媽媽一起去接他回家。

一見面,爸爸就問他:「你是輸了?還是沒有贏?」

阿邁爾不解地說:「這有什麼分別?」

爸爸沒有回答他的問題,只是再次問道:「下星期在史泰登島的另一場比賽,你還打算參加嗎?」

阿邁爾十分堅決地說:「當然要參加!」

爸爸說:「那麼,你今天只是沒有贏,而不是輸了!」

一個輸了的人,如果繼續努力,打算贏回來,那麼他今天的輸,就不是真輸,而是「沒有贏」;相反的,如果他失去了再戰鬥的勇氣,那就是真輸了!

海明威的名著《老人與海》裡面有這樣一句話:「英雄可以被毀滅,但是不能被擊敗。」

尼采說過這樣一句名言:「受苦的人,沒有悲觀的權利。」

英雄的肉體可以被毀滅,但是精神和鬥志不能被擊敗。受苦的人,因為要克服困境,所以不但不能悲觀,而且要比別人更積極!

據說徒步穿過沙漠,唯一可能的辦法,是等待夜晚,以最快的速度走到有蔭庇的地方一站,中途不論多麼疲勞,也不能倒下。否則,第二天烈日昇起,加上沙上炙人的輻射,只有死路一條。

在冰天雪地中歷險的人,也都知道,凡是在中途說「我撐不下去了,讓我躺下來喘口氣」的同伴,必然很快就會死亡,因為當他不再走、不再動,他的體溫迅速降低,跟著就被凍死。

一位著名的西方學者說:「在通往目標的歷程中遭遇挫折並不可怕,可怕的是因挫折而產生的對自己能力的懷疑。」其實,挫折並不能證明什麼,因為我們是人而不是神,我們不可能十全十美。相反,我們能力的大小,只有在經受了各種各樣的考驗之後方能證實。挫折就是這樣一種必須經受的考驗,它可以提醒我們去尋找和發現我們自身的不足之處,然後對它們進行彌補和改善。挫折使我們有了這樣一種機會:讓我們清醒地認識到事情是如何朝著失敗的方向轉變的,以使我們在將來能夠避免因重蹈覆轍而付出更加高昂的代價。

最重要的是,挫折還使我們看清了自己在通往目標的道路上一個必須去加以征服的敵人,這個敵人不是別人,他通常就是我們自己,人類最傑出的成就經常是在戰勝自我的同時被創造出來的,人類最崇高的目標也經常是在徹底戰勝自我的同時到達的。

艱難困苦對生活的強者來說,猶如通向成功之路的層層階梯;而對生活的弱者來說卻是萬丈深淵。生活告訴我們這樣的一個哲理:「在人類的歷史上成就偉大事業的往往不是那些幸福之神的寵兒,卻反而是那些遭遇諸多不幸卻能奮發圖強的苦孩子。」

古往今來有許多這樣的例子。德國大作曲家貝多芬由於貧困沒能上大學,17歲時得了傷寒和天花;這之後,肺病、關節炎、黃熱病、結膜炎又接踵而至;26歲時不幸失去了聽覺,在愛情上他也屢屢不順。在這種境遇下,貝多芬發誓「要扼住命運的咽喉」。在與命運的頑強搏鬥中,他的意志佔了優勢,在樂曲創作事業中,他的生命重新沸騰了。英國詩人勃朗寧夫人15歲就癱瘓在病床,後來靠著精神的力量同病魔頑強搏鬥,39歲時終於從病床上站了起來。她寫的《勃朗寧夫人十四行詩》一書馳名於世界各國。

一個人可能會由於家庭、身體等種種原因而感到失意,但只要他內心深處堅信自己是能夠有所作為、幹一番事業的,這樣,他就會產生戰勝困難、向命運挑戰的巨大勇氣,而他的社會價值,也終會在所從事的事業中實現。18世紀德國詩人歌德,用26年的時間完成了一部不朽名著《浮士德》。作品完成後,他的秘書請他用一兩句話概括作品的主旨,他引用浮士德的話說:「凡是自強不息者,終能得救!」

要讓人孩子懂得,在人生的戰場上,我們不但要有跌倒之後再爬起的毅力,拾起武器再戰的勇氣,而且從被擊敗的一刻,就要開始下一波的奮鬥,甚至不允許自己倒下,不准許自己悲觀。那麼,我們就不是徹底輸,只是暫時地「沒有贏」了!最偉大的成就,常屬於那些在大家都認為不可能的情況下,卻能堅持到底的人。

http://www.nwp.cn/book/352_18057.shtml

Tuesday, October 1, 2013

堅持到底的道路看起來很遙遠,卻是達成目標最近的路

秋風漸涼,突覺時光匆匆,倏忽地的時間偶然會搖醒沉默不改變的心。

今時今日,每個人最關心的還是要如何讓自己在固定的收入外,多存一些錢好規劃未來的日子。而我也不能例外地比從前更加關心自己的未來,也許是更年長了,很多事讓人感受到不確定,於是,想要穩穩地抓住些什麼來讓自我安心。

成長有時真讓人覺得寂寞。原本會談心、固定一段時日會見面的朋友,因為事業忙、或遠在他鄉而變得不太聯絡。從前的夢想,因為現實不得不做妥協…。

最近靜下心來的時候,閱讀了一些書,裡頭有些句子給我很大的啟發。比如說:
「堅持到底的道路看起來很遙遠,卻是達成目標最近的路。」
「不要小看不起眼的事物,有時候反而是新的契機。」
「跨出去不見得有收穫,但不跨出去你永遠不會有機會。」

我一直覺得”堅持到底”是一種很高貴的情操,它真的很難,因為你想要看到的那個目標往往很遠。中途有太多未知,過程艱辛萬苦。而我也覺得,當你因為一些挫折而放棄一件事,那件事不是你能力未及、就是你根本還沒這麼想要它。從我一個人勇闖天涯回國後,我對自己的信心又多了一分。雖然也許許多人都做過這樣的事,但對我而言,真的是跨出去了第一步。過去,也許對自己要求太高,做不到時很打擊自我信心。但是,每建立一次小信心,對自我的觀感又更不同。現在,我也開始學起金融理財的常識。我一直很再意心中的理想不能實現,但前陣子遇上生涯瓶頸,決心出國好好想一想。回來後,我多了很多心得。

「只要從來沒有忘記心中那份夢想,儘管偶而要屈就現實,但不代表就永遠放棄。」心是這樣對著自己說。雖然我常覺得沮喪,但仔細想想,我也許努力還不夠、我花的心還不夠,那我又怎麼會得到我想要的收穫??

在情感上也一樣,一個人真的很在乎妳,他就不會輕易地放棄。「路遙知馬力,日久見人心。」以上的道理套用在我自己身上,突然打開我糾結已久的心。要明白過去的那個人已然離開的事實,時間會証明一切;一個不值得再執著的感情,某天會因為另一個人真心對妳關懷才會恍然明白。那樣的過程很痛苦,但我希望痛的感覺不是因為時間太長而習慣了痛,而是真的要對自己好,也不要讓愛自己的人擔心。讓自己活在愛中才是最大的祝福。

就像我一直覺得,為什麼我總要為著現實而不能再執著我的夢想。我想把文學學得透徹,現在卻得去學商業知識,一切只為了能變得更有錢??可是,我想起同學跟我說的一句話。「當時我在做這份工作時,我告訴自己,這只是暫時,我在這段期間好好培養能力,最後我還是可以到達我想要的地方。」沒人可以讓自己放棄,除非是自己要放棄。我想,用在許多事上,都很有用。

覺得湖比海洋更能沉澱心思。在英國的時候,當我坐在石頭上、對著湖中城堡冥思,心裡潮思翻湧。有多少個夜我為了一些刻骨銘心的往事失眠,當別人看我在不到五度的氣溫下凝望著湖水,多少人會知道我當時的心情,是心酸的、也是喜悅般的複雜?有些人表面很平靜、面容之下卻澎湃洶湧,當你願意去懂一個人的時候,所有的起伏他/她都會明白。當你願意去等待一個人的時候,你便不會輕易放棄,直到你明白,你等待的是一個錯的人時,不消太長時日,你便自然而然地放棄。

用心在一個錯的人會讓你傷心,但用心在一件你一直想完成的事並不會讓你傷心。何必跟自己過不去?我告訴自己。並不是沒有做到就要懷憂喪志,重要的是它是否值得你繼續花心思下去。若是值得,「堅持到底的道路看起來很遙遠,卻是達成目標最近的路。」就努力去超越自己。

我很高興,因著這次的決定,我得到了寶貴的心得。失去亦或是得到,真的是很難說。那又何需想得太多,凡事順其自然吧!

去了歐洲,很羡慕歐洲人那種人生短暫、當及時行樂的瀟瀟。我想,我是需要這種灑脫的,這樣反而不會讓自己礙手礙腳。

我還是喜歡認真,只不過,這一次,讓自己沒有阻礙地向前進吧!

http://www.wretch.cc/blog/yuczhen29/2207752

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)

Reference:
http://techorange.com/2013/09/30/6-ways-to-ruin-your-day/

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

Reference:
http://spreadsheets.about.com/od/tipsandfaqs/qt/81130filldown.htm

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)) {
}

or

// 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).

Reference:
C# 5.0 in a Nutshell: The Definitive Reference
http://stackoverflow.com/questions/5117970/how-can-i-default-a-parameter-to-guid-empty-in-c