The fastest speed home broadband -NBN
I came from Hong Kong. The high-speed internet is an essential item at home. A lot of my friends in Hong Kong got 100Mbps internet at home, some of them got 1Gbps. What Even I have heard about the fastest speed is 20Gbps in Hong Kong, that is crazy. I believe Hong Kong is the highest density of optic fiber networks. In contrast, Australia population are more density. Even in the urban area, the population is less density than Hong Kong. Thus, we need to spend money on the infrastructure, but fewer people can use, comparing to Hong Kong.
I have used ADSL2+ for 10 ten years. Normally, that is 6Mbps download. Nowadays, even 4G is faster this speed. Recently, NBN is finally available in my area. Then I ordered an upgrade from ADSL2+ to NBN. The NBN I can have is the best option which is fiber to the premise. That is not using the old copper telephone line. Therefore, rewiring is required. The NBN Co. Technicians did wiring from outside my house to my living room where my router is siting. Then they installed an NBN box which is a kind of optical fiber modem. Finally, my router and phone need to connect to this box. Then I got the fastest speed broadband is 100Mbps download, 40Mbps upload. Well, I need to pay $30 extra per month. Unless, I only can get 12Mbps download and 1Mbps Upload.
That is a bit downside to use NBN, we have to use VOIP over NBN, the old copper phone line will be phased out. In Australia, if the area has NBN, the phone line will be phased out within a year after the date of NBN activated in your area.
[Example Code]: Simple Validation Framework
Recently, I built a simple validation framework which can work with WPF. I found I can use class attribute and reflection to achieve this purpose.
Firstly, I define a Required Attribute to see whether the property requires a value
Code
[AttributeUsage(AttributeTargets.All)] | |
public class RequiredAttribute : System.Attribute | |
{ | |
public readonly bool Required; | |
| |
public RequiredAttribute(bool required) | |
{ | |
this.Required = required; | |
} | |
| |
} |
Then I add IsValid method in the class, it will use the reflect to get all properties in this class. Then it will check whether the property has "required=true", if that is the case, it will check whether the property has value, if not, it will use an error.
public class PersonModel
{
[Required(true)]
public string Name {get;set;}
public IList IsValid()
{
IList ret = new List();
foreach (var prop in this.GetType().GetProperties())
{
foreach(Attribute attr1 in prop.GetCustomAttributes(typeof(RequiredAttribute),true)){
RequiredAttribute attr = (RequiredAttribute) attr1;
if (attr != null) {
if (attr.Required)
{
if (string.IsNullOrEmpty(Convert.ToString(prop.GetValue(this, null)))) {
ret.Add(string.Format("{0} is required",prop.Name));
}
}
}
}
}
return ret;
}
}
is the best practice. I cannot think another way can do it easier.
Please click here to download the example code.
Asynchronous method to update UI element in Xamarin
I got an app to call api in my server for loading the data. This make sense to use asynchronous methods for loading the data. I don't want the whole UI is locked for waiting the data. But I found
model.GetData().ContinueWith((items) =>
{
list.ItemSource= items;
});
It won't works. I found the reason is all Asynchronous methods are executed by a different thread. You have to call UI main thread to bind the data to UI.
model.GetData().ContinueWith((items) =>
{
evice.BeginInvokeOnMainThread(() =>
{
list.ItemSource= items;
});
});;
PHP Square Bracket Errors
I built a wordpress plug-in. The plug-in is working fine in a server, but another server returned an error about '[. I compared the two servers. Their php is different. The problematic server got old version of php which is php .5.3. Then I read the php specification. The Square Bracket array declaration which used in C# and Java is only available on Php >=5.4. So I have to change square brackets to array(). Then it works fine.
The Database Object in WordPress
You can access the database via WordPress. You can use any raw SQL too. That is quite easy. You only need to call a global object;
global $wpdb;
For the raw SQL, you can use query method:
$wpdb->query(
"
UPDATE $wpdb->posts
SET post_parent = 10
WHERE ID = 15
"
);
For get the record set,
$drafts = $wpdb->get_results(
"
SELECT *
FROM $wpdb->posts
WHERE post_status = 'draft'
AND post_author =1
"
);
There are insert, update and delete method too.
Please read WordPress development documentation for the further information