Older blog entries for shlomif (starting at number 733)

Tech Tip: Fix Poor Internet Connectivity by Restarting the Router

I noticed that one can often fix poor home Internet connectivity (I have an ADSL connection but it may apply to other types of Internet connection), by powering off the router and starting it again (“restart/reboot”). So I’ve made a mental note to keep it in mind and now it’s in this blog as a tip. Cheers!

Licence

You can reuse this entry under the Creative Commons Attribution 3.0 Unported licence, or at your option any later version of it. See the instructions of how to comply with it.

Syndicated 2015-06-25 09:48:32 from shlomif

git Tip: How to Call “git bisect start”

“git” is an open-source distributed version control system that has recently gained a lot of popularity. The “git bisect start” synopsis in “git help bisect” is somewhat misleading:

git bisect start [--no-checkout] [<bad> [<good>...]] [--] [<paths>...]

One has to specify both the “bad” and the “good” revisions explicitly or else “git bisect” will wait for the missing ones to be specified, which will be confusing. So specify them immediately at the “git bisect start” invocation.

Incidentally, perl-5.22.0 was released a few days ago. Grab it while it’s hot!

Licence

You can reuse this entry under the Creative Commons Attribution 3.0 Unported licence, or at your option any later version of it. See the instructions of how to comply with it.

Syndicated 2015-06-06 17:11:00 from shlomif

Linux Tip: How to Determine Which Program is Emitting Sounds

Here's a tip you may find useful about how to determine which program is emitting sounds on a modern Linux system. This tip requires PulseAudio to be enabled , and if that's the case, just start up KDE’s KMix and see which applications spring up in the “Playback Streams” tab. Hope it helps, and good luck.

Licence

You can reuse this entry under the Creative Commons Attribution 3.0 Unported licence, or at your option any later version of it. See the instructions of how to comply with it.

Syndicated 2015-06-02 15:02:25 from shlomif

Vim Tip: Going to the top or bottommost window/viewport

In the Vim and GVim text editors, one can use Ctrl+W;t (or Ctrl+w;Ctrl+t) to go to the topmost/most top window (= a section of the screen in Vim terminology) and Ctrl+W;b to go to the bottommost/most bottom one.

Cheers!

Syndicated 2015-05-29 17:08:46 from shlomif

Tech Tip: How to Configure Qt 5 Behaviour When Running on KDE4

Recently, I noticed that when running the VLC-2.2.0 prerelease, which is based on Qt 5 for its GUI, on my Mageia Linux 5 system on top of KDE 4, then in the playlist a single-click immediately played a file instead of selecting it, while reserving a double click for activation. After a long amount of research and thought, I figured out a way to configure Qt 5 on top of KDE.

To do so:

  1. Install lxqt-config and the “lxqt-qtplugin”.

  2. Add the line “export QT_QPA_PLATFORMTHEME=lxqt” somewhere before the desktop startup in your “.Xclients” or “.xinitrc” file (or in your “.bashrc”).

  3. Restart the X/KDE environment.

  4. Run “lxqt-config” to configure the appropriate behaviour.

This way one can use the Qt5 customisations of lxqt in KDE 4. Enjoy!

Licence

You can reuse this entry under the Creative Commons Attribution 3.0 Unported licence, or at your option any later version. See the instructions of how to comply with it.

Syndicated 2015-02-28 12:12:47 from shlomif

“Out of the Strong, Something Sweet” - How a Bug Led to a Useful Optimisation

The book Fortune or Failure: Missed Opportunities and Chance Discoveries (which my family used to own, but which I did not read) gives the case to the important role of luck and chance in scientific discoveries. Recently, when working on Project Euler Problem No. 146 I came up with a case of an accidental bug, that in turn led to an idea for a significant optimisation.

The C code with the bug (which was in turn translated from some Perl code) looked something like that:

#define DIV 9699690
#define NUM_MODS 24024
#define NUM_PRIMES 8497392

int primes[NUM_PRIMES];
int mods[NUM_MODS];

typedef long long LL;

static inline bool is_prime(LL n)
{
    LL lim = (LL)(sqrt(n));

    for (int p_idx=0; p_idx < NUM_MODS ; p_idx++)
    {
        typeof (primes[p_idx]) p = primes[p_idx];
        if (p > lim)
        {
            return true;
        }
        if (n % p == 0)
        {
            return false;
        }
    }
    return true;
}

.
.
.
            for (int y_idx=0;y_idx<sizeof(y_off)/sizeof(y_off[0]);y_idx++)
            {
                if (! is_prime(sq + y_off[y_idx]))
                {
                    goto fail;
                }
            }
            for (int n_idx=0;n_idx<sizeof(n_off)/sizeof(n_off[0]);n_idx++)
            {
                if (is_prime(sq + n_off[n_idx]))
                {
                    goto fail;
                }
            }

