.NET (296) administrative (41) Ajax (42) AngularJS (2) ASP.NET (144) bicycle (2) books (180) browser (8) C# (134) cars (1) chess (28) CodePlex (10) Coma (8) database (47) deployment (3) Entity Framework (2) essay (112) flash/shockwave (2) flex (1) food (3) friend (2) game (20) idea (5) IIS (8) javascript (82) LInQ (2) Linux (6) management (4) manga (42) misc (672) mobile (1) movies (91) MsAccess (1) murder (2) music (64) mysql (1) news (100) permanent (1) personal (68) PHP (1) physics (2) picture (307) places (12) politics (13) programming (504) rant (120) religion (3) science (43) Sharepoint (3) software (58) space (1) T4 (2) technology (11) Test Driven Development (4) translation (2) VB (2) video (97) Visual Studio (44) web design (46) Windows API (8) Windows Forms (3) Windows Server (5) WPF/Silverlight (63) XML (11)

Wednesday, October 15, 2014

The BucketList, an generic IList implementation that doesn't use a contiguous array of items

The wonder of .Net is that most of the time we don't really have to care about stuff like memory allocation, the framework does everything for you. One especially annoying thing, though, is when you are using a basic data structure that is supposed to be efficient and you get stuff like OutOfMemoryException. One of the cases is List<T> which in the background uses one big array. This means two things: one is that certain modifying operations are slow and the other is that it requires contiguous memory space for the items. If your memory space gets too fragmented, then there is not enough to allocate for hundred of thousands of items, even if in that memory space you only need a pointer for each item. That is why you end up with out of memory exceptions. It's not like you don't have enough memory, it's that you don't have a big enough contiguous block of it.

