Thursday, March 31, 2011

Convenience or "lazy programming" IList management - protecting IList.Add method

How do you manage this simple scenario when you have an object with a list of items. EG:

public class ContainerObject
{
    IList<ChildObject> Children { get; }

    public void AddCustom(ChildObject toAdd)
    {
        // Some validation ...
        Children.Add(toAdd);
    }
}

Assuming the collection is initialised to an implementation of IList, is there any way in which to control the way in which items are added to the list?

For example, I have another method on the ContainerObject class that takes a ChildObject and adds it to the list. This method is required to perform some basic validation on the ChildObject before adding it.

I am being lazy in that I don't want to mess around and write a custom list interface (without an add method) that consuming developers need to implement. I am also using the ToList() method on the IQueryable interface so this is another reason for sticking with IList - it just works.

So, is there an approach in which you can police how items are added to the IList instance i.e. prevent use of the Add method and only allow adding to the collection via my custom method, or am I just asking for the impossible? ... and being lazy :(

I can think of a few hacky ways in which to check when items are added via my custom method or directly on the list but these seem hacky!

Anyone experience anything similar to this? If so, what did you do?

From stackoverflow
  • You can make your property return a wrapper around the original list using ReadOnlyCollection<T>. This will ensure that callers don't add any items themselves. You can keep a reference to the original mutable list. Note that because the read-only collection is only a wrapper, callers which cache the read-only collection will still see additions that you make to the original list. That may or may not be a good thing depending on your expected use.

    EDIT: To explain my caching comment...

    Suppose a client did:

    IList<ChildObject> originalChildren = container.Children;    
    container.AddChild(new ChildObject());
    IList<ChildObject> updatedChildren = container.Children;
    

    with the Children property implemented like this:

    private IList<ChildObject> children = new List<ChildObject>();
    public IList<ChildObject> Children
    {
        get { return new ReadOnlyCollection<ChildObject>(children); }
    }
    

    Then originalChildren and updateChildren would both have the same contents - the returned ReadOnlyCollection wouldn't be a snapshot of the collection of children at the first line. It would just be a wrapper around the collection. Clients wouldn't be able to rely on it not changing - they just wouldn't be able to change it themselves.

    Tim Peel : Sorry Jon, could you explain the caching comment in more detail please? Thanks
    Tim Peel : Thanks Jon, appreciated
  • Make your property return _list.ToArray() instead of the list itself.

    Henk Holterman : I'm quite sure that would be expensive - ToArray hast to shallow-clone the list.
    ssg : It's not as expensive as it sounds since List itself keep things in an array already. So it's just an Array.Copy() operation.
  • Return a ReadOnlyCollection to the world wrapping your list which you manage the Adds to.

How can I hide weekends when using the ASP.NET Calendar control?

Sometimes when displaying a calendar it is necessary to prevent the weekend days and the weekend names in the day header from showing, is there a way to do this using the ASP.NET Calendar control?

From stackoverflow
  • As far I know you can't, but you can experiment with WeekendDayStyle, for example by setting style with display:none. Alternatively, you can create custom control inherited from Calendar and override ether Render, OnDayRender or something else.

  • I believe you can handle the Day Render event and hide the cell or assign CSS properties to make it invisible or grayed out. Below is a simple example, I hope this helps.

    protected void Calendar_DayRender(object sender, DayRenderEventArgs e)
    {
    
      e.Cell.Visible = False;
      // or
      // e.Cell.Attributes.Add("class", "Invisible");
      // or
      // e.Cell.Attributes.Add("style", "display: none");
    }
    
    Rob : This just hides the contents of the day field, you would still need to do additional work to be able to remove the day heading.
  • As the control is provided, there is no way to do this without overriding the control. One way of doing this is to is to override the OnDayRender and Render methods to remove the information from the output prior to sending it back to the client.

    The following is a screen shot of what the control looks like when rendered:

    Example of weekday calendar

    The following is a basic control override that demonstrates removing the weekend day columns from the control.

    /*------------------------------------------------------------------------------
     * Author - Rob (http://stackoverflow.com/users/1185/rob)
     * -----------------------------------------------------------------------------
     * Notes
     * - This might not be the best way of doing things, so you should test it
     *   before using it in production code.
     * - This control was inspired by Mike Ellison's article on The Code Project
     *   found here: http://www.codeproject.com/aspnet/MellDataCalendar.asp
     * ---------------------------------------------------------------------------*/
    using System;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Text;
    using System.IO;
    using System.Xml;
    
    namespace DataControls
    {
        /// <summary>
        /// Example of a ASP.NET Calendar control that has been overriden to force
        /// the weekend columns to be hidden on demand.
        /// </summary>
        public class DataCalendar : Calendar
        {
            private bool _hideWeekend;
            private int _saturday;
            private int _sunday;
    
            /// <summary>Constructor</summary>
            public DataCalendar()
                : base()
            {
                // Default to showing the weekend
                this._hideWeekend = false;
                // Set the default values for Saturday and Sunday
                this.Saturday = 6;
                this.Sunday = 0;
            }
    
            /// <summary>
            /// Indicate if the weekend days should be shown or not, set to true
            /// if the weekend should be hidden, false otherwise. This field 
            /// defaults to false.
            /// </summary>
            public bool HideWeekend
            {
                get { return this._hideWeekend; }
                set { this._hideWeekend = value; }
            }
    
            /// <summary>
            /// Override the default index for Saturdays.
            /// </summary>
            /// <remarks>This option is provided for internationalization options.</remarks>
            public int Saturday 
            {
                get { return this._saturday; }
                set { this._saturday = value; }
            }
    
    
            /// <summary>
            /// Override the default index for Sundays.
            /// </summary>
            /// <remarks>This option is provided for internationalization options.</remarks>
            public int Sunday 
            {
                get { return this._sunday; }
                set { this._sunday = value; }
            }
    
            /// <summary>
            /// Render the day on the calendar with the information provided.
            /// </summary>
            /// <param name="cell">The cell in the table.</param>
            /// <param name="day">The calendar day information</param>
            protected override void OnDayRender(TableCell cell, CalendarDay day)
            {
                // If this is a weekend day and they should be hidden, remove
                // them from the output
                if (day.IsWeekend && this._hideWeekend)
                {
                    day = null;
                    cell.Visible = false;
                    cell.Text = string.Empty;
                }
                // Call the base render method too
                base.OnDayRender(cell, day);
            }
    
            /// <summary>
            /// Render the calendar to the HTML stream provided.
            /// </summary>
            /// <param name="html">The output control stream to write to.</param>
            protected override void Render(HtmlTextWriter html)
            {
                // Setup a new HtmlTextWriter that the base class will use to render
                StringBuilder sb = new StringBuilder();
                StringWriter sw = new StringWriter(sb);
                HtmlTextWriter calendar = new HtmlTextWriter(sw);
                // Call the base Calendar's Render method allowing OnDayRender() 
                // to be executed.
                base.Render(calendar);
                // Check to see if we need to remove the weekends from the header,
                // if we do, then remove the fields and use the new verison for
                // the output. Otherwise, just use what was previously generated.
                if (this._hideWeekend && this.ShowDayHeader)
                {
                    // Load the XHTML to a XML document for processing
                    XmlDocument xml = new XmlDocument();
                    xml.Load(new StringReader(sw.ToString()));
                    // The Calendar control renders as a table, so navigate to the
                    // second TR which has the day headers.
                    XmlElement root = xml.DocumentElement;
                    XmlNode oldNode = root.SelectNodes("/table/tr")[1];
                    XmlNode sundayNode = oldNode.ChildNodes[this.Sunday];
                    XmlNode saturdayNode = oldNode.ChildNodes[this.Saturday];
                    XmlNode newNode = oldNode;
                    newNode.RemoveChild(sundayNode);
                    newNode.RemoveChild(saturdayNode);
                    root.ReplaceChild(oldNode, newNode);
                    // Replace the buffer
                    html.WriteLine(root.OuterXml);
                }
                else
                {
                    html.WriteLine(sw.ToString());
                }
            }
        }
    }
    
    Brian : Just a small comment that when I implemented this, the day headings ran from Tuesday to Saturday. The trick for me was to change the line: XmlNode sundayNode = oldNode.ChildNodes[0]; to: XmlNode sundayNode = oldNode.ChildNodes[5]; Possibly due to me being in the UK?
    Rob : @Brian - That would most likely be the case, I'm in the United States which uses Sunday as the first day of the week for the calendar. I didn't include anything in the way of localization logic in the code so that might be something for me to do at some point.
    Brian : @Joel - Just implemented this and tested in IE, predictably it doesn't appear as one would hope. The weekday headers and day cells all render at 5/7th's of the width of the calendar. This is due to the two day columns that were removed. I have a fix for this (replace any 'width:14%' in the xml to 'width:20%') and would like to share my solution with others. What's the best way for me to go about this?
    Rob : @Brian - I wrote the original modification as an example to build off of as opposed to a full production version. Your best best would likely to be to answer this question with your version or you could do a blog entry somewhere and post up a link.

Calling Directory.Exists("\\SERVER\SHARE\") in Setup Project

I have a .NET Setup Project to which I've added a custom installer action. During the setup process, the user has to provide a path (which often is a UNC path) to a share on their file server. I attempt to do some validation before proceeding to make sure the directory exists, as such:

if (!Directory.Exists(serverDirectory)) { 
    throw new InstallException("Specified path does not exist or ..."); 
}

Pretty vanilla -- and in a console app, the Directory.Exists() code works as expected. However, in the context of the MSI, it does not. Specifically, the call to Directory.Exists always fails when using a network resource. The documentation for Directory.Exists does indicate why:

The Exists method does not perform network authentication. If you query an existing network share without being pre-authenticated, the Exists method will return false.

Searches have led me to other similar scenarios in ASP.NET where impersonation is the solution. That isn't applicable here, but it illustrates the issue.

How can I check for the existence of the network path? To put in the language of the documentation -- how do I pre-authenticate before the call? The user is installing as an administrator, and browsing to that path in Windows Explorer works successfully, so it's not permissions of the user, but rather a lack of checking by the code.

Have I created an unnecessary concern -- should I omit this and throw the exception later when trying to use the network resource... it's largely the same critical failure, right?

From stackoverflow
  • It's not just existence: you need to check for permissions as well, and worry about what happens if they change on you in the period between when you check and when you actually use the value.

    Therefore the normal mechanism is to just assume everything is okay. Instead, put your development effort into handling the exception when the assumption proves false, because you need to be able to do that gracefully anyway.

    For this case, you might be able to improve on that by immediately creating a small placeholder file in directory in question, and holding a lock on that file until you're completely finished with the folder. That would allow you to give some better feedback, since you'll get an immediate error trying to create the file. It also helps guarantee that the folder stays accessible, since under windows at least users will have a hard time deleting or significantly changing folder as long as you hold a lock to that file.

Monday, March 28, 2011

Unknown significant moments of computing history

Computing as a discipline in its own right (rather than as a discussion of whether it is Mathematics or Physics) is a reasonably young science. Wherever you trace its roots (e.g. Turing's paper in 1936, Babbage's engines, ATLAS, ENIAC or LEO) it's much younger than most modern nation states.

I've been programming (using the loosest definition) for close to 30 years but it still seems to me that I come across parts of its history that are new to me. While it shouldn't surprise me that while I studied computing at school, at University, post-grad and now as a day-job, that there is stuff I don't know, it still causes a small pause when I read an article about something which seems pivotal but about which I know absolutely nothing.

For instance, this news item describes a conference which looks to have sown the seeds for many things that have come since. It was 1968, the world was young, IBM was old, Microsoft and Sun barely in glint in their creators' eyes; the notion of separating hardware and software was new, the largest institutions had networks that numbered in the dozens of machines. Yet some of their conclusions are fresh and remain unresolved, in particular managing large projects. (The proceedings are fascinating and full of lessons for the future software engineer.)

The question is YASOP (*) - what piece of computing history do you think still has significance to our current industry but you feel people don't know enough about?

(*) Yet Another Stack Overflow Poll

From stackoverflow
  • Bletchley Park.

    Back in WWII (or WW2 for my American friends ;) ), the modern computer was invented in England at Bletchley Park. After the war, the British government destroyed all evidence of its existence and swore everyone involved to secrecy. Thus the world came to assume the modern computer was invented in the USA a few years later. Even today - after the secrets of Bletchley Park have been revealed - most programmers remain oblivious to it.

    (As a quick aside, it is also a national disgrace for us Brits that we haven't bothered to fund the upkeep of this historic site and it took a generous donation recently from US companies to highlight its plight)

    Unsliced : That's exactly the kind of answer I was after! I'd recommend a visit to Bletchley Park to anyone who finds themselves in the area. It's both inspiring and dispiriting in equal measure. The job they did and - as David points out - the mess we've made of their legacy.
    Just Some Guy : We say "WWII" too. :-)
    Michael Stum : Even (or should I say "Especially"?) as a German, i was deeply saddened to hear how Bletchley Park was more or less abandoned. It is a national monument in my opinion.
    Jon Hanna : It's a bigger disgrace that when this answer was written, the British government still hadn't given Turing a post-humous apology for the way they treated him because he was homosexual. Keeping how big a war hero he was a secret had some security justification, harassing and torturing him until he committed suicide did not.
    David Arno : I agree with you completely Jon. Subsequently though Brown did issue an apology after the brilliantly successful on line campaign last year. So there was an eventual happy ending to that great man's life.
  • I have a rare piece of early computer trivia: the first computer program run on the ENIAC was a program to produce the first 1000 decimal places of Pi (source: my dad, who was there at the initial run). You could argue that this was the first "official" computer program ever.

    Skizz : Ada Lovelace would probably argue that one with you.
    PintSizedCat : She would, would she, and how many programs did she actually run?
    PintSizedCat : From the wiki article "her [Ada Lovelace] work never ran ...The ENIAC programming team, consisting of Kay McNulty, Betty Jennings, Betty Snyder, Marlyn Wescoff, Fran Bilas and Ruth Lichterman were the first working programmers."
    Skizz : Running the program is but a mere technicality. I'm sure if Mr Babbage had pulled his finger out she would have executed plenty.
    PintSizedCat : You don't get medals by being a slacker! Maybe if she wasn't around to distract him things would have been different.
  • The Xerox Alto for introducing the world to GUIs.

    Skizz

    Gary Willoughby : ...and Apple for completely ripping it off. Xerox had no business sense back then.
    Nik Reiman : Also, isn't the topic *unknown* pieces of computer history? I'm pretty sure lots of people (at least lots of geeks) know that Xerox made the first GUI system and mouse...
  • SAGE, the Semi-Automatic Ground Environment. Our original air traffic control system. Designed in the 1950, operational from 1963 to 1983. Vacuum tubes, ferrite core memory, magnetic drums, and teletype machines. It was the first large scale computer control system. It tracked all domestic flights in the USA. I was stationed at Griffiss AFB which had one of the last operations SAGE systems.

    Thomas Owens : Wow. You don't mean Griffiss AFB in Rome, New York, do you? That's amazing. I didn't know I was so close to computing history, if so.
    MSalters : Operational from 1063 - so the French could have just taken a plane when they invaded England 3 years later? ;)
  • In June 1945, John von Neumann published a 10-page report titled "First Draft of a Report on the EDVAC". It contained the outline of pretty much every general-purpose computer built since. The EDVAC's two main innovations were the use of binary instead of decimal and that it was to be a stored-program computer.

    Without stored-program computers, we would still be in the stone age of computing.

    More here.

  • Vannevar Bush and his memex.

  • Calvin Mooers invention of the TRAC programming language. It was ahead of its time in a number of ways, and unfortunately his attempt to control and profit from it probably lead to it not being more widely known.

  • Somewhere in 1973 Ken Thompson sat on a single night coding session and implemented Doug McIlroy's vague idea of pipes into the early UNIX code and invented the "|" notation in its shell. This was the moment when the UNIX system took of. An article describes it like this:

    The philosophy that everyone started to put forth was 'Write programs that do one thing and do it well. Write programs to work together. Write programs that handle text streams, because that is a universal interface.'

    The development of pipes led to the concept of tools -- software programs that would be in a "tool box,"

    Novices to the system could experiment, linking different commands together for what they thought should be the output. And very often their "pipes" worked the first time

  • The concept of the stored-program computer conceived by Presper Eckert and John Mauchly in 1944, but for which John von Neumann has unfairly taken the credit.

  • Ole-Johan Dahl and Kristen Nygaard developed the Simula languages, the first object oriented programming langauges in the 1960s.

  • Quoting from Squeak wiki...

    ...In December 1979, the Xerox Palo Alto Research Center developed the first prototype for a GUI. A young man named Steve Jobs, looking for new ideas to work into future iterations of the Apple computer, traded US $1 million in stock options to Xerox for a detailed tour of their facilities and current projects. One of the things Xerox showed Jobs and other members of the Apple Lisa team was the Alto machine, which sported a GUI and a three-button mouse. When Jobs saw this prototype, he had an epiphany and set out to bring the GUI to the public.Apple Computer then commercialized and refined the GUI into a system very much like that we use today—a system which became nearly ubiquitous after its adoption in Microsoft Windows. The first popular personal computer, the Apple 2, was a hit - and made Steve Jobs one of the biggest names of a brand-new industry...

    Jörg W Mittag : Unfortunately, to this day, neither Jobs nor Gates understand what the Alto GUI was about, and thus both OSX and Windows still are lightyears behind a typical 1980s Smalltalk system.
  • The public debut of the computer mouse on December 9, 1968 when Douglas C. Engelbart and the group of 17 researchers working with him in the Augmentation Research Center at Stanford Research Institute in Menlo Park, CA, presented a 90-minute live public demonstration of the Online System, NLS (which was the inspiration for the Xerox Alto).

    Dour High Arch : This demo also introduced graphical user interfaces, hypertext, videoconferencing, and email. Steven Levy called it "The mother of all demos".
  • The invention of an algebraic system of logic by George Boole in 1847, which forms the basis of all modern digital computers. At the time it appeared to have no practical uses.

    Approximately seventy years after Boole's death, Claude Shannon attended a philosophy class at the University of Michigan which introduced him to Boole's studies. Then in 1937 Shannon wrote a master's thesis at MIT, in which he showed how Boolean algebra could optimize the design of systems of electromechanical relays (telephone exchanges), and that circuits with relays could solve Boolean algebra problems.

    Victor Shestakov at Moscow State University proposed a theory of electric switches based on Boolean logic earlier than Claude Shannon in 1935 but the first publication of Shestakov's result took place only in 1941.

  • >> Konrad Zuse <<

  • JCR Licklider, his overall vision for man machine symbiosis. He put his money( ARPA money) where his mouth was by funding all the major research in the 50s and the 60s that gave us the technologies which make the current PC. Another one would be Claude Shannon's information theory. Not only did this infulence the direction of computing but also later was influential in the development of crytography outside of NSA and in the public domain.

  • Louis Pouzin invented both one of the first packet-switching networks and the concept of the shell and its commands.

  • I'd have to go with the development of numerical weather prediction, based on the principles which were first derived by Lewis Fry Richardson. He proposed that the primitive equations could be solved using a finite-differencing scheme, but when he attempted it by hand the result was off by an order of magnitude (it turns out that he didn't account for sound waves, which arise as a result of the compressibility of the atmosphere and propagate much faster than gravity/baroclinic waves).

    It wasn't until the advent of ENIAC that Charney and numerous other American scientists were able to complete the first successful numerical forecast by solving the barotropic vorticity equation (a simplified and boiled-down version of the equations of atmospheric motion). From their early work, the entire field of numerical weather prediction has been refined over the past 60 years in an attempt to accurately reproduce and forecast the state of the atmosphere. You can actually download a port of their original code to MATLAB, and solve the same set of equations in about 15 seconds that it took them about 12 hours to do.

    Advances in computing power, the advent of massively parallel computing, and specialized programming languages (mostly FORTRAN) have allowed us to attack problems such as complex boundary layer flow, the development of tornadoes, and gain an understanding of natural climate variability. And of course, they make the TV met's job a lot easier too ;)

  • Google secret history of silicon valley. They recently had a tech talk about how the CIA and NSA developed the major players early on as a form of tech transfer. Turns out that the war played a greater role in the development of the valley than we knew.

    Unsliced : I love this answer :)
  • Not so much a moment, but the PLATO system seems relatively untalked about, if not unknown. It's credited as the first computer assisted learning system. One of the designer's goals was to bring university-level education and access to technology to everyon, though costs prevented this from happening. Later versions featured monochrome plasma displays.

    In 1972, researchers from Xerox took a tour and adapted some of what they saw for their work in Palo Alto. PLATO didn't have as big an impact on the work at PARC as PARC had on a certain other company, but the story is still oddly familiar.

    On the darker side, PLATO's messaging system was the direct inspiration for Lotus Notes.

  • 1870, Émile Baudot designs the first binary character encoding, enabling a translation between human-readable text and binary numbers.

