Category Archives: Tips & tricks

Cross-platform browser keyboard shortcuts

As of recently I began working on a Mac-book pro and I have to get used to a keyboard with different keys and different layout. One of the most used piece of software today is a browser. I routinely use Opera but there are still sites that don’t work well with it, although it uses pretty much the same rendering engine like Chrome.

I suspect these issues arise from the fact that Chrome tends to become the new IE 6 for many web developers (i.e. : write a page, test it in Chrome, it works, the rest of browsers doesn’t matter to me, continue to next page etc.).

I consider, just like Scott Hanselman, that using the keyboard is the most efficient way to command a computer (and not the mouse / touchpad) therefore I strive to use it to the max. However, switching from OS X to the Windows virtual machine back and forth can be confusing since there are different shortcuts. For example F5 in Windows refreshes the window while in OS X it doesn’t (be it because by default you have to press Fn and then F5 in order to send F5 otherwise a media function will be sent or because this key does not do this function).

Therefore I gathered a few useful shortcut keys that work in both Windows and OS X so I can use them. Many of them work across all major browsers (IE, Firefox, Chrome, Opera and Safari). Use Command (Cmd) key in OS X and Control (Ctrl) in Windows. I’ll include only the secondary key(s) in the table below since the primary key should be held down. I am planning to update this table several times.

Function Second key Internet Explorer Opera for Windows Opera for Mac Chrome for Windows Chrome for Mac
Quit (Close) app Q  x
Close tab (window) W  ✓
Refresh tab R  ✓
Open a new tab T  ✓
Open last closed tab SHIFT-T  ✓
View source U  ✓  x
Print page P  ✓
Select all page content A  ✓
Save current page to computer S  ✓
Add to favorites / bookmark D  ✓
Find in page F  ✓
Find again G  ✓
Show history H  ✓  x
View downloads J  ✓  x
Focus the address bar L  ✓
Undo Z  ✓
Cut X  ✓
Copy C  ✓
Paste V  ✓
Open a new window N  ✓
Open a new private window SHIFT-N  ✓

✓ = available
x = unavailable
[white_space] = not yet verified

(work in progress)

Dear readers, what other useful shortcuts is this table missing?

Building Client (JavaScript) Custom Validation in ASP.NET MVC 4 using jQuery

Introduction

I was recently asked by some students of mine how exactly is client custom validation done in ASP.NET MVC (4). I did this once before unobtrusive validation and jQuery in ASP.NET MVC 2.0 but then I lost contact with the implementation details.

In ASP.NET MVC 4 (this started in MVC 3) there is jQuery unobtrusive validation that works hand-in-hand with Data Annotations (a set of validation attributes that can decorate properties or even (view)model classes). I just remembered that you need to create a ValidationAttribute subclass and also implement IClientValidatable on it. Also you must decorate a property of the (View)Model with this attribute.

On the client side you need to write JavaScript code that provides a validation adapter and a validation function.

Let’s suppose we’d want to create an URL shortening service and on the “Add URL” page we’d have three fields :
– Original URL (textbox)
– Use custom slug (checkbox)
– Custom slug (textbox)

