Thứ Ba, 24 tháng 4, 2012

Bị đảo ngược phím Fn trong Laptop

Hồi chiều khi mới về, bấm phím m, tự nhiên hiển thị lên số 0, nhòm lại mới biết bị lỗi đảo ngược phím Fn.
Hơi hoang mang 1 chút, sau đó lên mạng tìm hiểu, và mới phát hiện ra một cách khắc phục rất là đơn giản. Chỉ cần tắt phím Num lock đi là được ^^.

Thứ Tư, 11 tháng 4, 2012

Một số link lưu ý

Link học .net cơ bản: www.dotnetperls.com

Code hight light cho blog

Insert đoạn này trong body





Cách dùng xem trên đây:
 http://alexgorbatchev.com/SyntaxHighlighter/manual/installation.html
Đây là cách dùng thông thường nhất:
    /**
     * SyntaxHighlighter
     */
    function foo()
    {
        if (counter <= 10)
            return;
        // it works!
    }

Kỹ thuật Reflection C#

Theo mình thấy, Reflection dùng để xác định kiểu của Object mà bạn đưa vào, và nếu như lấy giá trị của đối tượng thất bại, sẽ trả về null hoặc là giá trị nào đó do mình gán.

Ban đầu mình làm 3 hàm như sau:

    
public JsonResult ViewTempByGuid(Guid name)
{
    var image = Context.Database.Files_Temporary.FirstOrDefault(f => f.TemporaryGuid == name);
    var filePathResult =
        new FilePathResult(
            FileManagerRepository.GetPathFromObjectType(enumObjectContentType.Temporary) + "\\" + image.RealFileName,
            DpnTools.GetMIMEType(image.RealFileName));
    var img = Image.FromFile(filePathResult.FileName);
    var resizedImage = ImageHelper.ResizeImage(img, 800, 600);
    var base64 = "data:image/png;base64," + ImageHelper.ImageToBase64(resizedImage, ImageFormat.Png);

    return Json(new { base64 }, JsonRequestBehavior.AllowGet);
}

public JsonResult ViewTemp(Guid name, int left, int top)
{
    var image = Context.Database.Files_Temporary.FirstOrDefault(f => f.TemporaryGuid == name);
    var filePathResult =
        new FilePathResult(
            FileManagerRepository.GetPathFromObjectType(enumObjectContentType.Temporary) + "\\" + image.RealFileName,
            DpnTools.GetMIMEType(image.RealFileName));
    var img = Image.FromFile(filePathResult.FileName);
    var resizedImage = ImageHelper.ResizeImage(img, 72, 54);
    var base64 = "data:image/png;base64," + ImageHelper.ImageToBase64(resizedImage, ImageFormat.Png);

    return Json(new { name, base64, left, top }, JsonRequestBehavior.AllowGet);
}

////[HttpPost]
public string ShowCameraThumb(int id)
{
    var image = Context.Database.Files_Uploaded.FirstOrDefault(f => f.ID == id);
    var filePathResult =
        new FilePathResult(
            FileManagerRepository.GetPathFromObjectType(enumObjectContentType.CameraSpot) + "\\" + image.RealFileName,
            DpnTools.GetMIMEType(image.RealFileName));
    var img = Image.FromFile(filePathResult.FileName);
    var resizeImage = ImageHelper.ResizeImage(img, 72, 54);
    var base64 = "data:image/png;base64," + ImageHelper.ImageToBase64(resizeImage, ImageFormat.Png);
    return base64;
}
Vì thấy 3 hàm trên xử lý quá giống nhau, nên muốn viết nó thành một hàm, tất nhiên chưa nhiều đến mức để nghĩ đến việc viết theo hướng đối tượng, và mình đã dùng Reflection như ở dưới
public static string ConvertImageToBase64(Object o, int type=0)//2
{
    //enumObjectContentType enumObjectContentType = enumObjectContentType.Temporary;
    var enumObjectContentType = o.GetType().GetProperty("EnumObjectContentType").GetValue(o, null);
    var realFileName = o.GetType().GetProperty("RealFileName").GetValue(o, null);
    var width = 72;
    var height = 54;
    if (type == 2)
    {
        width = 800;
        height = 600;
    }
    var filePathResult =
        new FilePathResult(
            FileManagerRepository.GetPathFromObjectType((enumObjectContentType) enumObjectContentType) + "\\" +
            realFileName, DpnTools.GetMIMEType(realFileName.ToString()));
    return "data:image/png;base64," +
            ImageHelper.ImageToBase64(
                ImageHelper.ResizeImage(Image.FromFile(filePathResult.FileName), width, height), ImageFormat.Png);
}
Và sử dụng như sau:
var image = Context.Database.Files_Temporary.FirstOrDefault(f => f.TemporaryGuid == name);
var base64 = AcceptanceRepository.ConvertImageToBase64(image); 
Khi đó, object sẽ tự xác định type.

Thứ Hai, 9 tháng 4, 2012

ShellNewHandler project page

So what is this ShellNewHandler thing?
GUI Tool to enable/disable ShellNew entrys, aka the New File context menu entrys from Windows Explorer in Windows Vista and Windows 7.
How does it work?
Simple check or uncheck an item to enable a desktop right-click context menu item.
Requirements?
No need to install. Standalone exe written in C# for .NET 2.0. Designed for Windows Vista and higher OS.
Why developing such a thing?
Because i just found me at a point in time where i just want to clean up my context menu and remove the unwanted entrys from New File Menu and look on internet and all i found was shareware, tipps how to do this with TweakUI for XP in legacy mode and hints to search in registry and modify registry entrys by hand. After that i decided to develop a app primary for myself, then i remember the cool and useful sourceforge site and all the advantages and helpers i found in years and friends told me maybe its a good idea to share this app with the world.
So maybe this is just Yet Another App that the world don't need and don't look for, but hey, why not? Feel free to post your comments about this useless or useful thing and take the source and use or modify or just drop it in recycle bin in any way you like.

How to Add Any Application to the Windows Desktop Right-Click Menu

image
If you want really quick access to launch a frequently used application without putting extra icons on your desktop, you can add that application to the context menu for the desktop with a simple registry hack. Here’s how to do it.
Naturally, we’ve also covered the opposite scenario—how to clean up your messy Windows context menu, which is an equally useful read if you’ve got a bunch of items you want to remove from the menu.
Note: this article was originally published a few years ago, but we’ve updated and polished it for Windows 7 and are republishing it for you today.

.delegate in jquery

.delegate in jquery
đính kèm một handler (1 sự kiện: vd như click) đến một hay nhiều sự kiện (events : dù chưa hiểu event này cụ thể là gì) cho tất cả các elements (các thẻ html, như div, p) cái match(ghép, khớp) được chọn (selector), bây giờ hoặc trong tương lai, căn cứ trên một lớp đặc trưng của các thẻ (element) gốc (root - elements)

Jquery Lightbox

http://leandrovieira.com/projects/jquery/lightbox/
http://www.ajaxblender.com/howto-extend-jquery-lightbox-plugin-with-slideshow.html
http://line25.com/articles/rounding-up-the-top-10-jquery-lightbox-scripts
http://line25.com/tutorials/basic-beginners-guide-to-installing-a-jquery-lightbox

Link Learn English

http://lopngoaingu.com/Dynamic_English_Study/index.php
http://www.tienganh123.com/tieng-anh-hang-ngay