Sunday, February 28, 2016

用 curl 測試 Reserve Proxy 是否正確運作

架好 reverse proxy 後要測試可以用 curl 的 --resolve 的功能來確認。

# curl -v --resolve i.kfs.io:443:68.232.45.191 https://i.kfs.io/article5/global/364,324,6v1/original.png > /dev/null

其中 --resolve 的第三個參數一定要用 IP address,你可以看到他的運作原理:

* Added i.kfs.io:443:68.232.45.191 to DNS cache

Reference:

https://blog.gslin.org/archives/2016/02/28/6375/%E7%94%A8-curl-%E6%B8%AC%E8%A9%A6-reserve-proxy-%E6%98%AF%E5%90%A6%E6%AD%A3%E7%A2%BA%E9%81%8B%E4%BD%9C/

Friday, February 26, 2016

jquery : focus to div is not working

Focus doesn't work on divs by default. But, according to this, you can make it work:

The focus event is sent to an element when it gains focus. This event is implicitly applicable to a limited set of elements, such as form elements (<input>, <select>, etc.) and links (<a href>). In recent browser versions, the event can be extended to include all element types by explicitly setting the element's tabindex property. An element can gain focus via keyboard commands, such as the Tab key, or by mouse clicks on the element.

http://api.jquery.com/focus/

To focus on Div element using jQuery its required to DIV element has tabindex property value -1. so set:

<div id="mydiv" tabindex="-1"></div>

Reference:

http://stackoverflow.com/questions/5965924/jquery-focus-to-div-is-not-working

Thursday, February 25, 2016

mysqldump Warning: mysqldump: ignoring option '--databases' due to invalid value 'simply'

mysqldump Warning: mysqldump: ignoring option '--databases' due to invalid value 'simply'

Reason: it was because I have the "database" line in my.cnf file. But, mysqldump doesn't like that parameter.

# cat ~/.my.cnf

[client]
user=root
host=127.0.0.1
password="root"
database=simply

Reference:

http://serverfault.com/questions/670648/mysqldump-complains-about-chosen-databases-regardless-of-command-line

Thursday, February 18, 2016

jQuery selector escape square brackets to select element

jQuery selector escape square brackets to select element

If you feel more comfortable without escaping you also use the attributes selector and search for the element with that id like this:

$('[id="meta[152][value]"]')

From the jQuery documentation:

