My colleague shared me a good trick on how you can copy a file with cmd, means you can do it even if it is half way being written by a program. But you will only have the content as per the moment it is duplicated.
1) C:\yourUsers > pushd \\TheFolderPath
2) D:\THePath> type fileName.txt > newFileName.txt
DONE!
Showing posts with label Programming. Show all posts
Showing posts with label Programming. Show all posts
Thursday, May 2, 2019
Tuesday, August 11, 2015
Bootstrap
a.k.a twitter bootstrap.
This is one of the most famous platform recently, mainly because it fully the single responsive design.
Responsive design means you will see your web design as a fluid and the browser or device as a container. The fluid will fit into any container that you fill them to. With the rapid grow of internet, a lot of web wants to emerge in the shortest time in most of the device available.
This platform attract a lot of user because of the flexibility in fitting all device that we have, deskstop , mobile and tablet.
This is one of the most famous platform recently, mainly because it fully the single responsive design.
Responsive design means you will see your web design as a fluid and the browser or device as a container. The fluid will fit into any container that you fill them to. With the rapid grow of internet, a lot of web wants to emerge in the shortest time in most of the device available.
This platform attract a lot of user because of the flexibility in fitting all device that we have, deskstop , mobile and tablet.
Saturday, July 18, 2015
Break vs continue
It is very important to know the differences between this
two, especially in the loop.
If you use break, you will go out from the loop;
If you use continue, you will continue to the next looped
item.
Sunday, June 28, 2015
what is the default constructor for parameter in C#?
default constructor C# private or public?
Default constructor for C#, if it is not specificed, is private.
you can test it via
public class TestConstructor
{
public string title2 = string.Empty;
string title = string.Empty;
}
you will found that when you
TestConstructor tc = new TestConstructor();
tc.title2 ==> this is valid in the intellisence
tc.title ==> TestConstructor.title' is inaccessible due to its protection level
tc.somethingNotExist ==> TestConstructor does not contain a definition for 'somethingNotExist' and no extension method 'somethingNotExist' accepting a first argument of type 'TestConstructor' could be found (are you missing a using directive or an assembly reference?)
Default constructor for C#, if it is not specificed, is private.
you can test it via
public class TestConstructor
{
public string title2 = string.Empty;
string title = string.Empty;
}
you will found that when you
TestConstructor tc = new TestConstructor();
tc.title2 ==> this is valid in the intellisence
tc.title ==> TestConstructor.title' is inaccessible due to its protection level
tc.somethingNotExist ==> TestConstructor does not contain a definition for 'somethingNotExist' and no extension method 'somethingNotExist' accepting a first argument of type 'TestConstructor' could be found (are you missing a using directive or an assembly reference?)
Wednesday, June 24, 2015
how to make grid to show 100% for xaml?
I had a little struggle to archive this, finally found that it is just as simple as setting both HorizontalAlignment and VerticalAlignment = "Stretch".
also if you have separate your grid to 3 column, set your Grid.ColumnSpan="3";
finally, remember to set MinHeight="" and MinWidth="" instead of height n width.
happy coding.
also if you have separate your grid to 3 column, set your Grid.ColumnSpan="3";
finally, remember to set MinHeight="" and MinWidth="" instead of height n width.
happy coding.
Monday, June 22, 2015
string to array, array to string via string builder.
Change comma separated string to array of string.
separate the string with comma into an array.
eg:
private void validateCompanyList()
{
//txtCompany output = "Company1, company2, company3,company4";
string[] companyList = txtCompany.Text.Split(',').ToArray();
if (companyList.Count() > 0)
{
foreach (string company in companyList)
{
//eg: 1st iteration => company = "Company1"
// 2nd: company = " company2"
// 3rd : company = " company3"
// 4th : company = "company4"
//if you take the company.trim(), then you will get
// 1st: company.trim() = "Company1"
// 2nd: company.trim() = "company2"
// 3rd: company.trim() = "company3"
// 4th: company.trim() = "company4"
}
}
}
you can then use stringBuilder to join back the company into a string.
for example:
using System.Text;
private void validateCompanyList()
{
if (string.IsNullOrWhiteSpace(txtCompany.Text))
return;
string[] companyList = txtCompany.Text.Split(',').ToArray();
StringBuilder sbErrorMsg = new StringBuilder();
if (companyList.Count() > 0)
{
foreach (string company in companyList)
{
int found = CompanyObject.Where(t=> t.COMPANY_CODE == company.Trim().ToUpper() && t.REC_DELETED == Constant.RECORD_ACTIVE).Count();
if (found == 0)
{
if (sbErrorMsg.Length != 0)
sbErrorMsg.Append(",");
sbErrorMsg.Append(company.Trim());
}
}
}
if (sbErrorMsg.Length != 0)
{
ErrorMessage.errorMessageControl(string.Concat("Invalid company code(s) : " , sbErrorMsg));
}
}
Beside text.split(','); you can also take a look at text.split(new char[] { ',' }, StringSplitOptions), where you can choose StringSplitOptions.None or StringSplitOptions.RemoveEmptyEntries.
let's take a look at the second option :
string[] companySpliter = txtCompany.Text.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
With this option, the return value doesn't not include array element that is empty string. This is a very good way if you want to exclude null string in array after split.
eg: txtCompany.Text = ",,,,,,";
companySpliter.length is 0 for this case.
while string[] companySpliter2 = txtCompany.Text.Split( ',' );
will have companySpliter2.length equal to 7, with all the child element having string.Empty.
However, StringSplitOptions.RemoveEmptyEntries will not exclude child element that contain only space(s).
eg: txtCompany.Text = " , ";
companySpliter.length is 2 for this case.
same with string[] companySpliter2 = txtCompany.Text.Split( ',' );
which will have companySpliter2.length equal to 2.
You will still need string.IsNullOrWhiteSpace(company) to check while looping the array if you wish to ignore the spaces.
separate the string with comma into an array.
eg:
private void validateCompanyList()
{
//txtCompany output = "Company1, company2, company3,company4";
string[] companyList = txtCompany.Text.Split(',').ToArray();
if (companyList.Count() > 0)
{
foreach (string company in companyList)
{
//eg: 1st iteration => company = "Company1"
// 2nd: company = " company2"
// 3rd : company = " company3"
// 4th : company = "company4"
//if you take the company.trim(), then you will get
// 1st: company.trim() = "Company1"
// 2nd: company.trim() = "company2"
// 3rd: company.trim() = "company3"
// 4th: company.trim() = "company4"
}
}
}
you can then use stringBuilder to join back the company into a string.
for example:
using System.Text;
private void validateCompanyList()
{
if (string.IsNullOrWhiteSpace(txtCompany.Text))
return;
string[] companyList = txtCompany.Text.Split(',').ToArray();
StringBuilder sbErrorMsg = new StringBuilder();
if (companyList.Count() > 0)
{
foreach (string company in companyList)
{
int found = CompanyObject.Where(t=> t.COMPANY_CODE == company.Trim().ToUpper() && t.REC_DELETED == Constant.RECORD_ACTIVE).Count();
if (found == 0)
{
if (sbErrorMsg.Length != 0)
sbErrorMsg.Append(",");
sbErrorMsg.Append(company.Trim());
}
}
}
if (sbErrorMsg.Length != 0)
{
ErrorMessage.errorMessageControl(string.Concat("Invalid company code(s) : " , sbErrorMsg));
}
}
Beside text.split(','); you can also take a look at text.split(new char[] { ',' }, StringSplitOptions), where you can choose StringSplitOptions.None or StringSplitOptions.RemoveEmptyEntries.
let's take a look at the second option :
string[] companySpliter = txtCompany.Text.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
With this option, the return value doesn't not include array element that is empty string. This is a very good way if you want to exclude null string in array after split.
eg: txtCompany.Text = ",,,,,,";
companySpliter.length is 0 for this case.
while string[] companySpliter2 = txtCompany.Text.Split( ',' );
will have companySpliter2.length equal to 7, with all the child element having string.Empty.
However, StringSplitOptions.RemoveEmptyEntries will not exclude child element that contain only space(s).
eg: txtCompany.Text = " , ";
companySpliter.length is 2 for this case.
same with string[] companySpliter2 = txtCompany.Text.Split( ',' );
which will have companySpliter2.length equal to 2.
You will still need string.IsNullOrWhiteSpace(company) to check while looping the array if you wish to ignore the spaces.
Friday, June 19, 2015
IsNullOrEmpty better or IsNullOrWhiteSpace better?
IsNullOrEmpty vs IsNullOrWhiteSpace
Are you also thinking , is IsNullOrEmpty better or IsNullOrWhiteSpace better?
The answer is IsNullOrWhiteSpace, unless you want to accept space (" ") or spaces(" ") as valid input.
The reason is IsNullOrWhiteSpace will validate (" ") as true, while IsNullOrEmpty required you to trim the string inorder to validate it the empty space. If you trim a string that is null, you will get exception.
Before the introduce of IsNullOrWhiteSpace , the usual way checking might be:
if(!string.IsNullOrEmpty(stringA))
if (stringA.Trim().Length != "")
dataSavingForExample;
IsNullOrWhiteSpace : lesser code, safer for empty space checking and better performance. :)
Are you also thinking , is IsNullOrEmpty better or IsNullOrWhiteSpace better?
The answer is IsNullOrWhiteSpace, unless you want to accept space (" ") or spaces(" ") as valid input.
The reason is IsNullOrWhiteSpace will validate (" ") as true, while IsNullOrEmpty required you to trim the string inorder to validate it the empty space. If you trim a string that is null, you will get exception.
Before the introduce of IsNullOrWhiteSpace , the usual way checking might be:
if(!string.IsNullOrEmpty(stringA))
if (stringA.Trim().Length != "")
dataSavingForExample;
IsNullOrWhiteSpace : lesser code, safer for empty space checking and better performance. :)
Sunday, January 25, 2015
the .NET babies: Visual basic & C#
While you have a few years of experience for one of the language ( VB or C#), you might found some time is needed for yourself when you want to code another language. It is easy to read and understand them but when it comes to write, you might become not as fast as when you code using the other language. This is because of the syntax! (It makes me felt that this is just like some people can understand Cantonese but cannot speak in Cantonese. hehe..)
First, C# is case sensitive while VB is case insensitive.
So,
you can do this to C# ==> Var i = 1; Var I = 10;
But,
you cannot do this to VB ==> Dim i as Integer = 1 Dim I as Integer = 10
the compiler will definitely complain about double declaration.
First, C# is case sensitive while VB is case insensitive.
So,
you can do this to C# ==> Var i = 1; Var I = 10;
But,
you cannot do this to VB ==> Dim i as Integer = 1 Dim I as Integer = 10
the compiler will definitely complain about double declaration.
Wednesday, January 7, 2015
Object Oriented programming
Module is a collection of classes,
Class is a definition,
and Object is a collection of data.
The object is actually an instance of class, it is 'born' based on the definition of the class. While module is a collection of classes.
This is for biology lover:
We have Kingdom, Family , Genus .....( I forgotten what I had memorized during high school)..
what makes those Families under that Kingdom is due to they have some similarities, but each of them is different.
For example, human and chimpanzee are under Hominidae, both is warm blood , about similar structure. In programming, human and chimpanzee inherit the definition in the Hominidae. Let's imagine them as each individual class. Human can walk, Chimpanzee can walk, Human extend from the base class and have something they have but Chimpanzee doesn't has.
in code: class Human(Hominidae)
Human us a derive class and Hominidae is a base class.
In the human class, we have each individual human , just like U and I. We are an object , that is an instance of the human. We represent the human. ( object is a collection of data based on class)
Now, move a level up, before Hominidae, we have a super family which can act as module. Module is a collection of classes.
I had the idea after this interesting video that describe OOP with the city planner example. Here is the link.: https://www.youtube.com/watch?v=P1WcKEgvRFE
Usually, this concept is widely practice when a programmer do programming, but one mey notknow how to explain it. I normally will have a class contain all related functions. It is more manageable and cleaner in this way. For each function, try to let it only have a "mission" to archive.
Programming is an art. :)
Class is a definition,
and Object is a collection of data.
The object is actually an instance of class, it is 'born' based on the definition of the class. While module is a collection of classes.
This is for biology lover:
We have Kingdom, Family , Genus .....( I forgotten what I had memorized during high school)..
what makes those Families under that Kingdom is due to they have some similarities, but each of them is different.
For example, human and chimpanzee are under Hominidae, both is warm blood , about similar structure. In programming, human and chimpanzee inherit the definition in the Hominidae. Let's imagine them as each individual class. Human can walk, Chimpanzee can walk, Human extend from the base class and have something they have but Chimpanzee doesn't has.
in code: class Human(Hominidae)
Human us a derive class and Hominidae is a base class.
In the human class, we have each individual human , just like U and I. We are an object , that is an instance of the human. We represent the human. ( object is a collection of data based on class)
Now, move a level up, before Hominidae, we have a super family which can act as module. Module is a collection of classes.
I had the idea after this interesting video that describe OOP with the city planner example. Here is the link.: https://www.youtube.com/watch?v=P1WcKEgvRFE
Usually, this concept is widely practice when a programmer do programming, but one mey notknow how to explain it. I normally will have a class contain all related functions. It is more manageable and cleaner in this way. For each function, try to let it only have a "mission" to archive.
Programming is an art. :)
Thursday, January 1, 2015
3 DES - Security / encryption
3DES
- Triple data encryption Algorithm
-Encrypts data 3 times using 64-bit keys
-symmetric-key block cipher
-widely use on electronic payment.
- Triple data encryption Algorithm
-Encrypts data 3 times using 64-bit keys
-symmetric-key block cipher
-widely use on electronic payment.
RSA - Security / encryption
RSA is public key encryption that used for data sending over internet.
- It is well known industry strength encryption, this 'recognition' is given based on the fact that there is no easy way to factor very large number. To factor a very large amount of computer processing time and power is needed.
- Uses asymmetric cryptography algorithm i.e. it uses two different key to achieve encryption.
- Also know as public key cryptography because the give is given to everyone, to the public. The private key is kept privately, private key is a prime factor. With the public key, everyone / anyone can encrypt the message and reply. Only the person that know the private key can use the factor to decode the message.
- For example(just as an example) : public key = A, message = B,
user will send the result of A * B to me and I will use C mode A to get message as B .
- It is well known industry strength encryption, this 'recognition' is given based on the fact that there is no easy way to factor very large number. To factor a very large amount of computer processing time and power is needed.
- Uses asymmetric cryptography algorithm i.e. it uses two different key to achieve encryption.
- Also know as public key cryptography because the give is given to everyone, to the public. The private key is kept privately, private key is a prime factor. With the public key, everyone / anyone can encrypt the message and reply. Only the person that know the private key can use the factor to decode the message.
- For example(just as an example) : public key = A, message = B,
user will send the result of A * B to me and I will use C mode A to get message as B .
Wednesday, December 31, 2014
Warm start-up and Cold start-up
Warm start up
-time taken to start application that launched in the recent past (no reboot in between)
(just like the time taken to do something after woke up from long sleep)
Cold start up
-the time taken to start application after machine reboot, i.e. the first launch after reboot.
-depends on the number of pager need to be fetched from disk.
(just like the time taken to do something after reborn)
-time taken to start application that launched in the recent past (no reboot in between)
(just like the time taken to do something after woke up from long sleep)
Cold start up
-the time taken to start application after machine reboot, i.e. the first launch after reboot.
-depends on the number of pager need to be fetched from disk.
(just like the time taken to do something after reborn)
what is JIT( just in time ) ?
If you are doing some reading regarding to the compilation of codes, you will of cause or should come across this word, "JIT".
As mentioned by itself, just in time compilation happen just at the time when it is needed.
I did some searching and finally landed on a MSDN article to understand more about JIT.
Why JIT is 'born'?
- to improve the first access performance.
When the loader only load and compile during runtime for the needed assemblies, it allows the application to start up quicker compare to those application that is use interpreter or native compiler. But is it always improve for both cold and warm start up? Read further on the blog to get more insight.
How does JIT works?
- use late binding to load only when it is needed.
As mentioned by itself, just in time compilation happen just at the time when it is needed.
I did some searching and finally landed on a MSDN article to understand more about JIT.
Why JIT is 'born'?
- to improve the first access performance.
When the loader only load and compile during runtime for the needed assemblies, it allows the application to start up quicker compare to those application that is use interpreter or native compiler. But is it always improve for both cold and warm start up? Read further on the blog to get more insight.
How does JIT works?
- use late binding to load only when it is needed.
Subscribe to:
Posts (Atom)