Skip to content

Instantly share code, notes, and snippets.

View longtth's full-sized avatar

Long Nguyen longtth

View GitHub Profile
@longtth
longtth / cau-truc-folder-du-an.txt
Created October 8, 2018 13:54
cấu trúc folder dự án
projects
project-1
docs
managements
trong này là các file quản lý như wbs, tasklist, issue list..
requirements
trong này là requirement của dự án
resources
trong này là các file design, hoặc các thư viện cần dùng, tool cần dùng nếu không dùng package management
nếu làm .NET thì mình dùng nuget thì hầu như không cần dùng cái này.
[HttpPost]
public ActionResult Index(IEnumerable<HttpPostedFileBase> files)
{
bool successUpload = false;
string datetime = DateTime.Now.ToString("yyyyMMdd_hhmmss");
var path = Path.Combine(Server.MapPath("~/App_Data"), datetime);
foreach (var file in files)
{
if (file?.ContentLength > 0)
@longtth
longtth / README.md
Created October 4, 2018 06:52 — forked from hofmannsven/README.md
My simply MySQL Command Line Cheatsheet
@longtth
longtth / DirSize.cs
Created October 2, 2018 08:11
Get size of directory
public static long DirSize(DirectoryInfo d)
{
long size = 0;
// Add file sizes.
FileInfo[] fis = d.GetFiles();
foreach (FileInfo fi in fis)
{
size += fi.Length;
}
// Add subdirectory sizes.
@longtth
longtth / Remove-item-from-one-list-in-another.md
Last active August 29, 2018 03:52
Lọc một list khỏi 1 list khác

You can use Except:

List<car> list1 = GetTheList();
List<car> list2 = GetSomeOtherList();
List<car> result = list2.Except(list1).ToList();

You probably don't even need those temporary variables:

List<car> result = GetSomeOtherList().Except(GetTheList()).ToList();
@longtth
longtth / VM-khong-tu-nhan-IP-theo-DCHP-cua-host.md
Created August 28, 2018 17:42
VM không tự nhận IP theo range của host

Một ngày đẹp trời, install xong VM Ubuntu server, nhấn ifconfig và mãi nó chẳng chịu ăn cái IP 192.168.56.x như "bình thường" cho mà cứ dính chặt vô cái IP 10.0.2.x. Vậy thì hãy thử bật cái lệnh này lên:

ip addr

Thật không may nếu như bạn thấy cái dòng lỗi này

mtu 1500 qdisc noop state down group default qlen 1000

Trong trường hợp đó, vậy thì "gọi hồn" cái network adapter dậy bằng 2 lệnh này thôi:

@longtth
longtth / ListToExcel.cs
Last active August 27, 2018 11:21
Lưu list thành excel
List<Info> list = new List<Info>();
foreach (var file in files)
{
Info info = new Info()
{
FileName = Path.GetFileNameWithoutExtension(file),
Duration = GetLength(file)
};
list.Add(info);
}
@longtth
longtth / DataGridViewCheckNull.cs
Created July 5, 2018 13:35
C# Check null datagridview
foreach (DataGridViewRow rw in this.dataGridView1.Rows)
{
for (int i = 0; i < rw.Cells.Count; i++)
{
if (rw.Cells[i].Value == null || rw.Cells[i].Value == DBNull.Value || String.IsNullOrWhiteSpace(rw.Cells[i].Value.ToString()))
{
// here is your message box...
}
}
}
@longtth
longtth / DataGridViewLoopCell.cs
Created July 5, 2018 02:30
Chạy qua tất cả các cell trong GridView để xử lý với nó.
foreach(DataGridViewRow row in yourDataGridView.Rows)
{
foreach(DataGridViewCell cell in row.Cells)
{
//do operations with cell
}
}
@longtth
longtth / StringExtension.cs
Last active July 1, 2018 15:18
1 cái Extension Method để extend cái class String, vẫn chép từ SO
// You can use an extension method:
public static class StringExtension
{
public static string GetLast(this string source, int tail_length)
{
if(tail_length >= source.Length)
return source;
return source.Substring(source.Length - tail_length);
}