Monday, November 30, 2015

To search and highlight text in a page

You can use window.find() in non-IE browsers and TextRange's findText() method in IE.

function doSearch(text) {
    if (window.find && window.getSelection) {
        document.designMode = "on";
        var sel = window.getSelection();
        sel.collapse(document.body, 0);
        
        while (window.find(text)) {
            document.execCommand("HiliteColor", false, "yellow");
            sel.collapseToEnd();
        }
        document.designMode = "off";
    } else if (document.body.createTextRange) {
        var textRange = document.body.createTextRange();
        while (textRange.findText(text)) {
            textRange.execCommand("BackColor", false, "yellow");
            textRange.collapse(false);
        }
    }
}

Reference:

http://stackoverflow.com/questions/5886858/full-text-search-in-html-ignoring-tags/5887719#5887719

Friday, November 27, 2015

Using Font-Awesome icons

Using Font-Awesome icons

To increase icon sizes relative to their container, use the fa-lg (33% increase), fa-2x, fa-3x, fa-4x, or fa-5x classes.

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">

<i class="fa fa-camera-retro fa-lg"></i> fa-lg
<i class="fa fa-camera-retro fa-2x"></i> fa-2x
<i class="fa fa-camera-retro fa-3x"></i> fa-3x
<i class="fa fa-camera-retro fa-4x"></i> fa-4x
<i class="fa fa-camera-retro fa-5x"></i> fa-5x

Reference:

http://fortawesome.github.io/Font-Awesome/icons/

http://fortawesome.github.io/Font-Awesome/examples/

Get a grid's cell position in jQWidgets

Get a grid's cell position in jQWidgets

$('#jqxgrid').jqxGrid({
  ready: function(){
    $('#jqxgrid').on('cellclick', function (event) {
      console.log(event.args.originalEvent.clientX);
      console.log(event.args.originalEvent.clientY);

      console.log($('#jqxgrid').offset());
      console.log($('#jqxgrid').width());
      console.log($('#jqxgrid').height());

      if (event.args.rightclick) {
        console.log('right clicked');
      }
    });
  },
});

Wednesday, November 25, 2015

height:100%; not working

height:100%; not working

Solution 1:

html, body { height:100%; }

Solution 2 (Modern Approach):

As an alternative to setting both the html/body element's heights to 100%, you could also use viewport-percentage lengths:

5.1.2. Viewport-percentage lengths: the ‘vw’, ‘vh’, ‘vmin’, ‘vmax’ units

The viewport-percentage lengths are relative to the size of the initial containing block. When the height or width of the initial containing block is changed, they are scaled accordingly.

body {
    height: 100vh;
}

Setting a min-height also works.

body {
    min-height: 100vh;
}

These units are supported in most modern browsers - support can be found here.

Reference:

http://stackoverflow.com/questions/7049875/height100-not-working

Remove all core and contrib CSS styles from Drupal 6

Remove all core and contrib CSS styles from Drupal 6

/**
 * Implementation of hook_preprocess_page().
 */
function YOUR_MODULE_NAME_preprocess_page(&$variables) {
      $variables['css']['all']['module'] = array();
      $variables['css']['all']['theme'] = array();
      $variables['css']['print']['module'] = array();
      $variables['css']['print']['theme'] = array();
      $variables['styles'] = drupal_get_css($variables['css']);
}

What You Need To Know About AngularJS Data Binding

What You Need To Know About AngularJS Data Binding

You hear a lot about data binding in AngularJS, and with good reason: its at the heart of everything you do with Angular. I’ve mentioned data binding more than a few times in my guides to directives and filters, but I haven’t quite explained the internals of how data binding works. To novices, it seems like straight sorcery, but, in reality, data binding is fundamentally very simple.

Scoping out the situation

Fundamentally, data binding consists of a set of functions associated with a scope. A scope is an execution context for the expressions you write in your HTML. AngularJS scopes behave like scopes in Javascript: a scope contains a set of named variables and is organized in a tree structure, so expressions in a given scope can access variables from an ancestor scope in the tree. However, data binding adds three powerful functions to a scope that enable you to assign an event handler to fire when a variable in scope changes as easily as you assign an event handler to fire when a button is clicked.

$watch()

This function takes an expression and a callback: the callback will be called when the value of the expression changes. For example, lets say our scope has a variable name, and we want to update the firstName and lastName variables every time name changes. With $watch, this is trivial:

$scope.$watch('name', function(value) {
  var firstSpace = (value || "").indexOf(' ');
  if (firstSpace == -1) {
    $scope.firstName = value;
    $scope.lastName = "";
  } else {
    $scope.firstName = value.substr(0, firstSpace);
    $scope.lastName = value.substr(firstSpace + 1);
  }
});

Under the hood, each scope has a list of watchers, internally called $scope.$$watchers, which contain the expression and the callback function. The $watch simply adds a new watcher to the $$watchers array, which AngularJS loops over when it thinks something that can change the state of the scope.

$apply()

When called without arguments, $apply lets AngularJS know that something happened that may have changed the state of the scope, so AngularJS knows to run through its watchers. You usually don’t have to call $apply() yourself, because directives like ngClick do it for you. However, if you’re writing your own event handler, like the swipeLeft and swipeRight directives from my guide to directives, you need to plug $apply() into your event handler. Try removing the $apply() calls from the swipeLeft and swipeRight directives in this JSFiddle and watch as the UI stops responding to swipes.

Some Important Information to $digest

$digest() is the third scope function related to data binding, and it’s the most important one. With high probability, you will never actually call $digest() directly, since $apply() does that for you. However, this function is at the core of all data binding magic, and its internals warrant some careful inspection if you’re going to be an AngularJS pro.

At a high level, $digest() runs through every watcher in the scope, evaluates the expression, and checks if the value of the expression has changed. If the value has changed, AngularJS calls the change callback with the new value and the old value. Simple, right? Well, not quite, there are a few subtleties.

1) The first subtlety is with the change callback: the change callback itself can change the scope, like we did with the name example in the $watch() section. If we had a watcher on firstName, this watcher wouldn’t fire! This is why $digest() is executed in a loop: $digest() will repeatedly execute all watchers until it goes through all watchers once without any of the watched expressions changing. In AngularJS internals, a dirty flag is set on each iteration of the $digest() loop when a change callback needs to be fired. If the dirty flag is not set after an iteration, $digest() terminates.

Of course, the $digest() loop described above can run forever, which is very bad. Internally, AngularJS uses a questionably-named field TTL (presumably “times to loop”) field to determine the maximum number of times a $digest() loop will run before giving up. By default, TTL is 10, and you will usually not run into this limit unless you have an infinite loop. If you for some reason need to tweak the TTL, the AngularJS root scope has a poorly-documented digestTtl() function which you can use to change the TTL on a per-page basis. You can read more about this function here.

2) The second subtlety is another interesting corner case with the change callback: what if the change callback calls $apply() or $digest()? Internally, AngularJS uses a system of phases to make sure this doesn’t happen: an error gets thrown if you try to enter the $digest phase while you’re already in the $digest phase.

3) Remember when we said that AngularJS scopes are organized in a tree structure and a scope can access its ancestor’s variables? Well, this means that $digest() needs to happen on every child scope in every iteration! Internally, this code is a bit messy in AngularJS, but each iteration of the $digest() loop does a depth-first search and performs the watcher check on every child scope. If any child scope is dirty, the loop has to run again!

4) Since Javascript is a single-threaded event-driven language, the $digest() loop cannot be interrupted. That means that the UI is blocked while $digest() is running, which means two very bad things happen when your $digest() is slow: your UI does not get updated until $digest() is done running, and your UI will not respond to user input, e.g. typing in an input field, until $digest() is done. To avoid a bad case of client side in-$digest-ion, make sure your event handlers lightweight and fast.

5) The final and often most overlooked subtlety is the question of what we mean when we say “checks if the value of the expression has changed”. Thankfully, AngularJS is a bit smarter than just using Javascript’s === operator: if AngularJS just used ===, data binding against an array would be very frustrating. Two arrays with the same elements could be considered different! Internally, AngularJS uses its own equals function. This function considers two objects to be equal if === says they’re equal, if angular.equals returns true for all their properties, if isNaN is true for both objects, or if the objects are both regular expressions and their string representations are equal. Long story short, this does the right thing in most situations:

angular.equals({ a : 1 }, { a : 1 }); //true
angular.equals({ a : 1 }, { a : 1, b : 2 }); // false
 
angular.equals([1], [1]); // true
angular.equals([1], [1, 2]); // false
 
angular.equals(parseInt("ABC", 10), parseInt("ABC", 10)); // true

Conclusion

