All posts by Pavel Chuchuva

About Pavel Chuchuva

I help coaches to deliver group programs.

How to open HTML files with Visual Studio from Far Manager

Occasionally I want to edit plain HTML file in Visual Studio. You know, those files with .htm or .html extension. Normally pressing Enter in Far Manager opens them in a browser. This is what I want most of the time, so let’s keep it.

Idea: let’s use F4 key to open file in Visual Studio.

Here’s how to achieve it:

* Open Commands menu, select File associations.
* Add new association, enter *.htm;*.html as a mask. Enter this command for F4:

"C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe" /edit "!.!"

Change path to devenv.exe if you have different version of Visual Studio.

Note the /edit parameter. It makes Visual Studio to re-use existing window if it is alredy running. Visual Studio is not exactly a lightweight editor so let’s be efficient here.

What if you want to open HTML file in internal Far editor? Simple: press Alft+F4.

Reference:

Devenv Command Line Switches

Solyanka Recipe

Solyanka is a traditional Russian soup. It is very tasty. This recipe is from cooking site say7.info, translated from Russian.

Ingredients

Ingredients

  • 700 g beef
  • 6-10 types of ham, smoked ribs, sausages, salami, hot dogs, small sausages etc. Total weight 1 kg.
  • 150 g carrot
  • 150 g onion
  • 200 g pickled cucumbers
  • 5 tablespoons tomato paste
  • 3 tablespoons capers
  • black pepper
  • 3-4 bay leaves
  • vegetable oil
  • 1 lemon
  • olives to taste
  • dill or parsley

Method


Place beef in a pan. Bring to a boil, cover and simmer for one and half hour (on medium, skim off the scum).


Take the meat out, let it cool, chop into small pieces.


Chop onion.


Grate carrot on medium grater.


Dice cucumbers.


Dice or julienne meat items (cervelat, ham, smoked ribs, sausages, salami, hot dogs, small sausages, bacon etc).


Fry meat items slightly on vegetable oil.


Fry onion slightly on vegetable oil.


Add carrot, fry a bit.


Add cucumbers, fry for 2-3 minutes.


Add tomato paste, simmer for 5-7 minutes on low.

If tomato paste is too thick you can add some water.


Add meat items to the boiling stock.


Then add beef. Simmer for 5-7 minutes.


Add few capers to taste.


Add fried onion, carrot and cucumbers.


Add half of cup of cucumber or olive pickle. Simmer for 5-7 minutes more.


Add bay leaves, pepper, dill, parsley.

Add salt if needed. Leave it covered for 15-20 minutes. Remove bay leaves.

Pour soup into bowls. Put lemon and olives into each bowl.

Enjoy!

Improving backup to Amazon S3

I use s3.exe command line utility to backup photos to Amazon Simple Storage (S3) and it works great.

I have lots of photos to backup: 900,000 files in 4,000 folders.

Obivously it is impractical to copy all files on every backup – it will take forever. s3.exe has exact feature that I need:

/sync is used with the put command and only uploads files that do not exist on S3 or have been modified since last being uploaded, based on the timestamp. It can be used alone or in conjunction with the /sub option for a fast incremental backup of a whole directory.

Here’s command line that I use for backups:

s3.exe put mybucket C:\photos\ /sub:withdelete /sync /acl:public-read /yes /nogui

Charges

When I started using S3 however I was surpised with the bill from Amazon.

Let’s open source code to see how backup is done. Here are relevant bits:

foreach (string file in Sub.GetFiles(directory, filename, sub))
...
DateTime? lastModified = svc.getLastModified(bucket, key);
if (lastModified.HasValue && lastModified.Value > File.GetLastWriteTimeUtc(file))
{
Progress.reportProgress(key, 0, 0);
continue;
}

For each file s3.exe gets last modified date from the storage. If it is greater than last modified date of local file then no upload is performed.

Let’s do some calculations. To get last modified date s3.exe sends HEAD request. Amazon charges $0.01 per 10,000 HEAD requests. So I would end up paying $0.09 every time I perform backup. If I do it every day that’s $27 per month.

Let’s try to optimize it. How about this: for every local folder get the corresponding list of files in storage. Last modified date will be included in response. Now we’re going to issue about 4,000 LIST requests (1 for each folder). 1,000 LIST requests is $0.01 so that would be $0.04 in total. Or $1.20 per month – that’s saving of $25.80 – a big win 🙂

Making the Patch

I have created a patch by following steps from Scott Hanselman’s blog post.

I have submitted my patch to Codeplex, let’s see if project owner decides that it’s good enough to be applied.

Progress so far

I have started working on my own business in December 2008. Here’s the progress so far.

Idea

Idea is very simple:  web gallery with shopping cart for wedding photographers. For more details see my older post.

Pricing

Fotrel is a web application. My clients use it as a service. The whole software-as-a-service model has a great appeal to me. I can make money while I sleep. There is no pain of acquiring new clients.

I’ve set the price to $95 per month right from the beginning. I didn’t want my product to look cheap. On the other hand it is flat price. I don’t like the idea of charging commission for this kind of service. For some reason it feels like putting my hands in client’s pocket. After all, my expenses are exactly the same regardless of how many orders my client gets.

Then, after reading Jay Abraham’s book I got an idea: charge $95 per month only if photographer has sales in that month. This creates a safety net for my clients: if my product doesn’t bring profit to them at least they are not losing money on it. This should be especially appealing to small (one-person) studios. Also, when you have sales paying $95 feels like giving away part of the profit, not parting with your own money. So far people like this idea. It certainly makes it easier to say yes rather than no.

Clients

Not everyone pays me each month because of the pricing structure. So it is somewhat hard to tell if someone is my customer. A photographer could sign up for my service just to try it out and then never come back. I define my client as someone who has uploaded at least one wedding or portrait gallery in past 3 months.