C# - What is a component Class and how is it typically used?

What is a component class and where would I typically use one?

EDIT: Sorry I guess I was a little vague. I am on a bit of a steep learning curve.

When I add a new item to my project in vs2008 one of the options is to add a component. I am not even sure I understand what a component is - but I would sure like to find out a bit more about them. Could somebody explain them to me or perhaps point me towards an online tutorial that would help me.

Thanks

From stackoverflow
  • Well, generally speaking, a component is any part of a thing. Specifically in .NET, a component is a class that implements the IComponent interface, which indicates that a class can interact with it's logical container.

    More often than not, you see this in the form of design support, in that classes interact with their host in the designer, but that's not a strict requirement.

  • If you mean a class that inherits from System.ComponentModel.Component, like for example the System.Windows.Forms.BindingSource and strongly-typed DataSets, this will allow to drag an instance on the Visual Studio design surface (on a form in design-time) and set some properties using the property grid. Once there is an instance of such component on the form it is discoverable by other components/controls. For example a BindingSource can be selected as a data source for a grid view or some other control.

  • Component Class is for sharing objects between applications.

    Typically for dropping down object like outlook email to an application.

Producing 64-bit builds on Windows with free software

Hi, I have a C++ project that I've been developing in Microsoft Visual C++ 2008 Express Edition. It has come to the point that I'd like to port to 64-bit and continue development.