As a solution I give you... the BucketList<T> class. It has a bucket size that defaults to 10000 and it implements a list of lists that each will always have at most that amount of items as specified in the bucket size. This way operations that remove and add items will only operate on 10000 item big arrays and there is no need for only one big memory block. I implemented the IList interface explicitly, so that you will never find it comfortable to use an instance as a BucketList, but as an IList. This way you can replace the implementation of the interface with a normal List or whatever other form you like. Enjoy!

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Siderite.DataStructures
{
    /// <summary>
    /// IList implementation that doesn't require a contiguous memory space (an array)
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class BucketList<T>:IList<T>
    {
        private int _bucketSize;
        private List<List<T>> _list;
        private int _count;

        /// <summary>
        /// Default constructor
        /// </summary>
        public BucketList():this(10000)
        {
            _list = new List<List<T>>();
        }

        /// <summary>
        /// Specify the bucket size (default 10000)
        /// </summary>
        /// <param name="bucketSize"></param>
        public BucketList(int bucketSize)
        {
            _bucketSize = bucketSize;
        }

        /// <summary>
        /// Create a bucket list from an IEnumerable
        /// </summary>
        /// <param name="enm"></param>
        public BucketList(IEnumerable<T> enm):this()
        {
            var list = (IList<T>)this;
            foreach (var itm in enm)
            {
                list.Add(itm);
            }
        }

        /// <summary>
        /// The item count
        /// </summary>
        public int Count
        {
            get
            {
                return ((IList<T>)this).Count;
            }
        }

        #region IList<T> implementation

        int IList<T>.IndexOf(T item)
        {
            var index = 0;
            for (var i = 0; i < _list.Count; i++)
            {
                var idx = _list[i].IndexOf(item);
                if (idx < 0)
                {
                    index += _list[i].Count;
                }
                else
                {
                    index += idx;
                    return index;
                }
            }
            return -1;
        }

        void IList<T>.Insert(int index, T item)
        {
            var idx = 0;
            for (var i = 0; i < _list.Count; i++)
            {
                var lst = _list[i];
                if (index < idx + lst.Count)
                {
                    lst.Insert(index - idx, item);
                    splitListIfTooLarge(i);
                    _count++;
                    return;
                }
                else
                {
                    idx += lst.Count;
                }
            }
            throw new IndexOutOfRangeException("index");
        }

        void IList<T>.RemoveAt(int index)
        {
            var idx = 0;
            for (var i = 0; i < _list.Count; i++)
            {
                var lst = _list[i];
                if (index < idx + lst.Count)
                {
                    lst.RemoveAt(index - idx);
                    removeListIfEmpty(i);
                    _count--;
                    return;
                }
                else
                {
                    idx += lst.Count;
                }
            }
            throw new IndexOutOfRangeException("index");
        }

        T IList<T>.this[int index]
        {
            get
            {
                var idx = 0;
                for (var i = 0; i < _list.Count; i++)
                {
                    var lst = _list[i];
                    if (index < idx + lst.Count)
                    {
                        return lst[index - idx];
                    }
                    else
                    {
                        idx += lst.Count;
                    }
                }
                throw new IndexOutOfRangeException("index");
            }
            set
            {
                var idx = 0;
                for (var i = 0; i < _list.Count; i++)
                {
                    var lst = _list[i];
                    if (index < idx + lst.Count)
                    {
                        lst[index - idx]=value;
                    }
                    else
                    {
                        idx += lst.Count;
                    }
                }
                throw new IndexOutOfRangeException("index");
            }
        }

        void ICollection<T>.Add(T item)
        {
            List<T> lst;
            int index;
            if (_list.Count == 0)
            {
                lst = new List<T>();
                _list.Add(lst);
                index=0;
            }
            else
            {
                index=_list.Count - 1;
                lst = _list[index];
            }
            lst.Add(item);
            splitListIfTooLarge(index);
            _count++;
        }

        void ICollection<T>.Clear()
        {
            _list.Clear();
            _count = 0;
        }

        bool ICollection<T>.Contains(T item)
        {
            return ((IList<T>)this).IndexOf(item) > -1;
        }

        void ICollection<T>.CopyTo(T[] array, int arrayIndex)
        {
            var index = arrayIndex;
            foreach (var lst in _list)
            {
                lst.CopyTo(array, index);
                index += lst.Count;
            }
        }

        int ICollection<T>.Count
        {
            get
            {
                return _count;
            }
        }

        bool ICollection<T>.IsReadOnly
        {
            get { return false; }
        }

        bool ICollection<T>.Remove(T item)
        {
            for (var i = 0; i < _list.Count; i++)
            {
                var lst = _list[i];
                if (lst.Remove(item))
                {
                    _count--;
                    removeListIfEmpty(i);
                    return true;
                }
            }
            return false;
        }

        IEnumerator<T> IEnumerable<T>.GetEnumerator()
        {
            foreach (var lst in _list)
            {
                foreach (var item in lst)
                {
                    yield return item;
                }
            }
        }

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return ((IList<T>)this).GetEnumerator();
        }

        #endregion

        private void splitListIfTooLarge(int listIndex)
        {
            var lst = _list[listIndex];
            if (lst.Count > _bucketSize)
            {
                var newList = lst.GetRange(0, _bucketSize);
                lst.RemoveRange(0, _bucketSize);
                _list.Insert(listIndex, newList);
            }
        }

        private void removeListIfEmpty(int listIndex)
        {
            var lst = _list[listIndex];
            if (lst.Count ==0)
            {
                _list.RemoveAt(listIndex);
            }
        }
    }
}

Sunday, October 05, 2014

Fappenings

You may have heard of the recent scandal about Internet leaks of nude or personal photos of female celebrities. Dubbed "The Fappening", a word play on the (horribly bad - my opinion) movie The Happening and the term "fap", which refers to masturbation, it is a huge collection of pictures that seem to have been taken by the celebs themselves or by close acquaintances in private surroundings. You know... selfies. They were obviously obtained through some underhanded methods and published in several waves, three at the moment. I am not here to give you torrent links to the leaked material, even if they are fairly easy to find, instead I am going to talk about the general reaction, as proven by seed/leech ratios of torrent downloads: after an initial boom in interest, the updates have been less and less interesting to people. Why is that?

At first I hypothesized that the vehement reaction of the media was part joining in the fray, like sharks smelling blood, and in their own way pointing people to search the net for the photos (yeah, I don't really believe in the difference between mentioning something that is easy to find and a link), but also because this affair was an obvious attack on the brands that the celebrities are standing for. Nobody really cares about how some of the actresses in this situation are actually acting if they look hot enough and also, very important, how unattainable they are. The reaction of the agencies that invested a lot in these brands was expectedly violent. However, there is another factor, one that I think makes it all meaningful to discuss: people expected something completely different from what was provided. No matter how much we understand the media processes involved in creating a celebrity personality, we don't really (emotionally) believe that it is happening or we don't understand the extent of the effort. Indeed, when people downloaded the pictures and guiltily and excitedly started to look at the images, they found out... real women. Without the expertise of professional photographers and without the extensive post processing and media censorship that occurs after the pictures are taken, the celebrity females that we collectively idolatrized appeared as less than goddesses and as just normal people, with zits and saggy tits and all that. Even if they look fabulous, like some of them do, the amateurish manner of the way the pictures were taken give little pleasure. Indeed, the only pleasure that can be extracted from this is akin to rape: they wanted to cheat, to show us just the Photoshopped images of themselves, but we showed them! We took what we wanted.

Look at the torrent statistics though. The October collection of pictures is at the top, over Fappening 2 that has more seeds than Fappening 3. People lost interest: they were curious, downloaded the stuff, then they didn't follow through with the rest. All because they were getting something other than they had bargained for. Instead of pictures showing more of the beautiful women we yearn for, they showed enough to make those women feel terribly human. The breasts, the asses and all the other hidden skin was hidden not because they were something amazing to hide, but because the myth was more beautiful and sexy, perfect in its imperfect sharing. It raises important questions that I believe to be worth exploring: what are we really falling for? What is beauty: just a branded illusion? Why do girls appearing fully clothed and smiling in a music video or a movie seem more desirable than the fully naked and active girls in porn films? Are we really interested in the "reality show" of someone's intimacy, or do we, really, secretly, want these people to show us only the beautiful parts, to make us believe that perfect people exist? Are we all victims of a global romcom? And who is it that is laughing at the comedy aspect of all this?

Tuesday, September 09, 2014

TV Series I've Been Watching - part 20

The autumn season for TV shows is beginning, so I am here again to discuss the ones that I have been watching lately.



  • The Legend of Korra - This third season was better than others, but we still have to contend with Korra's helplessness. Also I have this nagging feeling that her not being able to do anything and having to be saved by her friends repeatedly has less to do with what people can accomplish together and more with the fact that she is female and therefore must be perceived as in distress. And before you ask me when did I become a feminist, just read on and see what are the shows with female lead characters and what happens to them. The magnificent four villains also were ridiculously strong for people living in solitary confinement for years.
  • The Good Wife - Interesting new dynamic of the show. I am quite fascinated by how they achieve this dynamic equilibrium: giving people what they want, but always changing things one way or another, moving characters around, keeping things interesting. If nothing else, this is a brilliantly constructed TV show.
  • Homeland - Homeland will have a fourth season, which is to begin soon. They released a sort of recap of what happened so far, but I believe you should skip it as I think it contains spoilers for the upcoming season. Also it conveys nothing of the quality of the first three seasons. This is a good show, you should watch it, even if the lead female character is bipolar and prone to do crazy things in the name of love. See what I mean?
  • Gotham - A new superhero series will being shortly. Hurray! This time is about Gotham where every supervillain and superhero is young, at the beginning of their "careers". Why are you throwing an adolescent tantrum, Bruce? Because I'm Batman!
  • Ressurection - I've decided not to watch it anymore. It is a pale copy of the original.
  • Vikings - I love this show, however it is beginning to change. It started with eager actors doing a cool project, so they all gave their best and the focus was on the way of the Viking. But now, after a while, the actors are acting more like themselves and the focus of the story shifted towards feudal intrigue.
  • Suits - The fourth season just ended with Mike back at the law firm and the comic relief guy, Louis Litt, leaving the company. I thought the actor got tired of playing a ridiculous man that doesn't seem to do anything right, but the ending of the season goes a different direction.
  • Black Box - As expected, the show was cancelled.
  • Halt and Catch Fire - A lot of emotion, a lot of tension, a lot of drama. Of course it got renewed for the second season, even if it doesn't make a whole lot of sense.
  • Under the Dome - I kept watching and watching and watching until I realized this is the new Lost! Every episode something happens that is completely implausible and unrelated to anything in the previous episodes. I will not watch it anymore.
  • Crossbones - This is a well done show, with good acting and high production values. However it relates to pirates and not even the fun ones. Imagine watching a TV show about drug lords and instead of high powered automatic rifle fights you would see the accountants doing the job of inventorying the proceeds. Black Sails is like that and then they insert some artificial personal drama to spice it up.
  • The Honourable Woman - Described as "The daughter of an assassinated Zionist arms dealer seeks to legitimise the family business while righting the wrongs done to them in the past.", it is a strange little show. I started watching it, but then I stopped. It is heavy, well acted, good production values. I wasn't in the mood for it for a long time, though. The premise is nothing if not brave.
  • The Leftovers - I just couldn't watch it anymore. The entire show was about people feeling depressed and/or suicidal because they were not among the 2% of people who magically vanished. Depressing and pointless.
  • The Witches of East End - I guess it's like The Originals with witches instead of vampires. I keep watching it, though, even if I don't know why. Probably someone placed a spell on me.
  • Tyrant - Speaking of brave TV show premises, this is a show about an Arab-American, who left his birth country because his father was an ass - and the country's tyrannical ruler - who returns there after his father dies. I like the acting and the premise. What I don't like is the condescending viewpoint of the script: the smart educated moral good looking American comes and teaches his older brother how to rule the country based on American principles. But the ending of the first season implies that this is not what it is going to happen at all. Could it be that it will be the series to show Americans that all tyrants are manufactured, more or less, by circumstances? Check out this quote: "CIA guy: The US is not in the business of regime change. Al Fayed: Say that again with a straight face"
  • Taxi Brooklyn - A weird premise for a show that doesn't know what it wants to be: a comedy, a car thing or a police procedural. The idea is that a police detective (female and hot, but with daddy issues, of course) loses her right to drive. Instead, she coopts a French immigrant taxi driver to move her around. He serves as the comic relief most of the time, but also, probably, as the male reason why anything gets done. Decided not to watch it anymore for several reason: the premise, the scripting and the acting being at least three of them.
  • Extant - Female astronaut returns after a solo mission of more than nine months. And she is pregnant. Wonderful premise, however it has several things that are not going for the show: the main actress is Halle Berry, who I completely dislike. Then there is the electronic boy story arch (her husband and she have an artificial son that the husband created) which is either a good subject for another series or completely out of place here. And finally, the "corporate conspiracy" arch, where the guy from Helix is the bad guy. I don't know, imagine Gothica in space, with a little of AI sprinkled over for fun. Ugh!
  • The Bridge - Haven't watched any of the second season episodes, waiting for the wife to see it with me. I will wait for a long time more, I believe.
  • Tokyo Ghoul - I usually make separate blog posts with anime, but this one was nothing that deserves too much attention. Hybrid man and ghoul (something like a vampire that also likes to eat the flesh), the main character is a whinny boy who gets stepped on by just about everybody. In the end he is captured and tortured a lot, which makes him more aggressive and less whinny. But still it's nothing too interesting.
  • Ghost in the Shell - Arise - the modern reboot of GITS, it is not bad. Unfortunately there are only four OVA episodes, each one released months from the previous one. Still waiting for the fourth one. I like the show a lot, but then I am biased, since I love anything related to the Ghost in the Shell universe.
  • The Strain - Guillermo del Toro wrote a horror book with vampires and now he is creating the TV show based on the book. So far I like the series, although I've already read the book and a lot of the surprise is gone. It's brutal, with vampires that are neither sexy nor romantic, but just want to drink all your blood and answer unconditionally to their Master. The Master is even scarier. It is not brilliant, but certainly beats The Living Dead.
  • Blood Lad - Horribly stupid anime. This guy who is a prince in the magical world of demons accidentally meets a human girl who then gets killed. He pledges his support to help her ghost find a body again. Just boring.
  • Longmire - The second season is a lot darker, but for all the wrong reasons, if you ask me. The things I liked in Longmire were to see him being uncompromisingly moral, even if he appears lonely and withdrawn to everybody around him. This season everybody connected to him has to face a metaphorical demon or ten, including Longmire himself. It felt pushed too far, I think.
  • The Lottery - Just like Extant, The Lottery is a sci-fi series centered around a woman. Naturally, the only things she can possibly do is worry about children. You see, for some reason no one is able to sire children anymore. A scientist manages to impregnate 100 embryos and there will be a lottery to give the children to 100 couples. Lots of government conspiracies and child protecting going around. I may watch the rest of the episodes, but the pilot didn't convince me at all.
  • Manhattan - A show about the development of the first atomic bomb. Its take is interesting, focusing on the personal quirks, on the politically incorrect, on the compromises and mistakes, on scientists, military and their spouses alike. What I found fascinating is showing how the obnoxious arrogance of someone truly driven and brilliant is almost forced, as a defense mechanism against getting pulled down by the mediocre. Don't get me wrong, it is not another show about brilliant assholes a la Dr House and does not apologize gratuitous arrogance. Instead it shows how vital it is in the way to success. Given that, the character of Winter is so bloody annoying that I wonder why anyone would put up with such a guy and not kick his ass or just shoot him directly. Perhaps that is another strength of the show: describing how close to failure for some many different reasons the Manhattan Project truly was. It was a government project after all.
  • The Assets - The series ended with episode 8. In that sense, it is actually a miniseries, as the entire premise of the show comes to an end with the final episode. I wrote before that it got cancelled really soon and I believe that the reason is that all characters are really unlikable. Also, since it is based on a book that describes a real event that a lot of Americans know how it went down, the interest was probably small. Also, at the end of the show you realise something: spies are really boring.
  • Legends - A TV series for the sole purpose of keeping Sean Bean alive! :) Sean Bean is this deep undercover agent with a lot of prefabricated "legends", or fake lives, that he uses to infiltrate criminal or terrorist organizations. This leads him to have identity crises, even questioning if any of his lives, including the real one, are actually real. Sexy Ali Larter is his "handler", which can't hurt.
  • Outlander - Is this an attempt at a romantic Yankee in King Arthur's Court? A 1945 nurse is thrown back in time in 1743 Scotland. Her healing skills are helping her join this band of rebellious Scots and experience the life there. The synopsis of the show didn't give me much hope for it, but after watching all the episodes so far it got me hooked. The acting is good and the script is well written. I hope it doesn't deteriorate on the way. It is also intriguing that she has 200 years of extra knowledge, but she doesn't suddenly share antibiotics with the world or try to improve muskets or whatever. Being a woman in a sort of prisoner situation serves to explain that, but how long can it go on like that?
  • The Divide - About a woman that works for an organization that tries to help the wrongly accused in the US justice system. There is a coverup, a conspiracy, White men wrongly accused of killing a Black family, politics, etc. It started as intriguing, but outside the twist that is probably looming, I don't think there is anything really interesting to me in the show. Too political, I guess.
  • The Knick - This is one of the good ones. A look at the professional and personal lives of the staff at New York's Knickerbocker Hospital during the early part of the twentieth century, it is directed by Soderbergh, starring Clive Owen and it is both brutal and truthful. A must see for all the new age assholes that like to think medicine was better at that time.
  • Doctor Who - Season 8 with Capaldi is both interesting and dull. It was supposed to be darker, more intense, but it isn't really. What it is is confusing, though. I didn't like the pilot, but I enjoyed the second and third episodes. I don't know, let's see.
  • Forever - Another "special" person helping the police. Why?! Oh, why?!! This time it's about a guy who cannot die. Every time he dies, he appears somewhere in water, naked. A single, sexy, female police detective partners with him in order to solve crime. I like the actor, though, even if the script is eerily similar to any of the shows in the genre out there. Let's see how it goes.
  • Intruders - "Jack Whelan is a former LAPD officer who is asked to investigate some strange occurrences. He tries to find answers, but he's stonewalled at every turn. Baffled, he continues until he starts to concentrate his search around a secret society that chases immortality by seeking refuge in the bodies of others." The cast seems good. I still have to actually watch it, though.
  • Hysteria - It concerns the idea that people can get afflictions from social media. A perfect reason for Internet control! :) Anyway, the title is perfect as it seems the cause of the problem is hysteria, while the reaction of the people is mass hysteria. The Hannibal Lecter beginning, though, may either be the sign of bad writing or of some ingenious plot device. Wait and see.
  • Hand of God - Ron Perlman? Sign me up! I've seen the pilot though and it's kind of weird. You get this judge who's son just killed himself. He did it because someone raped his wife and made him watch. And so the judge gets born again in a shady church by a preacher who is an ex actor and a con artist. Then the judge starts hearing the voice of God. Some things clearly get lost in translation, because He is always putting Ron Perlman in the situation to be a total ass who everybody thinks is insane. Oh, except the insane people, who think he is the new Solomon. But is he? Weird, huh?

Well, a la prossima!

Monday, September 01, 2014

@font-face not working! ... if you don't write the CSS rule correctly

Just a quick solution for a problem that seems to be @font-face not functioning at all. You define the @font-face CSS rule, you then add a font-family CSS rule for your element and nothing seems to be happening. The element has the correct family when you look in the browser inspection tool, but the font is never loaded. Nor is it displayed. What could be wrong?

The simple answer in my case is that the element I wanted to style had a rule like this: font-family: 'My Special Font, Verdana, Arial';. The correct rule should have been font-family: 'My Special Font', Verdana, Arial;. The quotes are just for escaping spaces and the like for the individual family names, not for encapsulating the "value" of the css rule. I know, stupid, but I wasted half an hour on it!

Thursday, August 28, 2014

Command line Windows Update

Update: If you are behind a proxy, here is some additional code to add right after creating the update session:
'updateSession.WebProxy.AutoDetect = true 'try this first. It doesn't work so well in some environments if no authentication windows appears (*cough* Windows 8 *cough*)

strProxy = "proxy name or address:proxy port"  'ex: 1234:999
strProxyUser = "your username"
strProxyPass = "your password" 

updateSession.WebProxy.Address=strProxy
updateSession.WebProxy.UserName=strProxyUser
updateSession.WebProxy.SetPassword(strProxyPass)