At the moment I have 15 clients.

Profits

Profits chart

On average, I get $300 per month.

Expenses

You might be wondering why I have those red months with negative profit.

  • I hired web designer twice.
  • I sponsored few AIPP mentoring sessions.

Hosting is the biggest part of my expenses at the moment – about $150 per month. I’m using Amazon EC2 and Softsys Hosting.

Conclusion

Overall, I’m happy with my progress. For now, my focus is on preventing those red bars from appearing again.

P.S. You can take a look at my product here: Fotrel.

Detaching Far Manager from long-running process on Windows 7

Occasionally I launch a program from Far Manager that takes very long to complete. Normally you can use Ctrl+Alt+Tab to “detach” Far from a running process. Technical note #27 explains this well:

If a long-running process (for example, archiving) was run in a FAR console, and for some reasons this very instance of FAR is needed (an editor in the background) or it is undesirable to run a new instance ofFAR, pressing this key combination will create a new console for FAR where it will continue running as if the process has already ended, and the process will continue working in the old console.

Unfortunately this doesn’t work on Windows 7. Instead of detaching you get Windows task switcher:

Windows 7 task switcher

Interestingly the switcher is in “sticky” mode. It doesn’t disappear when you release keys. You can use arrow keys to select a window.

The fix is easy:

  1. Start regedit, open HKCU\Software\far2\System key.
  2. Create ConsoleDetachKey string value, set it to some keyboard shortcut. I use CtrlAltX.
  3. Restart Far Manager

To test it try executing this command from Far:

ping google.com -t

Press Ctrl+Alt+X to get back to Far without stopping pings.

Converting .Net DateTime to JavaScript Date

JavaScript Date constructor accepts number of milliseconds since Unix epoch (1 January 1970 00:00:00 UTC). Here’s C# extension method that converts .Net DateTime object to JavaScript date:

public static class DateTimeJavaScript
{
   private static readonly long DatetimeMinTimeTicks =
      (new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).Ticks;

   public static long ToJavaScriptMilliseconds(this DateTime dt)
   {
      return (long)((dt.ToUniversalTime().Ticks - DatetimeMinTimeTicks) / 10000);
   }
}

Usage:

var dt = new Date(<%= DateTime.Today.ToJavaScriptMilliseconds() %>);
alert(dt);

Reference

Java System.currentTimeMillis() equivalent in C#

How to enable detailed error information for IIS and ASP.NET

By default, IIS and ASP.NET hide detailed error information to prevent revealing sensitive information about your web application:
IIS generic error

ASP.NET generic error

Sometimes you need to see error details (think shared hosting). Add these entries to your web.config file to disable generic errors:

<configuration>
  <system.web>
    <customErrors mode="Off" />
  </system.web>

  <system.webServer>
    <httpErrors errorMode="Detailed" />
  </system.webServer>
</configuration>

Resources

How to safely remove USB flash drive with Far Manager

Do you have one of these:
USB flash drive
When you finish copying files from and to your USB flash drive you need to safely remove it, otherwise you risk losing data. Normally you do this by clicking icon with green arrow in system tray:

You can do the same with Far Manager. Open drive menu (Alt+F1 or Alt+F2), select your flash drive and press Shift+Del. You should get this confirmation:

Select “Remove” and you’re done. Note that the key combo (Shift+Del) is different from ejecting CD/DVD (Del).

jQuery BBQ plugin and Internet Explorer 7

Remember the problem with jQuery BBQ plugin in Internet Explorer 7? It’s not really a problem, just a minor glitch but let’s fix it anyway.

Steps to reproduce:

  1. Open BBQ demo in Internet Explorer
  2. Click Next button few times
  3. Open history menu

Observe:

No page titles, just URLs. Definitely it would be nice to see photo numbers there.

First, let’s see how Asual jQuery Address fix this problem:

_title = _d.title = value;
if (_juststart && _frame && _frame.contentWindow && 
    _frame.contentWindow.document) {
    _frame.contentWindow.document.title = value;
    _juststart = FALSE;
}

Aha! For IE7 you need to set title of the hidden iframe in addition to setting document title. So this is how you set page title:

document.title = "New title";
var iframe = $("iframe:hidden");
if (iframe.length > 0 && iframe[0].contentWindow && iframe[0].contentWindow.document)
  iframe[0].contentWindow.document.title = "New title";

Updated demo should work correctly in Internet Explorer 7.

Using jQuery BBQ plugin for photo gallery

Click here to view demo

Let’s take previous demo and use jQuery BBQ plugin instead. Our goal is Ajax photo gallery that supports browser’s back button. We will display numbers instead of actual photos for now.

$(function () 
{
  $(window).bind('hashchange', function(e) {
    var i = parseInt(e.fragment, 10);
    if (!isNaN(i))
      switchTo(i);
  });
  $(window).trigger('hashchange');
});

function switchTo(i)
{
  if ($("#number").text() == i)
    return;
  $("#number").text(i);
  document.title = i;
  if (i > 1)
    $("#lnk_prev").attr("href", "#" + (i - 1)).removeClass("disabled");
  else
    $("#lnk_prev").removeAttr("href").addClass("disabled");
  if (i < 20)
    $("#lnk_next").attr("href", "#" + (i + 1)).removeClass("disabled");
  else
    $("#lnk_next").removeAttr("href").addClass("disabled");
}

Instead of handling click event we modify href attribute of the links. BBQ will fire hashchange event whenever we "navigate" to a new page. No need to prevent default processing – simple!

One gotcha to watch out for is changing page title. If you take naive approach and simply use document.title (like I did) to set page title you won't see your titles in the history menu in Internet Explorer 7:

Compare with Internet Explorer 8: