Tired of ads? Upgrade to paid account and never see ads again!
Shlomif's Technical Posts Community [entries|archive|friends|userinfo]
Shlomif's Technical Posts Community

[ userinfo | livejournal userinfo ]
[ archive | journal archive ]

Links
[Links:| Shlomi Fish's Homepage Main Journal Homesite Blog Planet Linux-IL Amir Aharoni in Unicode open dot dot dot ]

Tech Tip: How to Configure Qt 5 Behaviour When Running on KDE4 [Feb. 28th, 2015|02:12 pm]
Shlomif's Technical Posts Community

shlomif
[Tags|, , , , ]
[Current Location |Home]
[Current Mood |Happy]
[Current Music |Tiffany Alvord - Hurt Me Tomorrow (K'NAAN cover)]

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.

LinkLeave a comment

“Out of the Strong, Something Sweet” - How a Bug Led to a Useful Optimisation [Feb. 26th, 2015|08:23 pm]
Shlomif's Technical Posts Community

shlomif
[Tags|, , ]
[Current Location |Home]
[Current Mood |Happy]
[Current Music |Tomita Isao - Theme From Star Wars]

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.

LinkLeave a comment

Optimisation Tip: Avoid Excessive Forks+EXECVEs to Processes [Feb. 22nd, 2015|03:33 pm]
Shlomif's Technical Posts Community

shlomif
[Tags|, , , , ]
[Current Location |Home]
[Current Mood |Productive]
[Current Music |Stefano Mocini - Winds (Ready for an adventure) - from Jamendo]

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.

LinkLeave a comment

Tech Tip: Make Jamendo Playback Work in Firefox on Mageia Linux [Feb. 5th, 2015|10:34 am]
Shlomif's Technical Posts Community

shlomif
[Tags|, , , , ]

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.

LinkLeave a comment

Game Recommendation: “Untrusted: a User JavaScript Adventure Game” [Apr. 21st, 2014|12:47 pm]
Shlomif's Technical Posts Community

shlomif
[Tags|]
[Current Location |Home]
[Current Mood |lazylazy]
[Current Music |StrangeZero - Nanofly (from Jamendo.com)]

If you’re a software developer, you should check out the game “Untrusted: a user JavaScript adventure game” which someone on ##programming referred me to and which I became fond of. It is a game that involves writing some JavaScript code in certain designated places in order to make progress.

On a different note, I found the Jamendo album Nanofly by StrangeZero to be very nice and you should also check it out.

LinkLeave a comment

Tech Tip: add a notification (or any other command) after a command-line task has ended [Mar. 30th, 2014|06:33 pm]
Shlomif's Technical Posts Community

shlomif
[Tags|, , , ]
[Current Location |Home]
[Current Mood |productive]
[Current Music |The White Panda - Bearly Legal]

I discovered that one can add a notification after a command you've already started running has ended on a UNIX system by suspending the command using “Ctrl + Z” and then typing something like “fg ; n --msg 'Command finished'” (where “n” is the command I use for notifications). “fg” brings a job to the foreground, and for more information about it see its wikipedia entry and the Unix Background Jobs entry on thegeekstuff.com.

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.

LinkLeave a comment

Tech Tip: Resetting the GLib/Gtk+ Default Apps on Linux (e.g: the Default Browser) [Mar. 8th, 2014|01:31 pm]
Shlomif's Technical Posts Community

shlomif
[Tags|, , , , ]
[Current Location |Home]
[Current Mood |happyhappy]
[Current Music |Herman’s Hermits - There’s a Kind of Hush]

In this tip, I would like to describe how to reset the default apps, and especially the default browser, for GLib and GTK+. These are used by desktops like GNOME and XFCE, and by GTK+ applications such as HexChat or claws-mail. My problem originally was that I accidentally pressed the "Yes" button when Firefox Nightly (installed under a prefix under /opt) asked me whether I should set it as the default browser, which caused HexChat and Claws-Mail to open links using it by default.

Anyway, to resolve this problem do this:

  1. Go to ~/.local/share/applications.

  2. Backup this directory somewhere safe.

  3. The mimeapps.list file contains the reference to use the offending apps under the *.desktop files there which you can search for the reference to the apps.

  4. Remove these line or their portions from mimeapps.list.

Now you may need to restart the desktop apps or the desktop environment (not sure).

Hope it helps.

Here’s how I found it: after some false leads of either trying to recursively search my home directory for occurrences of /opt/firefox and reading the source code of HexChat, GLib and gtk+ to see where this happens (there were too many levels of indirection there), I ended up doing “strace -f -o hexchat.strace hexchat” and inspecting the strace file for hints.

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.

LinkLeave a comment

The Lost Souls of Freenode [Feb. 25th, 2014|04:02 pm]
Shlomif's Technical Posts Community

shlomif
[Tags|]
[Current Location |Home]
[Current Mood |lazylazy]
[Current Music |Grace Valhalla - Apricot Hill (from Jamendo.com)]

I originally wanted to write a more prose-like blog post about the topic of “The Lost Souls of Freenode”, echoing some of my frustrations from trying to help people on Freenode channels, especially #perl and ##programming and I started from keeping a list of bullets and sub-bullets and decided to keep it this way out of being lazy. Maybe it can also be considered the blog equivalent of some wikiHow pages.

After I gave a link to the bullets to someone I met on Freenode, he told me he hasn't found any of what he read here surprising from his experience on IRC and as a tutor and T.A. (= Teacher Assistant) in an American college.

  • “Many Lost Souls” on Freenode's #perl - IM conversation.

  • Quote the conversation about “First rule of #perl channels” (meaning that Freenode’s #perl is our first line of defence).

  • People having problems getting indentation right.

  • People who /msg me after asking.

    • Either they think that's the way to answer.
    • Or they think that I cannot help them because there's another conversation.
    • They're usually not willing or cannot afford to pay.
    • Someone who thought that paying me 50 USD / hour for private help was too high.
  • * People who want us to write their code for them.

  • “Help me with a script I found.”

    • Often badly written.

  • “Help me with using a program / my operating system / etc.”

    • Not even related to coding.

    • “Are you using version control?” “No, what's that?”
    • Automated tests?
    • A debugger?
  • Old versions of perls.
    • Homework/scholastic constraints.

    • “We didn't study it yet”

    • “No external modules / CPAN”

    • “Not allowed to use any built-in language data structures, including not arrays.”

      • Mandatory course.

      • Graded 0 once because was programmed on Python-2.7.x and tested on Python-3.3.x (on Windows).

  • One who didn't know what files are nor did file I/O.

    - Ruby

    - private conversation with someone else who didn't know what files are.

LinkLeave a comment

Tech Tip: Empty tag in XHTML served as text/html [Jan. 14th, 2014|04:25 pm]
Shlomif's Technical Posts Community

shlomif
[Tags|, , , ]
[Current Location |Home]
[Current Mood |productive]
[Current Music |Set Fire to the Rain - Cover by Spencer Borup with Cimorelli]

If you serve XHTML (= HTML written using XML grammar and conventions) as Content-Type: text/html, you may be tempted to write an empty <div> tag as a standalone XML tag with a trailing slash using <div id="my_anchor" />. Don’t do that, because with text/html (a.k.a “tag-soup”) the browser may think you just have an opening tag and will look for a closing tag elsewhere. Instead, write a pair of opening and closing tags, e.g: <div id="my_anchor"></div>.

Using the first form confused both Firefox (24.2.x in my case) and Google Chromium (whatever shipped with Mageia at the time), and made them misrender my page, despite the fact that it validated as valid XHTML. Perhaps I should have considered putting the id=".." inside a meaningful sub-section of the document, but I implemented something for skipping a section navigation menu.

LinkLeave a comment

Tech Tip: Mitigating “git clone”’s inability to be resumed using rsync [Jan. 2nd, 2014|02:43 pm]
Shlomif's Technical Posts Community

shlomif
[Tags|, , ]
[Current Location |Home]
[Current Mood |Productive]
[Current Music |Chumbawamba - Tubthumping]

Happy new civil year, everyone. As you may know Git is a distributed version control system, but its often time-consuming (if the repository’s history is large) “git clone” operation cannot be resumed, which is a problem with bad Internet connections. There was a service that did “git clone” and then allowed people to download using HTTPS Called “Git bundler” but it has been down for sometime now. However, I found a different solution to the problem.

What can be done is use ssh to log in to a remote host, where the “git clone” is performed (preferably, but not absolutely necessarily, when running on top of a session of tmux, GNU Screen or similar). After that, you can use rsync over ssh to download the .git directory to the local workstation (I like to use the invocation rsync -a --progress -v --inplace for that).

Following that all you have to do is run git clone to a different directory to the one where you put the .git and set “git remote” appropriately.

Hope that helps, and the same can be done with other distributed version control systems such as Mercurial, or Bzr.

LinkLeave a comment

navigation
[ viewing | most recent entries ]
[ go | earlier ]