I am working behind a "secured" web proxy that sometimes skips a beat. As a result there are days in which I cannot install Window Updates, the normal Windows update application just fails (with Error Code: 0x80246002) and I am left angry and powerless. Well, there are options. First of all, none of the "solutions" offered by Microsoft seem to work. The most promising one (which may apply to you, but it did not apply to me) was that you may have corrupted files in the Download folder for Windows updates. As a result you need to:
  • Stop the Windows Update service issuing the command line command: net stop wuauserv or by going to Control Panel, Services and manually stopping it.
  • Go to the download folder parent found at %systemroot%\SoftwareDistribution (cd %systemroot%\SoftwareDistribution) and rename the Download folder (ren Download Download.old)
  • Start the Windows Update service issuing the command line command: net start wuauserv or by going to Control Panel, Services and manually starting it.

So my solution was to use a script that downloads and installs the Windows updates from the command line and I found this link: Searching, Downloading, and Installing Updates that pretty much provided the solution I was looking for. There are two issues with the script. The first is that it prompts you to accept any EULA that the updates may present. The second is that it downloads all updates, regardless of severity. So I am publishing here the script that I am using who fixes these two problems: EULA is automatically accepted and only Important and Critical updates are downloaded and installed:
Set updateSession = CreateObject("Microsoft.Update.Session")
updateSession.ClientApplicationID = "Siderite :) Sample Script"

