Chủ Nhật, 4 tháng 8, 2019

CSS Tutorial 01: Position

Relative: vị trí gắn với chính nó ở trạng thái mặc định (static), thay đổi nó mà không làm thay đổi cấu trúc xung quanh. Nghĩa là: Định vị trí tuyệt đối (vị trí bao ngoài), lúc này các thẻ HTML bên trong sẽ coi nó là thẻ cha.
Absolute: liên quan đến vị trí của bố mẹ và thay đổi bố cục xung quanh vị trí đó. Nghĩa là: Định vị trí tương đói theo thẻ cha (thẻ khai báo relative) hoặc thẻ body nếu ko có khai báo.

Ta có thể ví relative như một cái khung và absolute là một hòn bi di chuyển bên trong cái khung nên nó có thể lăn tới bất kì vị trí nào, thậm chí nó có thể lăn ra bên ngoài khung. Và để thiết lập vị trí thì ta sử dụng bốn thuộc tính sau:
  • top: lên phía trên
  • right: qua bên phải
  • bottom: xuống phía dưới
  • left: qua bên trái
Bạn chỉ có thể sử dụng nhiều nhất là 2 giá trị liền kề nhau tuân theo tọa độ đề cát, các cặp đó là: (top, right) - (right, bottom) - (bottom, left) - (left, top).

---

<!DOCTYPE html>
<html>

<head>
    <title>Demo</title>
    <style type="text/css">
    .main {
        background-color: blue;
        width: 500px;
        height: 500px;
        position: relative;
    }

    .topleft {
        width: 100px;
        height: 100px;
        background-color: red;
    }

    .topright {
        position: absolute;
        top: 0px;
        right: 0px;
        width: 100px;
        height: 100px;
        background-color: green;
    }

    .bottomleft {
        position: absolute;
        bottom: 0px;
        left: 0px;
        width: 100px;
        height: 100px;

        background-color: yellow;
    }

    .bottomright {
        position: absolute;
        bottom: 0px;
        right: 0px;
        width: 100px;
        height: 100px;

        background-color: orange;
    }

    .middle {
        position: absolute;
        top: 50%;
        left: 50%;
        width: 100px;
        height: 100px;
        background-color: black;
        transform: translate(-50%, -50%);
    }
    </style>
</head>

<body>
    <div class="main">
        <div class="topleft"></div>
        <div class="topright"></div>
        <div class="bottomleft"></div>
        <div class="bottomright"></div>
        <div class="middle"></div>
    </div>
</body>

</html>


Thứ Năm, 1 tháng 8, 2019

Icon using FontAwesome Package

Thư viện

        
font_awesome_flutter: ^8.4.0
        
    

Code:

        
import 'package:font_awesome_flutter/font_awesome_flutter.dart';

Widget _yourAwesomeIcon() {
  return Icon(
    FontAwesomeIcons.school,
    color: Colors.blue,
  );
}
        
    

Thứ Tư, 31 tháng 7, 2019

Add plugin Sublime Text 3

VD: Sublime Highlight:
 https://apple.stackexchange.com/questions/337862/install-sublimehighlight-plugin-on-sublime-text-3



I found the answer in another post: https://stackoverflow.com/a/39432069/3511695
  1. Install Package Control inside sublime text 3. If you don't know how, follow this link here
  2. Open the Sublime Command Pallette by pressing CTRL+SHIFT+P on Windows and ⌘⇧P on Mac
  3. Type "Add Repository", and press enter or return
Then paste this link https://github.com/n1k0/SublimeHighlight/tree/python3 [and press enter]
  1. Press CTRL+SHIFT+P on Windows and ⌘⇧P on Mac again and type "Install package" and press enter or return
  2. Type "Sublime highlight" and press enter to install the plugin
  3. Restart your Sublime

Thứ Năm, 25 tháng 7, 2019

Blogger Code Mẫu

<head>
    <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.15.8/styles/googlecode.min.css" />
    <script src="https://pastebin.com/raw/ADKB4pKc"></script>
    <script>
        hljs.initHighlightingOnLoad()
    </script>
    <style>
        .hljs, pre, code{
            padding: 0;
            margin: 0;
        }
        code{
            font-size: 15px;
        }
        .bold {
            font-weight: bold;
        }
    </style>
</head>
<body>
    <p></p>
    <p>Code:</p>
    <pre>
        <code class="dart">
            <!-- YOUR CODE -->
        </code>
    </pre>
</body>

Thứ Ba, 16 tháng 7, 2019

XML to C# class và ngược lại

A. XML to C# class

Dùng tool online: https://xmltocsharp.azurewebsites.net/

+ Chuẩn hóa chuỗi XML trước khi dùng tool trên:
Tạo app Winform để add tag đóng vào XML:

Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace AutoCloseXMLTag
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnAddCloseTag_Click(object sender, EventArgs e)
        {
            txtOutput.Clear();

            var lines = txtInput.Text.Split('\n').ToList();
            List<string> linesChuanHoa = new List<string>();

            //add chuỗi có tag đóng
            foreach (var line in lines)
            {
                string strRegex = @"[\t]+";
                Regex myRegex = new Regex(strRegex, RegexOptions.None);
                string strReplace = @"";


                String temp = line;
                String tempRegex = myRegex.Replace(temp, strReplace).Trim();
                if (tempRegex.Contains("</"))
                    linesChuanHoa.Add(tempRegex);

            }

            foreach (var line in lines)
            {
                // MessageBox.Show(line);

                string strRegex = @"[\t]+";
                Regex myRegex = new Regex(strRegex, RegexOptions.None);
                string strReplace = @"";


                String temp = line;
                String tempRegex = myRegex.Replace(temp, strReplace).Trim();
                //MessageBox.Show("-"+temp+"-");
                if (!tempRegex.Contains(@"</") && !linesChuanHoa.Contains("</" + tempRegex.Replace("<", "")))
                {
                    txtOutput.AppendText(temp + tempRegex.Replace("<", "</") + "\r\n");
                }
                else
                {
                    txtOutput.AppendText(temp + "\r\n");
                }
            }
        }
    }
}