Hopefully now you don’t need to go buy the recently released ng-book, which promises to teach you the answer to the question “seriously, what the does $apply and $digest mean?” Data binding seems like magic, but really its just some clever-yet-simple software engineering. You can even build your own version of AngularJS data binding if you follow the steps lined out in this awesome article. Ideally, now data binding should be a lot less confusing. Good luck and code on!

Reference:

https://thecodebarbarian.wordpress.com/2014/01/31/what-you-need-to-know-about-angularjs-data-binding/

Tuesday, November 24, 2015

mysql_install_db FATAL ERROR: Could not find ./bin/my_print_defaults

# pkg_info | grep -i mysql

mysql-client-5.5.9  Multithreaded SQL database (client)
mysql-server-5.5.9  Multithreaded SQL database (server)

# /usr/local/bin/mysql_install_db

FATAL ERROR: Could not find ./bin/my_print_defaults

If you compiled from source, you need to run 'make install' to copy the software into the correct location ready for operation.

If you are using a binary release, you must either be at the top level of the extracted archive, or pass the --basedir option pointing to that location.

Solution:

Look for binary path:

# which mysql_install_db

/usr/local/bin/mysql_install_db

Look for binary path:

# which my_print_defaults

/usr/local/bin/my_print_defaults

Set basedir to /usr/local:

# /usr/local/bin/mysql_install_db --basedir=/usr/local

Improving ng-repeat Performance with "track by"

Improving ng-repeat Performance with "track by"

track by allows you to specify your own key for ngRepeat to identify objects by, instead of just generating unique IDs.

<ul class="tasks">
  <li ng-class="{done: task.done}" ng-repeat="task in tasks track by task.id">
    {{task.id}}: {{task.title}}
  </li>
</ul>

Reference:

http://www.codelord.net/2014/04/15/improving-ng-repeat-performance-with-track-by/
http://www.codelord.net/2014/05/10/understanding-angulars-magic-dont-bind-to-primitives/
http://moduscreate.com/the-magic-of-angular-js-two-way-binding/

Sunday, November 22, 2015

我們常說要“放下”,到底要放下什麼?

我們常說要“放下”,到底要放下什麼?

1、放下爭論對錯
有許多人不能認識到自己也是犯錯的,而是希望自己永遠正確,殊不知,這對我們良好的人際關系是一個巨大風險,
也給我們或別人帶來巨大的壓力和痛苦。仔細想想,這真是的值得的嗎?
因此,當你感覺自己急切投入到爭論對錯的時候,請問一下自己,這樣做真的是對的嗎?對自己真的是有利的嗎?
我們的自我真的就那樣大嗎?

2、放下你的控制欲
要願意放棄你對身邊人、環境和事物的控制欲。無論他們是你愛的人,還是你的工作伙伴,或僅是街上一個陌生人,
請允許他們遵循自己的狀態,這樣你就能感受到更好。

3、放下責備
不要去責備別人做了什麼,或者沒有做什麼,也不要憑著你的感受去責怪別人。

4、放下你的自怨自艾心態
許多人之所以痛苦是因為他們消極的,不潔淨的和反復出現自暴自棄的心態。不要相信任何消極的自怨自艾的想法。
這樣你會更好。

5、放下對自己有限的認識
我能做什麼,我不能做什麼?什麼是可能的,什麼是不可能的?
現在,放下你對自己問題的思考,對自己有限的認識不應該讓你圈禁自己。張開翅膀,盡情飛翔吧!

6、放下抱怨的心態
停止你一貫對(人、環境、事物)的抱怨吧!除非你願意,沒有人能使你不快樂,沒有環境能讓你沮喪可憐。
不是環境引發了你的這些感受,而是你自己選擇的。積極想法的能量不可低估。

7、放下批評
不要去輕易批評與你不同的人和事。我們都是不同的,但我們又都是相同的,我們都希望快樂,希望被人愛和理解。

8、放下虛榮心
停止去迎合和取悅別人,因為這是做不到的。只有當你放下偽裝,摘下自己的面具時,你才能接受和擁抱真實,
這時別人也才能被你吸引。

9、放下惰性
改變是好的,改變可以幫助你從A到B,改變可以改進你和你周邊人的生活。跟隨你的運氣,擁抱改變吧,不要去抗拒它。

10、放下隨意判斷的心
不要給那些你不了解的人和事輕易下定義,貼標簽,盡管有時它們看起來很怪異不同,嘗試一點點打開你的心靈。
記住,頭腦在打開的時候才會工作,高級的愚癡就是輕易拒絕那些你一點也不了解的事。