Set updateSearcher = updateSession.CreateUpdateSearcher()

WScript.Echo "Searching for updates..." & vbCRLF

Set searchResult = _
updateSearcher.Search("IsInstalled=0 and Type='Software' and IsHidden=0")

WScript.Echo "List of applicable items on the machine:"

For I = 0 To searchResult.Updates.Count-1
    Set update = searchResult.Updates.Item(I)
    WScript.Echo I + 1 & "> " & update.Title
Next

If searchResult.Updates.Count = 0 Then
    WScript.Echo "There are no applicable updates."
    WScript.Quit
End If

WScript.Echo vbCRLF & "Creating collection of updates to download:"

Set updatesToDownload = CreateObject("Microsoft.Update.UpdateColl")

For I = 0 to searchResult.Updates.Count-1
    Set update = searchResult.Updates.Item(I)

    addThisUpdate = false
    If update.InstallationBehavior.CanRequestUserInput = true Then
        WScript.Echo I + 1 & "> skipping: " & update.Title & _
        " because it requires user input"
    Else
        If update.EulaAccepted = false Then
            update.AcceptEula()
            WScript.Echo I + 1 & ">     Accept EULA " & update.Title 
            addThisUpdate = true
            'WScript.Echo I + 1 & "> note: " & update.Title & " has a license agreement that must be accepted:"
            'WScript.Echo update.EulaText
            'WScript.Echo "Do you accept this license agreement? (Y/N)"
            'strInput = WScript.StdIn.Readline
            'WScript.Echo 
            'If (strInput = "Y" or strInput = "y") Then
            '    update.AcceptEula()
            '    addThisUpdate = true
            'Else
            '    WScript.Echo I + 1 & "> skipping: " & update.Title & _
            '    " because the license agreement was declined"
            'End If
        Else
            addThisUpdate = true
        End If
    End If

    If addThisUpdate AND (update.MsrcSeverity = "Important" OR update.MsrcSeverity = "Critical") Then
        'wscript.echo ("This item is " & update.MsrcSeverity & " and will be processed!")
    Else
        'comment these lines to make it download everything
        wscript.echo (update.Title & " has severity [" & update.MsrcSeverity & "] and will NOT be processed!")
        addThisUpdate=false
    End If

    If addThisUpdate = true Then
        wscript.echo(I + 1 & "> adding: (" & update.MsrcSeverity & ") " & update.Title)
        updatesToDownload.Add(update)
    End If