What is the best way to do this using free software?


My thoughts so far:

The Express Edition of MSVC doesn't come with 64-bit compilers, so I can install the Windows SDK to get these. I could then port my project files to nmake, and use the IDE just as a tool to debug and invoke my nmake scripts.. The downside to this is that nmake looks very poor. The example towards the end of this tutorial suggests that nmake cannot figure out source file dependences itself, and I don't know of anything equivelant to gcc -M that I could use.

Another option might be to use vcbuild from the Windows SDK to produce 64-bit builds from my existing vcproj files. Preliminary investigations show that this doesn't really work, as my project files don't have the 64-bit configurations present. (Perhaps I could fudge this by adding the 64-bit configurations to the vcproj files in a text editor.)

A final option might be to give up on MSVC, and port my project to the MinGW/MSYS toolchain.

From stackoverflow
  • You can use makedepend as an alternative to gcc -M. Here's a primer on this and other methods of generating dependencies.

    You could also give the autoconf+automake combo a try, though it requires some work to make it use MSVC's compiler. Some have succeded at doing this.

  • If you want to use the Windows SDK compiler with GNU make or another build system, you could write a program/script that converts the output of cl.exe /showIncludes into a format that is compatible with your build system.

Api to turn on your computer

I'm Making a small on-line clock (both for fun and to learn a bit more of php and javascript) started it because i actualy need an alarm clock and this would be easier than buying one (don't ask)