**Lưu ý nhớ test Validate XML: https://www.freeformatter.com/xml-validator-xsd.html

B. C# class to XML:

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Serialization;

namespace XMLtoCSharp
{
    class Program
    {
        static void Main(string[] args)
        {
            Customer c = new Customer("a", "b");
            string xml = ToXML(c);
            Console.Write(xml);

            Console.ReadKey();
        }

        public static string ToXML<T>(T obj)
        {
            using (var stringwriter = new System.IO.StringWriter())
            {
                var serializer = new XmlSerializer(typeof(T));
                serializer.Serialize(stringwriter, obj);
                return stringwriter.ToString();
            }
        }

        public static Customer LoadFromXMLString(string xmlText)
        {
            using (var stringReader = new System.IO.StringReader(xmlText))
            {
                var serializer = new XmlSerializer(typeof(Customer));
                return serializer.Deserialize(stringReader) as Customer;
            }
        }
    }

    //TOOL ONLINE: xml to C#: https://xmltocsharp.azurewebsites.net/

    [XmlRoot(ElementName = "CustomerKK")]
    public class Customer
    {
        [XmlElement(ElementName = "CustomerIDDD")]
        public string CustomerID { get; set; }

        [XmlElement(ElementName = "ContactName")]
        public string ContactName { get; set; }

        public Customer(String CustomerID, String ContactName)
        {
            this.CustomerID = CustomerID;
            this.ContactName = ContactName;
        }
        public Customer() { }

        public string ToXML()
        {
            using (var stringwriter = new System.IO.StringWriter())
            {
                var serializer = new XmlSerializer(this.GetType());
                serializer.Serialize(stringwriter, this);
                return stringwriter.ToString();
            }
        }

        public static Customer LoadFromXMLString(string xmlText)
        {
            using (var stringReader = new System.IO.StringReader(xmlText))
            {
                var serializer = new XmlSerializer(typeof(Customer));
                return serializer.Deserialize(stringReader) as Customer;
            }
        }
    }

}

Thứ Hai, 15 tháng 7, 2019

Firebase Push Notification in Flutter

1. Postman:

1. Method: POST
2. URL: https://fcm.googleapis.com/fcm/send
3. Headers:
Content-Type: application/json
Authorization: key=your_key
4. Body raw json:
{
    "to": "/topics/191448148",
    "collapse_key": "type_a",
    "notification": {
        "title": "TieuDe",
        "body": "NoiDung",
        "sound": "Enabled"

    },
    "data": {
        "title": "TieuDe",
        "body": "NoiDung",
        "dichvu": "1",
        "chucnang": "giaoduc",
        "chucnangid": "thongbao",
        "click_action": "FLUTTER_NOTIFICATION_CLICK"
    },
    "priority": "high"
}
5. Response json when success:
{
    "message_id": 607975690105141
}

2. C# code:

private void FirebasePush() {
    try {
        applicationID = "YOUR_KEY"; // legacy server key firebase
        string senderId = "YOUR_ID";

        WebRequest tRequest = WebRequest.Create("https://fcm.googleapis.com/fcm/send");
        tRequest.Method = "post";
        tRequest.ContentType = "application/json";
        var dataSend = new {
            to = "/topics/" + "TenTaiKhoan",
            collapse_key = "type_a",
            notification = new {
                title = row["TieuDe"],
                body = row["NoiDung"],
                sound = "Enabled"
            },
            data = new {
                title = row["TieuDe"],
                body = row["NoiDung"],
                dichvu = row["DichVu"],
                chucnang = row["ChucNang"],
                chucnangid = row["ChucNangID"],
                click_action = "FLUTTER_NOTIFICATION_CLICK"
            },
            priority = "high"
        };

        var serializer = new JavaScriptSerializer();
        var json = serializer.Serialize(dataSend);
        Byte[] byteArray = Encoding.UTF8.GetBytes(json.ToString());

        tRequest.Headers.Add(string.Format("Authorization: key={0}", applicationID));
        tRequest.Headers.Add(string.Format("Sender: id={0}", senderId));
        tRequest.ContentLength = byteArray.Length;

        using(Stream dataStream = tRequest.GetRequestStream()) {

            dataStream.Write(byteArray, 0, byteArray.Length);
            using(WebResponse tResponse = tRequest.GetResponse()) {
                using(Stream dataStreamResponse = tResponse.GetResponseStream()) {
                    using(StreamReader tReader = new StreamReader(dataStreamResponse)) {
                        String sResponseFromServer = tReader.ReadToEnd();
                        string str = sResponseFromServer;
                        //Execute StoreProcedure
                        /*HERE*/
                    }
                }
            }
        }
    }
    catch {}
    Thread.Sleep(5000); // 5giay
}

20 Tech News Website

9to5Mac.com
Appleinsider.com
Arstechnica.com --
Cnet.com
Digitaltrends.com
Engadget.com
Gadgetsnow.com --
Gizmodo.com
LifeHacker.com
Macrumors.com
Mashable.com --
NewYorkTimes.com
Pcmag.com --
Tech2.com
Techcrunch.com --
Techradar.com --
Thenextweb.com
Theverge.com --
Tomshardware.com
Wired.com