Next

If updatesToDownload.Count = 0 Then
    WScript.Echo "All applicable updates were skipped."
    WScript.Quit
End If
    
WScript.Echo vbCRLF & "Downloading updates..."

Set downloader = updateSession.CreateUpdateDownloader() 
downloader.Updates = updatesToDownload
downloader.Download()

Set updatesToInstall = CreateObject("Microsoft.Update.UpdateColl")

rebootMayBeRequired = false

WScript.Echo vbCRLF & "Successfully downloaded updates:"

For I = 0 To searchResult.Updates.Count-1
    set update = searchResult.Updates.Item(I)
    If update.IsDownloaded = true Then
        WScript.Echo I + 1 & "> " & update.Title 
        updatesToInstall.Add(update) 
        If update.InstallationBehavior.RebootBehavior > 0 Then
            rebootMayBeRequired = true
        End If
    End If
Next

If updatesToInstall.Count = 0 Then
    WScript.Echo "No updates were successfully downloaded."
    WScript.Quit
End If

If rebootMayBeRequired = true Then
    WScript.Echo vbCRLF & "These updates may require a reboot."
End If

WScript.Echo  vbCRLF & "Would you like to install updates now? (Y/N)"
strInput = WScript.StdIn.Readline
WScript.Echo 

If (strInput = "Y" or strInput = "y") Then
    WScript.Echo "Installing updates..."
    Set installer = updateSession.CreateUpdateInstaller()
    installer.Updates = updatesToInstall
    Set installationResult = installer.Install()
 
    'Output results of install
    WScript.Echo "Installation Result: " & _
    installationResult.ResultCode 
    WScript.Echo "Reboot Required: " & _ 
    installationResult.RebootRequired & vbCRLF 
    WScript.Echo "Listing of updates installed " & _
    "and individual installation results:" 
 
    For I = 0 to updatesToInstall.Count - 1
        WScript.Echo I + 1 & "> " & _
        updatesToInstall.Item(i).Title & _
        ": " & installationResult.GetUpdateResult(i).ResultCode   
    Next
End If
WScript.StdIn.Readline()

Save the code above in a file called Update.vbs and then creating a batch file that looks like this:
@ECHO OFF
start "Command line Windows update" cscript Update.vbs

Run the script and you will get the .vbs executed in a command line window that will also wait for pressing Enter at the end of execution so you can see the result.

For other solutions that are more system admin oriented, follow this link which provides you with a lot of possibilities, some in PowerShell, for example.

Also, I didn't find a way to install the updates without the Windows annoyance that asks me to reboot the computer popping up. If you know how to do that, I would be grateful.