Skip to content

Instantly share code, notes, and snippets.

  • 1st way (I don't like it, it's long) but it suits for checking object has the field or not (2nd way is not applied)
var attr = $(this).attr('name');

// For some browsers, `attr` is undefined; for others, `attr` is false. Check for both.
if (typeof attr !== typeof undefined && attr !== false) {
  // Element has this attribute
}
@khoand0000
khoand0000 / money-format.php
Created October 28, 2015 10:00
money_format is not working with Vietnamese
$number = 1234.56;
// let's print the international format for the en_US locale
setlocale(LC_MONETARY, 'en_US');
echo money_format('%i', $number) . "\n";
// USD 1,234.56
// but if using vi_VN or vi_VN.UTF-8, not working
setlocale(LC_MONETARY, 'vi_VN');
echo money_format('%i', $number) . "\n";
@khoand0000
khoand0000 / install-php7-pear-mysql-php-codesniffer-homebrew.md
Last active May 23, 2018 14:57
install php7, pear, mysql, PHP_CodeSniffer by homebrew

Install php7 with pear

$ brew tap homebrew/dupes
$ brew tap homebrew/versions
$ brew tap homebrew/homebrew-php
$ brew install php70 --with-pear

Enable php7 with apache2

@khoand0000
khoand0000 / connect_azure.php
Created September 9, 2014 19:26
connect azure
<?php
try {
$conn = odbc_connect(
"DRIVER={SQL Server};Server=tcp:ac1wr559wv.database.windows.net,1433;Database=1407_test",
"project", "Plastic48");
$cur = odbc_exec($conn, "select username, password, address from users");
while (odbc_fetch_row($cur)) {
//collect results
@khoand0000
khoand0000 / ionicModal-ionicPopup-ionicPopver.md
Last active January 11, 2017 17:34
$ionicModal vs. $ionicPopup vs. $ionicPopover
  • $ionicModal: show dialog (must provide UI) at center screen if large screen (ipad, pc); otherwise, showing fullscreen overlays current screen, allow close modal by clicking backdrop
  • $ionicPopover: show dialog (must provide UI) at element occurs event (button), allow close modal by clicking backdrop
  • $ionicPopup: show dialog (confirm, alert, prompt or custome) at center screen, doesn't allow close modal by clicking backdrop
@khoand0000
khoand0000 / json-structure.md
Last active November 11, 2016 06:19
RESTful guidline

usage

  • return collection. *http code: 200
[
  {id:1},
  {id:2}
]
  • return single object. http code: 200
@khoand0000
khoand0000 / centering-css-complete-guide.md
Last active February 10, 2016 04:35
middle vertical align. Just using the link and apply suitable case: https://css-tricks.com/centering-css-complete-guide/

Take note when using https://css-tricks.com/centering-css-complete-guide/

  • Vertically
    • Is it inline or inline-* elements (like text or links)?
      • Is it a single line?
        • don't know height of element: padding-top == padding-bottom
        • know height of element: using line-height
            .center-text-trick {

height: 100px; /* apply inline-block element, inline element doesn't need it */