Now i wanted to know one thing, i know it's impossible to turn on/off you're computer from a browser, but a friend asked me if i could do him a small addon/program that would fetch the alarm time he added there, and would turn his computer on so it would let if wake up

I know turning on must be pretty much impossible, but turning on from sleep/hibernate maybe?

Anyone knows any api to do this? Windows or mac, or cross platform.

Just for curiosity the alarm clock is here http://www.my-clock.net

Edit:

On the wiki page, wake-on-lan says it requires to turn the bios power to the network-board, is there any way arround this? Or are todays computers already ready for this kind of protocol?

From stackoverflow
  • I don't know a lot about how it works, but it sounds like you need Wake-on-LAN

    Wake on LAN (WOL, sometimes WoL) is an Ethernet computer networking standard that allows a computer to be turned on or woken up remotely by a network message.

  • Your best bet may be Wake-on-LAN

  • As people have pointed out, Wake-On-Lan is one possibility. But there's another one that might suit your need. Most BIOS'es today already provide an option to turn your computer on at a given time. If your goal is simply to turn your computer into an alarm clock, this should do the trick.

  • Once a OS goes in hibernate/sleep the only way to bring it up is through some kind of kernel level hardware driver event. for example pressing power button or opening the lid of the system etc.

    IMO it would be bit complex to model the functionality within an application, as application is dependent on OS level services, that are not available in sleep/hibernate mode.

  • There could be two solutions:

    1. Use Wake-on-LAN as was suggested. But you must have another machine up on that LAN, it doesn't work over the Internet itself. So it goes like You -> [Internet] -> Waker -> Your friend.
    2. You can set his RTC wakeup alarm over the Internet while his machine is still up and running. Then his computer will wake at the specified time.

    Both would work even if the computer is completely powered-off.