11、放下恐懼
恐懼只是一個幻覺,它並不真實存在,只是你創造了它,它只存在於你的頭腦裡。
只有一樣東西令我們恐懼,那就是恐懼本身。修改你的內在,外在的自然就變好。

12、放下藉口
大多數時候,我們限制我們自己,因為我們總是使用這樣或那樣的藉口,而不是改進我們的生活和努力成長。
我們被它們障礙了,被它們欺騙了,要知道99%的藉口都是虛假的。

13、放下過去
我知道這是很難的,尤其是過去十分美好, 而未來令人恐懼的時候。但是你不得不認真考慮現實,因為現實才是你擁有的。
過去雖然是你渴望的,但那只是你的一個妄想。你必須回到現實認清這一點。不要令自己迷惑,活在當下,享受當下。
畢竟人生是旅程,而不是終點。為自己做好准備,保持一個清醒的意識,僅僅活在當下。

14、放下執著
這個概念,對於我們大多數人來說確實很難領悟,但這依然不是不可能的。你可以通過花時間不斷地鍛煉一點點做到。
放下執著就是超然物外,放下一切,但這不代表你可以放棄愛,因為愛與執著是兩回事,執著更多的來源於對失去的恐懼。
而愛是純淨的,寬容的,不自私的。當你愛的時候,你不會恐懼失去。因此愛與執著不能共存。
放下執著,你將變得十分平和,寬容和安詳。這時,你能夠理解一切事物,甚至包括你並未體驗過的事。這種狀態超越語言。

15、放下別人的看法,自己過自己的生活,太多的人在為別人生活,而不是自己。
他們總是根據別人的觀點去生活,包括別人認為好的。他們忽視內在的聲音,內心的呼喚。

他們總是忙著取悅別人,為別人的期望生活,而忘記控制自己的生活,忘記自己到底喜歡什麼,到底想要什麼,到底需要什麼。

最終,他們忘記了自己。請記住,你擁有自己的人生,這是一項權利,它是屬於你的,你必須為自己的人生而活。

尤其注意不要讓他人的意見左右你的道路。有的人以為放下就是不管不顧,或者就是隨隨便便。其實不然,不管不顧是放棄隨隨便便是馬虎客。真正的放下,不是應付了事,而是用心做事。

做事包括工作、生活、學習、修行等等。在做事過程中不做與事情本身無關的事情,比如邊做事邊胡思亂想,邊做事邊覓心覓性,邊做事邊計較,邊做事邊情緒化,邊做事邊妄想我在做事…等等,這些統統要放下。 那麼做完事呢?

你盡心盡責做完事了,剩下的只能是結果,不管是好是壞,已經告一階段了。

你對好的總結經驗,對壞的吸收教訓,然後全部從心上放下,好的不留戀再三,壞的不難過憂愁,都不要執著了,因為你已經努力過了。

放下,是一種生活的智慧。
放下,是一種坦然,不是無奈,更不是放棄。
放下,是一種大度,是一種徹悟,是一種靈性。

只有該放下時放下,你才能夠騰出手來,抓住真正屬於你的快樂和幸福。

Wednesday, November 18, 2015

Custom Order Number and Invoice number prefix

SELECT
  entity_type_id
, entity_type_code
FROM eav_entity_type
ORDER BY entity_type_id

5 order
6 invoice
7 creditmemo
8 shipment


### Order
INSERT INTO magento191.eav_entity_store (entity_type_id, store_id, increment_prefix, increment_last_id)
VALUES (5, 1, 2, 200000000);

### Invoice
INSERT INTO magento191.eav_entity_store (entity_type_id, store_id, increment_prefix, increment_last_id)
VALUES (6, 1, 2, 200000000);

### Credit Memo
INSERT INTO magento191.eav_entity_store (entity_type_id, store_id, increment_prefix, increment_last_id)
VALUES (7, 1, 2, 200000000);

### Shipment
INSERT INTO magento191.eav_entity_store (entity_type_id, store_id, increment_prefix, increment_last_id)
VALUES (8, 1, 2, 200000000);

SELECT
*
FROM magento191.eav_entity_store;

SELECT
core_store_group.name AS group_name
, core_website.name AS website_name
, core_store.name AS store_name
, core_store.store_id
, increment_prefix
, increment_last_id
, entity_type_code
FROM eav_entity_store
INNER JOIN eav_entity_type ON eav_entity_type.entity_type_id = eav_entity_store.entity_type_id
INNER JOIN core_store ON core_store.store_id = eav_entity_store.store_id
INNER JOIN core_store_group ON core_store_group.group_id = core_store.group_id
INNER JOIN core_website ON core_website.website_id = core_store.website_id
WHERE eav_entity_store.store_id != 0 ORDER BY eav_entity_store.store_id;

If you have encountered "duplicated invoice number" error message from Paypal, try to examine the "reserved_order_id" field and reset it accordingly:

SELECT 
entity_id
, store_id
, reserved_order_id 
, base_currency_code
, base_grand_total
, customer_email
FROM sales_flat_quote
ORDER BY entity_id DESC

Reference:

http://www.warpconduit.net/2012/04/18/how-to-change-the-order-increment-id-and-prefix-in-magento/

Format price in the current locale and currency

Format price in the current locale and currency

To display price with currency symbol:

$finalPrice = 55;
Mage::helper('core')->currency($finalPrice, true, false);

// static mixed currency (float $value, [bool $format = true], [bool $includeContainer = true])

OR

$finalPrice = 55;
$formattedPrice = Mage::helper('core')->formatPrice($finalPrice, false);

To display price without currency symbol:

$finalPrice = 55;
Mage::helper('core')->currency($finalPrice, false, false);

OR

$finalPrice = 55;
Mage::getModel('directory/currency')->formatTxt($finalPrice, array('display' => Zend_Currency::NO_SYMBOL));

To get currency symbol and symbol name by currency code:

$currency_code = Mage::app()->getStore()->getCurrentCurrencyCode();
$currency_symbol = Mage::app()->getLocale()->currency( $currency_code )->getSymbol();
$currency_name = Mage::app()->getLocale()->currency( $currency_code)->getName();

To convert Price from Current Currency to Base Currency and vice-versa:

$baseCurrencyCode = Mage::app()->getStore()->getBaseCurrencyCode();
$currentCurrencyCode = Mage::app()->getStore()->getCurrentCurrencyCode();
$price = 100;
 
// convert price from current currency to base currency
$priceOne = Mage::helper('directory')->currencyConvert($price, $currentCurrencyCode, $baseCurrencyCode);
 
// convert price from base currency to current currency
$priceTwo = Mage::helper('directory')->currencyConvert($price, $baseCurrencyCode, $currentCurrencyCode);

To change price from any one currency to another:

$from = 'USD';
$to = 'NPR';
$price = 10;
 
$newPrice = Mage::helper('directory')->currencyConvert($price, $from, $to);

Reference:

http://blog.chapagain.com.np/magento-format-price/
http://magento.stackexchange.com/questions/8450/how-to-get-currency-symbol-by-currency-code
http://blog.chapagain.com.np/magento-convert-price-from-current-currency-to-base-currency-and-vice-versa/

Tuesday, November 17, 2015

薪資倒退十八年!拿高薪的 12 個秘訣,還不知道的話就虧大了!擺脫 22k 趁現在

生活中時常聽到人們抱怨工資少,

但是抱怨歸抱怨,你是否意識到自身的一些問題呢?

高薪的條件你又滿足幾條?

繼續看下去...

一、忠誠

單位可能開除有能力的員工,但對一個忠心耿耿的人,

不會有領導願意讓他走,

他會成為單位這個鐵打營盤中最長久的戰士,

而且是最有發展前景的員工。

1、 站在老闆的立場上思考問題;

2、 與上級分享你的想法;

3、 時刻維護公司的利益;

4、 琢磨為公司賺錢;

5、 在外界誘惑面前經得起考驗。

二、敬業

隨著社會進步,人們的知識背景越來越趨同。

學歷、文憑已不再是公司挑選員工的首要條件。

很多公司考察員工的第一條件就是敬業,

其次才是專業水平。

1、 工作的目的不僅僅在於報酬;

2、 提供超出報酬的服務與努力;

3、 樂意為工作作出個人犧牲;

4、 模糊上下班概念,完成工作再談休息;

5、 重視工作中的每一個細節。

三、積極

不要事事等人交代,

一個人只要能自動自發地做好一切,

哪怕起點比別人低,也會有很大的發展,

自發的人永遠受老闆歡迎。

1、 從「要我做」到「我要做」;

2、 主動分擔一些「分外」事;

3、 先做後說,給上司驚喜;

4、 學會毛遂自薦;

5、 高標準要求:要求一步,做到三步;

6、 拿捏好主動的尺度,

不要急於表現、出風頭甚至搶別人的工作。

四、負責

勇於承擔責任的人,對企業有著重要的意義,

一個人工作能力可以比別人差,

但是一定不能缺乏責任感,

凡事推三阻四、找客觀原因,而不反思自己,

一定會失去上級的信任。

1、 責任的核心在於責任心;

2、 把每一件小事都做好;

3、 言必信,行必果;

4、 錯就是錯,絕對不要找藉口;

5、 讓問題的皮球至於你;

6、 不因一點疏忽而鑄成大錯。

五、效率

高效的工作習慣是每個可望成功的人所必備的,

也是每個單位都非常看重的。

1、 跟窮忙瞎忙說「再見」;

2、 心無旁騖,專心致志;

3、 量化、細化每天的工作;

4、 拖延是最狠毒的職業殺手;

5、 牢記優先,要事第一;

6、 防止完美主義成為效率的大敵。

六、結果

「無論黑貓、白貓,抓得到老鼠就是好貓!」,

無論苦幹、巧幹,出成績的員工才會受到眾人的肯定。

企業重視的是你有多少「功」,而不是有多少「苦」。

1、 一開始就要想怎樣把事情做成;

2、 辦法永遠要比問題多;

3、 聰明地工作而不僅僅是努力工作;

4、 沒有條件,就創造條件;

5、 把任務完成得超出預期。

七、溝通

不好溝通者,即便自己再有才,也只是一個人的才幹,

既不能傳承,又無法進步;

好溝通者,哪怕很平庸,也可以邊干邊學,

最終實現自己的價值。

1、 溝通和八卦是兩回事;

2、 不說和說得過多都是一種錯;

3、 帶著方案去提問題,當面溝通,當場解決;

4、 培養接受批評的情商;

5、 胸懷大局,既報喜也報憂;

6、 內部可以有矛盾,對外一定要一致。

八、團隊

團隊提前,自我退後。

不管個人能力多強,只要傷害到團隊,

公司決不會讓你久留——不要認為缺了你一個,

團隊就無法運轉!

1、 滴水融入大海,個人融入團隊;

2、 服從總體安排;

3、 遵守紀律才能保證戰鬥力;

4、 不做團隊的「短板」,如果現在是,

就要給自己「增高」;

5、 多為別人、為團隊考慮。

九、進取

個人永遠要跟上企業的步伐,

企業永遠要跟上市場的步伐;

無論是職場還是市場,無論是個人還是企業,

參與者都不希望被淘汰。

為此就一定要前進,停就意味著放棄,意味著出局!

1、 以空杯心態去學習、去汲取;

2、 不要總生氣,而要爭氣;

3、 不要一年經驗重複用十年;

4、 擠時間給自己「增高」、「充電」;

5、 發展自己的「比較優勢」;

6、 挑戰自我,未雨綢繆。

十、低調

才高不必自傲,不要以為自己不說、不宣揚,

別人就看不到你的功勞。所以別在同事面前炫耀。

1、 不要邀功請賞;

2、 克服「大材小用」的心理;

3、 不要擺架子耍資格;

4、 凡是人,皆須敬;

5、 努力做到名實相符,要配的上自己的位置;

6、 成績只是開始,榮譽當作動力。

十一、成本

節約,但不可摳門。不要把公司的錢不當錢,

公司「鍋」裡有,員工「碗」裡才有;

同樣,「鍋」裡多,「碗」裡也自然就多。

而掌勺的,恰恰就是你自己。

1、 報銷賬目,一定要誠信;

2、 不耍小聰明,不貪小便宜;

3、 不浪費公司的資源,哪怕是一張紙;

4、 珍惜工作的每一分鐘時間;

5、 每付出成本,都要力爭最大收益;

6、 記住:省下的,就是利潤!

十二、感恩

為什麼我們能允許自己的過失,

卻對他人、對公司有這麼多的抱怨?

再有才華的人,也需要別人給你做事的機會,

也需要他人對你或大或小的幫助。

你現在的幸福不是你一個人就能成就的。

1、 老闆給了你飯碗;

2、 工作給你的不僅是報酬,還有學習、成長的機會;

3、 同事給了你工作中的配合;

4、 客戶幫你創造了業績;

5、 對手讓你看到距離和發展空間;

6、 批評者讓你不斷完善自我。