To use any of the meta-characters ( such as !"#$%&'()*+,./:;<=>?@[]^`{|}~ ) as a literal part of a name, it must be escaped with with two backslashes: \\.

Reference:

http://stackoverflow.com/questions/8404037/jquery-escape-square-brackets-to-select-element

http://stackoverflow.com/questions/18573178/what-is-the-difference-between-these-different-ways-to-escape-square-brackets-in

Tuesday, February 16, 2016

To disable MySQL query cache when testing

To disable MySQL query cache when testing:

SELECT SQL_NO_CACHE id, name FROM customer;

Or

RESET QUERY CACHE

Or

SET SESSION query_cache_type = OFF

Note: Besides the query cache, there is also the cache in buffer pool you need to consider. The only way to purge the buffer pool is to restart the MySQL instance.

Reference:

http://stackoverflow.com/questions/16043943/how-to-disable-mysql-query-caching

http://dev.mysql.com/doc/refman/5.7/en/innodb-buffer-pool.html

Fast counting of rows on InnoDB

Fast counting of rows on InnoDB

See, MyISAM always stores the number of rows on the table header. So, whenever we ask "how many rows are there?", it can just grab the count and return it. Not InnoDB. This makes InnoDB very slow in count queries without a where clause.

So if you have query like SELECT COUNT(*) FROM USER It will be much faster for MyISAM (MEMORY and some others) tables because they would simply read number of rows in the table from stored value. Innodb will however need to perform full table scan or full index scan because it does not have such counter, it also can’t be solved by simple singe counter for Innodb tables as different transactions may see different number of rows in the table.

If you have query like SELECT COUNT(*) FROM IMAGE WHERE USER_ID=5 this query will be executed same way both for MyISAM and Innodb tables by performing index rage scan. This can be faster or slower both for MyISAM and Innodb depending on various conditions.

The trick is to hint it at a specific index. So, if you’re getting poor response times from InnoDB count, it means you’ve got lots of rows that have to be counted one at a time. And since you’ve got a lot of rows, you have at least one index. Just pick an index that will never contain a NULL value, and tell MySQL to USE INDEX (index_name).

Note: COUNT doesn't count NULL values, so if you are counting values by a field that has NULL values, those rows won't be counted by COUNT.

SELECT COUNT(*) FROM messages USE INDEX (index_messages_on_remote_created_at);

+----------+
| count(*) |
+----------+
|  1276831 |
+----------+

1 row in set (3.19 sec)

Reference:

http://kingori.co/minutae/2013/05/mysql-count-innodb/

Fast MySQL InnoDB count. Really fast

MySQL Performance Blog | COUNT(*) for Innodb Tables

MySQL 5.1 Reference Manual | Counting Rows

Wednesday, February 10, 2016

How to generate a new GUID unique ID?

How to generate a new GUID unique ID?

According to Is there any difference between a GUID and a UUID?

GUID is Microsoft's implementation of the UUID standard.

So, here's a link to libraries, that let's you create UUIDs of the following types:

version 1 (time-based)
version 3 (name-based and hashed with MD5)
version 4 (random)
version 5 (name-based and hashed with SHA1)

https://github.com/search?p=1&q=uuid+php&ref=cmdform&type=Repositories

I don't know exactly, which one C# is using, but that's at least something you can use if you're writing some piece of software and want to have universal unique identifiers.

My perfered choice was https://github.com/fredriklindberg/class.uuid.php because it is just a simple PHP file and the most rated one (https://github.com/ramsey/uuid) had to much dependencies on other libraries, but his may change soon (see https://github.com/ramsey/uuid/issues/20).

But if you really need a GUID (according to the Microsoft standard), they have a different generation process than these 4122. Wikipedia claims that

GUIDs and RFC 4122 UUIDs should be identical when displayed textually

http://en.wikipedia.org/wiki/Globally_Unique_Identifier#Binary_encoding

In most cases, you should be fine by going for one of the PHP libs for UUIDs. I don't think you're meddling with Microsoft Component Object Model (COM), don't you?

<?php
// Usage
// Named-based UUID.

$v3uuid = UUID::v3('1546058f-5a25-4334-85ae-e68f2a44bbaf', 'SomeRandomString');
$v5uuid = UUID::v5('1546058f-5a25-4334-85ae-e68f2a44bbaf', 'SomeRandomString');

// Pseudo-random UUID

$v4uuid = UUID::v4();

class UUID {
  public static function v3($namespace, $name) {
    if(!self::is_valid($namespace)) return false;

    // Get hexadecimal components of namespace
    $nhex = str_replace(array('-','{','}'), '', $namespace);

    // Binary Value
    $nstr = '';

    // Convert Namespace UUID to bits
    for($i = 0; $i < strlen($nhex); $i+=2) {
      $nstr .= chr(hexdec($nhex[$i].$nhex[$i+1]));
    }

    // Calculate hash value
    $hash = md5($nstr . $name);

    return sprintf('%08s-%04s-%04x-%04x-%12s',

      // 32 bits for "time_low"
      substr($hash, 0, 8),

      // 16 bits for "time_mid"
      substr($hash, 8, 4),

      // 16 bits for "time_hi_and_version",
      // four most significant bits holds version number 3
      (hexdec(substr($hash, 12, 4)) & 0x0fff) | 0x3000,

      // 16 bits, 8 bits for "clk_seq_hi_res",
      // 8 bits for "clk_seq_low",
      // two most significant bits holds zero and one for variant DCE1.1
      (hexdec(substr($hash, 16, 4)) & 0x3fff) | 0x8000,

      // 48 bits for "node"
      substr($hash, 20, 12)
    );
  }

  public static function v4() {
    return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x',

      // 32 bits for "time_low"
      mt_rand(0, 0xffff), mt_rand(0, 0xffff),

      // 16 bits for "time_mid"
      mt_rand(0, 0xffff),

      // 16 bits for "time_hi_and_version",
      // four most significant bits holds version number 4
      mt_rand(0, 0x0fff) | 0x4000,

      // 16 bits, 8 bits for "clk_seq_hi_res",
      // 8 bits for "clk_seq_low",
      // two most significant bits holds zero and one for variant DCE1.1
      mt_rand(0, 0x3fff) | 0x8000,

      // 48 bits for "node"
      mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff)
    );
  }

  public static function v5($namespace, $name) {
    if(!self::is_valid($namespace)) return false;

    // Get hexadecimal components of namespace
    $nhex = str_replace(array('-','{','}'), '', $namespace);

    // Binary Value
    $nstr = '';

    // Convert Namespace UUID to bits
    for($i = 0; $i < strlen($nhex); $i+=2) {
      $nstr .= chr(hexdec($nhex[$i].$nhex[$i+1]));
    }

    // Calculate hash value
    $hash = sha1($nstr . $name);

    return sprintf('%08s-%04s-%04x-%04x-%12s',

      // 32 bits for "time_low"
      substr($hash, 0, 8),

      // 16 bits for "time_mid"
      substr($hash, 8, 4),

      // 16 bits for "time_hi_and_version",
      // four most significant bits holds version number 5
      (hexdec(substr($hash, 12, 4)) & 0x0fff) | 0x5000,

      // 16 bits, 8 bits for "clk_seq_hi_res",
      // 8 bits for "clk_seq_low",
      // two most significant bits holds zero and one for variant DCE1.1
      (hexdec(substr($hash, 16, 4)) & 0x3fff) | 0x8000,

      // 48 bits for "node"
      substr($hash, 20, 12)
    );
  }

  public static function is_valid($uuid) {
    return preg_match('/^\{?[0-9a-f]{8}\-?[0-9a-f]{4}\-?[0-9a-f]{4}\-?'.
                      '[0-9a-f]{4}\-?[0-9a-f]{12}\}?$/i', $uuid) === 1;
  }
}
?>

