Refactor unit tests?

When we work with legacy code and need to do changes, we first write tests on the current behavior. That way we can implement new changes with confidence. We can even refactor the code.

Legacy code is often bad code, and after some refactoring the code may be simpler, easier to test. Since the refactor has been validated by the tests should we also refactor the tests if we can make them simpler/clearer or keep them as they were written?

Go to Source
Author: JayZ

Why .deb packages never add desktop and start menu shortcuts, even if installed software is graphical UI only?

Sorry if it’s a lame question but why installing software from .deb package never seems to add any shortcuts to desktop and start menu, even if installed software is a graphical UI program?

For example, try installing Chrome on fresh Ubuntu 20.20. You go to official chrome page where it will point you to the latest .deb package. Great. You download and install the package. Perfect. But then what?

No shortcut on desktop, no icon in start menu and -if you happened to close the package installer window – you even have no clue where the software was installed.

Is this fundamentally impossible due to some technical limitations of the package manager or is it just laziness of package creators which don’t care about auto creating those launcher shortcuts on desktop?

I’ve just installed new Ubuntu, installed Chrome and was puzzled how counter-intuitive and user-unfriendly the whole process is. I had to 1) find where the stuff from .deb was physically installed 2) create launcher manually 3) assign an icon to the shortcut manually.

Go to Source
Author: PawelRoman

How to download a zipfile from a Github repository

I’m trying to download a zipfile from a Github repository with this command:

wget --no-check-certificate https://github.com/brendenlake/omniglot/blob/master/python/images_evaluation.zip -O /tmp/images_evaluation.zip

But it doesn’t download a valid zip file. I suppose that it downloads the HTML file that the browser shows if you click on the url.

How can I download a zip file from a public Github repository using wget?

Go to Source
Author: VansFannel

Alternative to synonym search over AWS managed Elasticsearch instance

I am working a search implementation wherein I have to use the synonym filter but the challenge I am facing here is how do I make it dynamic, I can not pass the filters in the mapping itself. I need some way to externalize it. But apparently, its not supported in the AWS managed version.

Is there any other way I can do it here?

Go to Source
Author: Steve B

mouse and keyboard not working on Ubuntu 20.04

I’m sorry I’m new to Ubuntu so I’ll try be as descriptive as possible.
At the moment my mouse is working when plugged into a specific USB port on the back of my PC. However when I move it to another port it doesn’t work. If I plug my keyboard into this same USB port then the keyboard will work and the mouse won’t. I have my system on a dual boot at the moment and I know for a fact that both the mouse and keyboard do work, it’s only when I reach the login screen that I have issues with my keyboard/mouse. I have tried other solutions given on this site and elsewhere but they don’t seem to work.
Like I said I’m new to Ubuntu and Linux as a whole so I’m sorry if this is an obvious question.

Go to Source
Author: Alexander Hunter

Multiple intersection tables vs multiple joins

I have a hierarchical relationship between my tables, with the children having foreign keys referring back to their parent ids (assuming id is the primary key for each table):

Department has many Category Groups
Category Group has many Category(-ies)
Category has many Sub-Category(-ies)
Sub-Category has many Attributes.

Now, all these entities except for Attributes are optional meaning if I don’t select anything on my hierarchical cascading dropdown based UI, I need to display the Attributes that belong to all Departments, if I only select a Department then I need to display Attributes that belong to all Category Groups belonging to that Department and so on.

Obviously, one option to implement it is to do a inner join between all the tables to get to Attribute. For instance, if nothing is selected it will be:
Department inner join Category Group
inner join Category
inner join Sub-Category
inner join Attribute
to show all the attributes belonging to all departments.

The other thought in my head is to have intersection/relation mapping table(s) –
DepartmentAttributeRelation which has foreign keys to Department and Attribute,
CategoryGroupAttributeRelation which has foreign keys to CategoryGroup and Attribute and so on.
This will enable direct search to get to the Attributes given any entity.

My question is – Are there any downsides to the second approach above or are there any better approaches to solve this?

Go to Source
Author: linuxNoob

Is `en_US.utf8` canonically wrong?

The output of locale seems to distinguish between upper and lowercase:

% locale -a 
C
en_AU.utf8
en_US.utf8
POSIX

Almost everywhere else in the wild seems to use the uppercase .UTF8, however glibc normalises locales to lowercase, and comments:

There is no standard for the codeset names.

What is the standard that defines the form <language>_<country>.<codeset>? Is it really silent on code page capitalisation?

Go to Source
Author: Tom Hale

How to apply custom filters for John The Ripper when cracking RAR3 archive password?

My problem is that I’m trying to crack RAR file with is encrypted with RAR3 encryption.
Decided to try with John The Ripper.
Here are clues I have from my friend.

  1. Max password length is 8
  2. Only capital letters or digits

And I need now filter to make John crack the password without trying to check small lowercase letters.
On hashcat it’s easy to do but program do not support $RAR3$*1 type of hashes.

Go to Source
Author: Madiator2011

GRUB not picking up windows boot manager which is in another drive