As you can notice eventually, the problem was that in the p_idx loop, NUM_MODS should have been the larger NUM_PRIMES. This caused the test for primality to finish faster, but to sometimes return true instead of false. As a result, I noticed that some numbers were erroneously reported as suitable, but the program finished much faster.

I corrected it and reran the program which was now much slower, but this led me to think that maybe the lower limit to the count of primes can be a pre-filter for primality for the “y_idx”/“y_off” numbers, that will run quicker and eliminate some numbers. As a result, I did this:

#define NUM_PRIMES__PRE_FILTER 24024

static inline bool is_prime__pre_filter(LL n)
{
    LL lim = (LL)(sqrt(n));

    for (int p_idx=0; p_idx < NUM_PRIMES__PRE_FILTER ; p_idx++)
    {
        typeof (primes[p_idx]) p = primes[p_idx];
        if (p > lim)
        {
            return true;
        }
        if (n % p == 0)
        {
            return false;
        }
    }
    return true;
}

.
.
.
            for (int y_idx=0;y_idx<sizeof(y_off)/sizeof(y_off[0]);y_idx++)
            {
                if (! is_prime__pre_filter(sq + y_off[y_idx]))
                {
                    goto fail;
                }
            }
            for (int y_idx=0;y_idx<sizeof(y_off)/sizeof(y_off[0]);y_idx++)
            {
                if (! is_prime(sq + y_off[y_idx]))
                {
                    goto fail;
                }
            }
            for (int n_idx=0;n_idx<sizeof(n_off)/sizeof(n_off[0]);n_idx++)
            {
                if (is_prime(sq + n_off[n_idx]))
                {
                    goto fail;
                }
            }

This made the program finish in under a minute, while yielding the correct solution. The original program, with the bug fix, was still running after several minutes.

So the bug proved to be useful and insightful. One possible future direction is to merge the two “y_idx” loops into a single function that will accept an array of numbers, and will check them all for primality using the same divisors simultaneously, so as soon as one of them is found to be non-prime, a verdict will be reached.

Licence

You can reuse this entry under the Creative Commons Attribution Noncommercial 3.0 Unported licence, or at your option any later version. See the instructions of how to comply with it.

Syndicated 2015-02-26 18:23:14 from shlomif

Optimisation Tip: Avoid Excessive Forks+EXECVEs to Processes

This will come as a surprise to few, but performing a separate fork() and EXECVE system calls (e.g: for `factor "$n"` in Perl or popen in C), on each iteration of a loop can really kill performance. One option to reduce that would be to read individual lines from a seq 2 999999 | xargs factor loop, or avoid forking altogether.

I discovered this issue while working on Project Euler problem #141, and I should have realised that the sub-100% CPU utilisation of the program was caused by the excessive spawning of new processes.

Licence

You can reuse this entry under the Creative Commons Attribution 3.0 Unported licence, or at your option any later version. See the instructions of how to comply with it.

Syndicated 2015-02-22 13:33:16 from shlomif

Tech Tip: Make Jamendo Playback Work in Firefox on Mageia Linux

If you’re having a problem playing Jamendo tracks after pressing the “Listen” button (such as on this page) on Firefox running on Linux, then try to install the packages «gstreamer0.10-plugins-bad gstreamer0.10-plugins-good gstreamer0.10-plugins-ugly gstreamer0.10-mpeg gstreamer0.10-ffmpeg» (relevant to Mageia; try their equivalent in other distributions), restart Firefox and try again. The problem is that Firefox needs extra gstreamer plugins to play proprietary formats in HTML audio and video elements. Cheers!