工作心態很重要呀!

無論什麼工作,只要證明自己的價值...

總會有出頭天的一天!我一直相信著...

To translate page in Magento

To translate page in Magento, copy the URL key of the existing page. Then add a new page with the same URL key and select the store view.

For example: privacy-policy

flush DNS domain cache

flush DNS domain cache

dnscmd /clearcache
ipconfig /flushdns
ipconfig /registerdns

3 ways to Add JavaScript Translations in Magento

3 ways to Add JavaScript Translations in Magento

If you want to add translation in JavaScript code of your Magento module, there are three ways to achieve that. You can select any approach that suits your requirement the best.

Method 1: Direct Translation: In this method you can use the defalt Magento translation function to perform the translations. For example in your .phtml you can write the following code:

//javascript
alert("<?php echo Mage::helper('core')->__('I have been translated.') ?>");

This is the simplest way to Translate JavaScript strings in Magento.

Method 2: Using Translator: Magento provides you the JavaScript Translator object to translate the strings which is used as follows:

//javascript
alert(Translator.translate('I have been translated.'));

Before that you have to add the string in Translator as follows:

<script type="text/javascript">
Translator.add('I have been translated.','<?php echo Mage::helper('core')->__('I have been translated.')?>');
</script>

You have to add this new string in the translation csv file of your module. See how to add translation csv in your module.

Method 3: Using jstranslator.xml: Alternatively you can add the jstranslator.xml in your module under etc/ folder. This file contains all the string that you want to translate through JavaScript. Here is the sample file:

<jstranslator>
    <my_string translate="message" module="mymodule">
        <message>I have been translated.</message>
    </my_string>
    <my_another_string translate="message" module="mymodule">
        <message>I want to be translated.</message>
    </my_another_string>
</jstranslator>

Now in your template or JS file you can use:

//javascript
alert(Translator.translate('I have been translated.'));

Reference:

http://www.webspeaks.in/2013/10/3-ways-to-add-javascript-translations-in-magento.html

Generate the CRC32 Hash for the translation string

Generate the CRC32 Hash for the translation string

$str = 'Mage_Core::test';
echo crc32($str);

2921638064

Sample record in core_translate table:

INSERT INTO `core_translate` VALUES ('1', 'Mage_Core::test', '0', 'テスト', 'ja_JP', '2921638064');

Monday, November 16, 2015

Get the unique Android device ID

Get the unique Android device ID

String android_id = Secure.getString(getApplicationContext().getContentResolver(), Secure.ANDROID_ID);

Reference:

http://stackoverflow.com/questions/2785485/is-there-a-unique-android-device-id/5626208#5626208

Sunday, November 15, 2015

Gradle command line: failed to find target android-22

Gradle command line: failed to find target android-22

Expecting that you use android studio...

Firstly check the build.gradle file of a previous app or just create a new one and check the build.gradle file.

Check the build.gradle file of the app which gives this issue. Just change it according to build.gradle in the running app.

Basically you'll have to change 2 main things here. Shown below:

compileSdkVersion = 23 // add the version which is in your running project
buildToolsVersion = "23.0.2" /* add the version which is in your running project*/

minSdkVersion = 23
targetSdkVersion = 23  /*same as your build.gradle of running app*/

After the changes, clean and rebuild your project. It should work.

or

You could download the required sdk versions.

Reference:

http://stackoverflow.com/questions/30373756/gradle-command-line-failed-to-find-target-android-22

Tuesday, November 10, 2015

output buffering

If it did not work, try to disable gzip encoding first.

<?php
  ob_start();
  #ob_start('ob_gzhandler');
  #ob_start('ob_deflatehandler');

  header( 'Content-type: text/html; charset=utf-8' );

  for ($i=0; $i<3; $i++) {
    $arr = array('status' => TRUE, 'test' => 'TEST ' . date('Y-m-d H:i:s'));
    echo str_pad(json_encode($arr), 4096);

    ob_flush();
    flush();
    sleep(1);
  }

  ob_end_flush();
  exit;
?>

Comet is a web application model in which a long-held HTTP request allows a web server to push data to a browser, without the browser explicitly requesting it.

Reference:

http://stackoverflow.com/questions/3901495/what-is-the-best-way-of-showing-progress-on-an-ajax-call
https://en.wikipedia.org/wiki/Comet_%28programming%29
http://jpauli.github.io/2014/12/19/php-output-buffer-in-deep.html
http://stackoverflow.com/questions/4191385/php-buffer-ob-flush-vs-flush?rq=1