Ubuntu 18.04 LTS and Windows 10
I have a laptop that has an SSD and a hard drive
Windows is on the SSD and Ubuntu on the Hard Drive
I made a separate EFI partition while installing ubuntu using the “Something Else” option
When I boot my laptop I have to press “Esc” key to enter GRUB and it does not pickup the windows boot manager
Moreover, Ubuntu is not detecting the SSD
What to do ?
Please ask for any additional info required

Go to Source
Author: Tanmay Bhatnagar

What exactly does PostgreSQL (or other databases) do internally when you “prepare” a query rather than just running it directly?

When I face a huge number of repeated INSERTs in a loop, I tend to first create a “prepare skeleton query” prior to the loop, and in the loop, I simply “execute” this prepared query and send it all the values. I heard long ago, and can understand in some abstract sense, that this is more optimized than just having the loop with a normal parameterized query in it.

However, I don’t understand what exactly PG is doing that makes it so much faster. If it even is so much faster. I frankly have never done any real benchmarks to compare the two different methods.

Also, shouldn’t PG be “warmed up” to a query once you repeat it several (let alone many) times in very short succession, and perhaps do the same thing as I do manually, but internally, when I just use a normal parameterized query?

I find myself constantly second-guessing what the database is up to internally. I have no real grasp of how “smart” it is. I fear that I’m doing a lot of things which are meaningless because it’s already taken care of internally by its smart code.

Maybe “preparing” and “executing” is an archaic practice which has no real benefit these days?

It sounds like PG is basically allocating resources to “prepare” for upcoming huge amounts of similar INSERT queries, but I don’t understand what exactly it would do differently compared to just executing them one by one. I also don’t understand what the point would be of a non-INSERT prepared query/statement.

PS: Just to clear up any confusion: I never use non-parameterized queries, whether they are prepared or not. A lot of people confuse “parameterized queries” and “prepared statements”. Even I called the latter “prepared queries” in this question…

Go to Source
Author: Jevontay Rohler

How to actually set up MariaDB replication/high availability

I’m setting up a high availability LAMP stack – so far, I have two servers with HAProxy running on both their frontends that own a floating IP. HAProxy redirects requests to backend Apache servers running on each of them (same machine, port 8000).

This all works, and I’m happy with this so far for high availability. I have yet to deal with the databases yet however.

Since I only have two servers, I don’t think I can do master-master like Galera cluster due to the requirement of quorum. So, I planned to do master-slave read only replication.

Most of the guides I see online don’t mention the MaxScale proxy that MariaDB suggests in its high availability guide (page 4 for example)

I’m just really confused overall on what to do and how to set it up?

From my perspective, I’d like to set up a MaxScale proxy on one of my servers and run MariaDB on both servers; MaxScale will handle things like redirects. How can I actually accomplish what I’m looking for?

Go to Source
Author: forkwasher

Benefits of “Bluetooth LE Privacy” feature?

For making an (until now, un-) educated guess about the necessity of spending the effort of including the “Bluetooth LE Privacy” feature in a consumer, embedded device’s BT software, I am seeking information about the “necessity” from an information security standpoint of offering this feature – is it useful? does it really solve a security issue or is it already broken?

The BT SIG itself is fairly quiet about this feature besides well-worded blog posts, so shedding a little light on this would help tremendously in making the decision to “go the extra mile” or just leave it aside.

Go to Source
Author: Christian

WordPress API single post

I’m grabbing a list of posts from Blog A to Blog B using the wordpress API, so far everything is fine, but how do I access the single post inside Blog B? How do I make it so when I access /blog/post-name it shows me the content from the same post from Blog A?

Anyone has an idea?

Go to Source
Author: Radu033

Pattern name for “Platform independant class with Hooks + sub class implementing platform specific”?

I am developing an android app to process jpg exif meta data in a workflow.

The Workflow class is implemented platform independant (i.e. code runs on android and on j2se).

The Workflow contains and calls protected virtual methods that do nothing for android specific .functions (i.e save changes to android media database)

package de.k3b.media;

// platform independant
public class Workflow {
    public void processPhoto(...) {
        ...
        saveChangesToMediaDatabase(....);
        ...
    }
    
    protected void saveChangesToMediaDatabase(...) {    
        // to nothing in platform independant version
    }
}

I also have a android platform specific sub class that implements the platform specific code

package de.k3b.android.media;

// android platform dependant
public class AndroidWorkflow extends Workflow {
    @Override
    protected void saveChangesToMediaDatabase(...) {    
        ... do something with android media database
    }
}

I can use Workflow.processPhoto(...) in non-android j2se apps and in automated unit or integration tests
and i can use AndroidWorkflow.processPhoto(...) in my android app

My question: Is this an established pattern and is there a name for this pattern?
My current pattern name “Platform independant class with Hooks” and “Platform specific Hook implementation”.

I hope to find a better (??established??) name for this pattern.


Remarks:

One established pattern to have platformindependat code is by using a Facade pattern.

Example: I use a FileFacade with a j2se implementation based on java.io.File and AndroidFileFacade which is based on android specific DocumentFile.

Although the goal of platform independance is the same the way how this is achieved is different.

Go to Source
Author: k3b