(Thanks to “dolske” from #firefox on irc.mozilla.org for their help.)

Licence

You can reuse this entry under the Creative Commons Attribution 3.0 Unported licence, or at your option any later version. See the instructions of how to comply with it.

Syndicated 2015-02-05 08:34:51 from shlomif

Tech Tip: Make Jamendo Playback Work in Firefox on Mageia Linux

If you’re having a problem playing Jamendo tracks after pressing the “Listen” button (such as on this page) on Firefox running on Linux, then try to install the packages «gstreamer0.10-plugins-bad gstreamer0.10-plugins-good gstreamer0.10-plugins-ugly gstreamer0.10-mpeg gstreamer0.10-ffmpeg» (relevant to Mageia; try their equivalent in other distributions), restart Firefox and try again. The problem is that Firefox needs extra gstreamer plugins to play proprietary formats in HTML audio and video elements. Cheers!

Licence

You can reuse this entry under the Creative Commons Attribution 3.0 Unported licence, or at your option any later version. See the instructions of how to comply with it.

Syndicated 2014-12-13 12:15:09 from shlomif

Emma Watson’s Visit to Israel&Gaza; ; “So, Who the Hell is Qoheleth?”

Here are the recent updates for Shlomi Fish’s Homepage.

  1. “Emma Watson’s Visit to Israel and Gaza” is a work-in-progress Real Person fiction screenplay which aims to bring Shalom to the turbulent Gaza Strip/Israel border:

    Waitress: I hope you’re having a good time, ah…

    EmWatson: Emma… Emma Watson!

    Waitress: Oh! I heard about you, naturally. Are you gonna threaten me with a wand? Heh!

    EmWatson: A wand… yes, the bane of my existence. I’m thinking of collecting money for a public campaign to convert the weapon most associated with me to something more menacing.

    Waitress: Don’t you have enough money for that?

    EmWatson: No, not enough! Heh. And money isn’t everything.

    Waitress: So you’re not playing in films for money?

    EmWatson: Playing in films for money? Of course not! What a preposterous idea.

    Waitress: Ah, nice.

    EmWatson: I’m playing in films for a shitload of money!

  2. “So, who the Hell is Qoheleth?” - is a new illustrated screenplay that tells what I imagine to have happened to the author of the Biblical book of Ecclesiastes / Qoheleth shortly after he has written it. The timing is appropriate because Ecclesiastes is being read during the upcoming Sukkot Jewish holiday.

    Josephus: Anyway, can you share some details about your trip? I never ventured a long way past Damascus.

    Athena: Sure! It was very interesting. Most interesting.

    Athena: We travelled with our own people and some Greek merchants, all the way to Athens, and there we hitchhiked a ride with some Assyrian merchants, hoping it will get us closer to Alexandria. There were some guards escorting us, and at one point they disarmed us and threatened us at sword’s point to have sex with them or else they'll kill us and take all our possessions.

    Josephus: Wow! Rape. So what did you do?

    Athena: Well, we consulted between ourselves and after a long while of being really scared, we calmed down a little, and decided that if we are forced to have sex, we might as well cooperate and try to enjoy it. So we told them that we’ll do it willingly and they agreed.

    Josephus: How clever of you! And then what happened.

    Athena: Well, the three of us and her lover each found their own part of the woods, and we had sex. Then, after one or two times, the three men all lost stamina, while we were not completely satisfied and cried for more!

    [ Josephus laughs. ]

    Alexis: Yes! Then we heard each other’s cries and we gathered at one place together still naked with our clothes as cover, and we bitched about the whole situation - in Greek - and the men stood there ashamed.

    Athena: Yes! Anyway, we continued as couples throughout the trip and the men got better in love making as time went by, and they also taught us a little Aramaic. Then we arrived at the junction - they wanted to go to Assyria, and we wanted to head more south, and then all the 6 of us were completely emotional and offered each other to escort them on the way, so we won’t part, but we eventually cared enough about the others to let them go on their own way.

    Josephus: Wow! That sounds like love.

    Athena: Love! Yes! That’s the word. Eros in action.

  3. A new essay A #SummerNSA’s Reading has been added for summarising the concentrated “#SummerNSA” / Summerschool at the NSA effort during the summer of 2014.

  4. There are new factoids in the Facts Collection:

    “Talk Like a Pirate Day” is the only day of the year when Chuck Norris only talks like a pirate, and does not actually act like one.

    On Yom Kippur (= the Jewish Day of Atonement), Chuck Norris forgives God for his sins.

    Chuck Norris once refactored a 10 million lines C++ program and was done by lunch time. It then took Summer Glau 5 minutes to write the equivalent Perl 10-liner.

  5. There are some new captioned images and aphorisms:

    Every mighty Klingon warrior has Watched Sesame Street

    Every Mighty Klingon warrior has watched Sesame Street!

  6. The screenplay Buffy: A Few Good Slayers has some new scenes:

    [ Faith is teaching Becky and the rest of the class how to throw knives. ]

    Faith: Becky, it’s nice that you hit the mark three times in succession, but you’re not always holding the knife correctly.

    Becky: OK, Ms. Harris. Can you show me how to do that again? [She prepares her phone.]

    Faith: OK, here goes.

    [ Cut to the bullseye - three knives hit it quickly. ]

    Faith: How´s that?

    Becky: That’s very nice, but as my mobile‘s video demonstrates, you didn’t hold the knife “correctly” (in quotes) once.

    Faith: Let me see. [She watches the video.] Oh crap.

    Faith: Becky, Becky… you have a lot of potential. You’re more than a pretty face.

    Becky: Heh, I knew that I have potential, but do you really think I have a pretty face?

    Faith: If my opinion as a straight, married, woman, matters, I think you do.

    Becky: Thanks, Ms. Harris.

    Faith: OK, class dismissed. Please try to practise at your free time, we’re going to have a test soon.

    [ The students rise up and leave. ]

Syndicated 2014-10-05 12:35:17 from shlomif

724 older entries...

New Advogato Features

New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!