Thursday, November 5, 2015

How to post data in PHP using file_get_contents?

How to post data in PHP using file_get_contents?

Sending an HTTP POST request using file_get_contents is not that hard, actually : as you guessed, you have to use the $context parameter.

There's an example given in the PHP manual, at this page : HTTP context options (quoting) :

$postdata = http_build_query(
    array(
        'var1' => 'some content',
        'var2' => 'doh'
    )
);

$opts = array('http' =>
    array(
        'method'  => 'POST',
        'header'  => 'Content-type: application/x-www-form-urlencoded',
        'content' => $postdata
    )
);

$context  = stream_context_create($opts);

$result = file_get_contents('http://example.com/submit.php', false, $context);

echo $result;

Basically, you have to create a stream, with the right options (there is a full list on that page), and use it as the third parameter to file_get_contents -- nothing more ;-)

As a sidenote : generally speaking, to send HTTP POST requests, we tend to use curl, which provides a lot of options an all -- but streams are one of the nice things of PHP that nobody knows about... too bad...

Reference:

http://stackoverflow.com/questions/2445276/how-to-post-data-in-php-using-file-get-contents

Wednesday, November 4, 2015

How to print a logo on labels using a Zebra printer and sending ZPL instructions to it

How to print a logo on labels using a Zebra printer and sending ZPL instructions to it

go to the Labelary online ZPL viewer, paste your ZPL into the viewer, click "Add image", and upload the image that you want to add to the ZPL.

Reference:

http://stackoverflow.com/questions/29253453/how-to-print-a-logo-on-labels-using-a-zebra-printer-and-sending-zpl-instructions

http://labelary.com/viewer.html

https://sharpzebra.codeplex.com/

Tuesday, November 3, 2015

Load PDF into iframe and call print

<html>
<head>
<script src="jquery-1.11.3.min.js"></script>
<script>
jQuery(document).ready(function($) {
  function print(url)
  {
      var _this = this,
          iframeId = 'iframeprint',
          $iframe = $('iframe#iframeprint');
      $iframe.attr('src', url);

      $iframe.load(function() {
          callPrint(iframeId);
      });
  }

  //initiates print once content has been loaded into iframe
  function callPrint(iframeId) {
      var PDF = document.getElementById(iframeId);
      PDF.focus();
      PDF.contentWindow.print();
  }

  print('http://mydomain.local/test.pdf');
});
</script>
</head>
<body>
  <iframe id="iframeprint"></iframe>
</body>
</html>

Reference:

http://www.sitepoint.com/load-pdf-iframe-call-print/

Print directly from browser without print popup dialog window

Print directly from browser without print popup dialog window

I wanted to follow up on this to share how I resolved this.

I ended up implementing a custom application that works very similar to the Nexus Mod Manager. I wrote a C# application that registers a custom Application URI Scheme. Here's how it works:

1. User clicks "Print" on the website.
2. Website links user to "CustomURL://Print/{ID}
3. Application is launched by windows via the custom uri scheme.
4. Application communicates with the pre-configured server to confirm the print request and in my case get the actual print command.
5. The application then uses the C# RawPrinterHelper class to send commands directly to the printer.

This approach required an initial download from the user, and a single security prompt from windows when launching the application the first time. I also implemented some Javascript magic to make it detect whether the print job was handled or not. If it wasn't it asks them to download the application.

Reference:

http://stackoverflow.com/questions/9213660/html-javascript-one-click-print-no-dialogs

get ZPL Code From zebra designer?

You can add a new ZebraDesigner ZPL driver to the system and use a file as the port. Then when you "Print" the document, it will write the ZPL code to the file.

Note that it might have some header information before the first ^XA which you might not need.

UPDATE : (How to add local port on a driver)

  1. Go to Printer Properties
  2. Click on the Ports tab
  3. Click Add Port
  4. Select Local Port and click New port
  5. Enter a filename e.g. C:\output.zpl
  6. Make sure it is checked in the ports list
  7. Now all printing output should go to C:\output.zpl

===

If you want to see native ZLP codes you must use zebra fonts, if you do not use you will see .GRF codes like below:

^FT320,64^XG007.GRF,1,1^FS

and do not understand them. After that hit print than select "print to file". So you can see clear ZLP codes.

Reference:

http://stackoverflow.com/questions/13586865/get-zpl-code-from-zebra-designer