The “Original URL” textbox would be mandatory and the input format should be of a fully-qualified URL (for example “http://blog.andrei.rinea.ro” :P)

The custom slug textbox would be mandatory ONLY if the “Use custom slug” checkbox would be checked. This is the tough part since validating this field requires knowledge of another field’s value (the checkbox in this case). And by tough I mean having to write actual code because there is no out-of-the-box validator for this (not on the server-side nor on the client-side).

This small tutorial will asume that you have knowledge of the ASP.NET MVC platform and C#. I will not go into detail on matters such as what is the MVC pattern, what is the controller, view etc.

 

Implementation – server side

Let’s start by creating a new ASP.NET MVC 4 web project (select “Internet site” template).
We’ll create a UrlController controller with an action called Add :

using System.Web.Mvc;

namespace MVC4_jQuery_Unobtrusive_Custom_Validation.Controllers
{
    public class UrlController : Controller
    {
        [HttpGet]
        public ActionResult Add()
        {
            return View();
        }

        [HttpPost]
        public ActionResult Add(AddUrlViewModel userInput)
        {
            if (ModelState.IsValid)
            {
                // store the data
                // ...
                return RedirectToAction("Index", "Home");
            }
            return View();
        }
    }
}

Read more »

Windows Explorer contextual menu gotcha

Recently I had to extract the public key from a signed .NET assembly and I needed to run the sn.exe tool in order to obtain it. That required opening a command prompt and then setting the current directory to the one in which the assembly resided.

Typically I did :

  1. Win+R (Run)
  2. cmd
  3. Enter
  4. F: [ENTER] (or whatever the drive was)
  5. CD and either type the directory (using the TAB autocomplete or not) or copy the folder path and pasting it into the command prompt [ENTER]

Then I thought how can I simplify this little tedious task, which I sometimes do many times a day. After looking for Microsoft PowerToys which is no longer available I found out a little gem hidden in Windows Explorer. This is what my contextual menu looks like normally :

But just pressing (and keeping pressed) SHIFT before the right-click will give you this :

Selecting this command will do the opening of the command prompt and setting the drive and path in one click.

Of course, the next thing is to add the path to SN.EXE in the Environment Variable PATH in order to be able to execute it “anywhere”.

I hope this helps at least some of us 🙂

ReSharper hidden features – Generate Delegating Members

A frequently-used design pattern is the Decorator. This is also known as a mixin (or they might not be the very same thing but certainly they are related).

Typically you might need to create a class that implements a certain interface and uses another class that implements that exact interface but you need to provide some additional feature(s). An example would be a class that adds transactional behavior to an existing data-access class (a naive example) :


public interface IDataAccess
{
    void AddCustomerInvoice(Invoice invoice, User user);
}

public class DataAccess : IDataAccess
{
    public void AddCustomerInvoice(Invoice invoice, User user)
    {
        InsertInvoice(invoice, user);
        UpdateCustomerDebt(user, invoice.Total);
    }

    // ... the rest of the implementation
}

public class TransactionalDataAccess : IDataAccess
{
    private readonly IDataAccess _dataAccess;

    public TransactionalDataAccess(IDataAccess dataAccess)
    {
        if (dataAccess == null)
        {
            throw new ArgumentNullException();
        }
        _dataAccess = dataAccess;
    }

    public void AddCustomerInvoice(Invoice invoice, User user)
    {
         using(var tx = new TransactionScope())
         {
             _dataAccess.AddCustomerInvoice(invoice, user);
             tx.Complete();
         }
    }

    // ... the rest of the implementation
}

Another type of example would be the Adapter design pattern. An example would be providing access to a (static) class (that may be out of your control) in a mock-able manner. That is, implement another class, non-static, which implements a defined interface and eases unit-testing :

Read more »

Network Security Measures

An MSSP should provide a complete outsourced security solution for an organization’s leading data center. We have expertise in:

Firewall, intrusion detection, firewall protection, network security and security incidents management.

You need to be confident that the network security program is up to the task of protecting the applications and data as they traverse the public internet. The IMSI Security Product List (ISPL) is part of the MSSP package, also there are services for MSSP which you can find in this webpage online. It includes:

Advance Threat Detection (ATD) – This tool compares how the data traffic is encrypted with Internet Key Exchange (IKE) and Active Directory/Active Directory Federation Services (ADFS) encryption methods.

– This tool compares how the data traffic is encrypted with Internet Key Exchange (IKE) and Active Directory/Active Directory Federation Services (ADFS) encryption methods. Antispam Analysis – Uses your analysis for more accurate results in compliance and compliance intelligence.

– Uses your analysis for more accurate results in compliance and compliance intelligence. Antivirus – For preventing virus infections that may lead to mis-configuration, network compromise or the loss of user data.

– For preventing virus infections that may lead to mis-configuration, network compromise or the loss of user data. Cloud Diagnostics – Provides insights on applications and data hosted on Microsoft Azure for further analysis and security recommendations.

– Provides insights on applications and data hosted on Microsoft Azure for further analysis and security recommendations. Data Loss Prevention – Tools to help protect personal data that is located on the network from unauthorized access and data loss.

– Tools to help protect personal data that is located on the network from unauthorized access and data loss. Data Loss Prevention and Advanced Threat Protection – Improved technology to protect against data loss and prevent/mitigate software, hardware and user attacks.

– Improved technology to protect against data loss and prevent/mitigate software, hardware and user attacks. Extensible Storage Engine – Extends the capability to the network in ways that are not available with a standard SAN.

– Extends the capability to the network in ways that are not available with a standard SAN. Flexible Configuration – Provides flexibility to provide configurable information exchange. This includes: Secure connection to a private or secured network using HTTPS, HTTPS Secure (SSL), HTTPS Secure (WPA/WPA2) (WEP) or port 443, Secure (DHCP) or Basic services for private and secure web-browsing and content publishing services. Secure (S/MIME) Security Using certificates that secure connections with authentication and encryption to your enterprise users, apps, applications and services. Transport Layer Security (TLS) – Protects all Internet traffic, while providing extra protection for sensitive data such as key exchanges, identity, credit card and signature verification.

– Protects all Internet traffic, while providing extra protection for sensitive data such as key exchanges, identity, credit card and signature verification. Remote Desktop Services (RDS) Authentication – Provides remote connection to a Microsoft hosted Windows Server instance for usage, file and printer sharing, system and system center administration. Microsoft Active Directory – Provides access to network resources, and configuration and administration of remote Windows desktop and desktop connectivity applications.