Reference:

http://stackoverflow.com/questions/21671179/how-to-generate-a-new-guid

http://php.net/manual/en/function.uniqid.php

http://php.net/manual/en/function.com-create-guid.php

Sunday, February 7, 2016

一個年薪9000萬的銷售女神經驗總結,太精闢了!

一個年薪9000萬的銷售女神經驗總結,太精闢了!

1、銷售最大的信念

一切成交都是為了愛!

2、銷售要掌握的兩大能力

①銷售攻心能力;

②整合資源的能力。

3、銷售三境界

①圍人:能將顧客圍住,並死纏爛打,初步具備接近顧客、推介購買的能力;

②維人:建立長期穩定的關係,不是簡單的買賣,而是朋友、夥伴關係;

③為人:不只是把產品賣出去,同時把自己也銷售出去。

4、銷售不出業績4主要原因

①拖延,不斷的拖延;

②無意義的拜訪;

③一問三不知;

④生理的疲憊。

5、業績猛增的5類銷售

①導師型:靠智慧吃飯的帶隊者;

②鬥士型:喜歡交談、擅長外交,喜歡與銷售並肩作戰;

③警官型:有極高的忠誠度;

④自信型:沒有“不可能”;

⑤事必躬親型:有強烈的責任感。

6、頂級銷售的6個人格特質

①主動積極,永不放棄,提高成功機率;

②同理心,察覺客戶沒說出口的需求;

③正向思考,挫折復原力強,修正再出發;

④守紀律,做好簡單的小事,累積成卓越;

⑤聽多於說,先聽後說,提出對的問題;

⑥說真話,重承諾,不說謊,不誇張。

7、銷售頂尖人員的7個小習慣

①不說尖酸刻薄的話;

②牢記顧客的名字,養成翻看客戶檔案的習慣;

③嘗試著跟你討厭的人交往;

④一定要尊重顧客的隱私;

⑤很多人在一起的時候,當你與其中某個人交談,請不要無視其他人存在;

⑥勇於認錯,誠信待人;

⑦以謙卑的姿態面對身邊的每一個人。

8、銷售的八個更重要

①找到顧客重要,找准顧客更重要;

②瞭解產品重要,瞭解需求更重要;

③搞清價格重要,搞清價值更重要;

④融入團隊重要,融入顧客更重要;

⑤口勤腿勤重要,心勤腦勤更重要;

⑥獲得認可重要,獲得信任更重要;

⑦達成合作重要,持續合作更重要;

⑧卓越銷售重要,不需銷售更重要。

9、頂尖銷售員的九大秘訣

①錢是給內行人賺的——世界上沒有賣不出的貨,只有賣不出的貨的人;

②想幹的人永遠在找方法,不想幹的人永遠在找理由;世界上沒有走不通的路,只有想不通的人;

③銷售者不要與顧客爭論價格,要與顧客討論價值;

④帶著目標出去,帶著結果回來,成功不是因為快,而是因為有方法;

⑤沒有不對的客戶,只有不夠的服務;

⑥營銷人的職業信念:要把接受別人拒絕作為一種職業生活方式;

⑦客戶會走到我們店裡來,我們要走進客戶心裡去;老客戶要坦誠,新客戶要熱情,急客戶要速度,大客戶要品味,小客戶要利益;

⑧客戶需要的不是產品,而是一套解決方案;賣什麼不重要,重要的是怎麼賣;

⑨客戶不會關心你賣什麼,而只會關心自己要什麼;沒有最好的產品,只有最合適的產品。

Reference:

http://tw.anyelse.com/article/155710.html

Friday, February 5, 2016

Use CSS's transform property to move the element to a position

Use CSS's transform property to move the element to a position

<html>
  <head>
    <style>
    .sourceDiv {
      background: #000;
      color: #fff;
      width: 100px;
      height: 100px;
      position: absolute;
    }

    .destinationDiv {
      top: 300px;
      left: 700px;
      background: #c2c3c4;
      color: #fff;
      width: 100px;
      height: 100px;
      position: absolute;
    }

    .moveTo600x400 {
      transform: translate(600px, 400px);
      transition-duration: 5s;
    }
    </style>
    <script src="/javascript/jquery/jquery-1.10.2.min.js"></script>
    <script>
      $(document).ready(function() {
        $('.sourceDiv').on('click', function(e){
          //$(this).addClass('moveTo600x400');

          var pos = $('.destinationDiv').offset();
          console.log(pos);

          $(this).css({
            transform: 'translate(' + pos.left + 'px, ' + pos.top + 'px)',
            'transition-duration': '3s',
          });
        });
      });
    </script>
  </head>
  <body>
    <div class="sourceDiv">test</div>
    <div class="destinationDiv">test</div>
  </body>
</html>