Fatal: Refusing to Merge Unrelated Histories

fatal: refusing to merge unrelated histories

I get this error every now and then. This happens when I created a new branch first right after a new Git project was started (by me), without bothering to base it from the Master branch. The reason is the lack of permission/access to being able to write or put anything on the latter branch.

Rather than waiting for someone to kick off the Master branch, I just go ahead and start my own branch as I’ve mentioned earlier. Later on, somebody from the team who has write permissions to Master, starts a README file just to initiate it. Thus the “unrelated histories” issue happens from then on. Two branches that started off independently from each other and with no common base.

The issue appears when I want to merge my branch to Master. Git will say my branch is behind on commit on the branch it will be merged into. If I try to merge it, it gets rejected. The pipeline also won’t allow for merge conflicts like this, and advises me to fix it first.

ANSWER

As I recall, this behavior started after a certain Git version only. This to avoid to unnecessarily create a parallel history being merged into the project, because a previous merge happened between to branches that didn’t have a common base.

I’ve used Git’s “–allow-unrelated-histories” option to fix this problem. I’ll do this via command line.

Pull the Master branch into mine with the option above included.

Fix the merging conflict.

Commit the changes.

Push to remote repository.

Then this time the merge request to Master will not warn that my branch is behind a commit.

Others have commented saying that rebasing also does the trick for them. I do not recall having gone that route though.

The paragraph is green. Why?

I came across this sort of “CSS riddle” recently.

It goes something like this.

Given this CSS definition,

body {
  max-width: 28em;
  margin: auto;
  padding: 1em;
}

html {
  --color: green;
}

body {
  color: yellow;
}

p {
  --color: inherit;
  color: red;
  color: var(--color, blue);
}

what would be the color of the <p> element?

<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent bibendum, lorem vel tincidunt imperdiet, nibh elit laoreet felis, a bibendum nisl tortor non orci. Donec pretium fermentum felis, quis aliquet est rutrum ut. Integer quis massa ut lacus viverra pharetra in eu lacus. Aliquam tempus odio adipiscing diam pellentesque rhoncus. Curabitur a bibendum est. Mauris vehicula cursus risus id luctus. Curabitur accumsan venenatis nibh, non egestas ipsum vulputate ac. Vivamus consectetur dolor sit amet enim aliquet eu scelerisque ipsum hendrerit. Donec lobortis suscipit vestibulum. Nullam luctus pellentesque risus in ullamcorper. Nam neque nunc, mattis vitae ornare ut, feugiat a erat. Ut tempus iaculis augue vel pellentesque.</p>

Source: https://codepen.io/shshaw/pen/wvJmOOq

ANSWER

The output color is Green. As if the title wasn’t a giveaway.

Try it out yourself too.

Here is an explanation: https://twitter.com/SelenIT2/status/1400832345016606722

Quoting from that Tweet:

It does inherit it. But then the color gets overridden with the inherited value of the *custom property* named `–color`, which doesn’t know anything about the actual `color` property and gets independently inherited all the way down from `html`

What Password Managers available in Linux

List of Password Managers that are available in Linux?

Aside from BitWarden. I want to know some alternatives you guys are using. Prefer it’s standalone program instead of browser plugin or extensions.

ANSWER

I am using KeePassXC personally for some time. 1Password for work-related stuffs.

The first one is a KeePass variant and open-source. It has a Qt-based application that has been available for Linux for a while. Then, 1Password support in Linux was in beta since last year. Recently it has been moved out of beta.

Others I know off the top of my head,

  • AuthPass
  • Password Safe (for Gnome DE)
  • KeePassX (where KeePassXC was forked)

View what’s inside the Keystore

I have a file with java keystore type that I would like to inspect. Can the contents of the keystore of java be viewed if I don’t have it password? I want to verify an SSL certificate is inside of it. Maybe also check the details are correct, expiration date and so on. What tool can be used to open the keystore?

ANSWER

The normal notion that because the Java Keystore (JKS for short) asks for a password, then I cannot see what is in it is not entirely correct. The password for the JKS does not prevent that. Instead the purpose of the password is to protect the integrity of the JKS. The intention is that without the password, I should not be able to modify the contents, such as adding certificates or deleting some.

With the proper tool I can still read what is inside of a JKS. Normally we just use the keytool. This command line tool usually comes with the Java installation in your system. Try to find it in the installation directory of Java. It resides together with other Java binaries in the ../bin/ directory.

Without password warnings will be displayed, like this one:

*****************  WARNING WARNING WARNING  *****************
* The integrity of the information stored in your keystore  *
* has NOT been verified!  In order to verify its integrity, *
* you must provide your keystore password.                  *
*****************  WARNING WARNING WARNING  *****************

How to print what is inside the JKS:

(1) View all as a list

:~$ keytool -list -keystore /path/to/keystore/file

(2) View all as a list with details

:~$ keytool -list -v -keystore /path/to/keystore/file

(3) View a specific entry only using alias with details (The alias is the text that comes out in command #1 before the date, without the comma)

:~$ keytool -list -alias "the alias text" -v -keystore /path/to/keystore/file

How to fix error: snap “telegram-desktop” has “install-snap” change in progress

I enconter this error message when installing a Snap app Telegram for Desktop from the terminal command line. I followed instructions on how to do this from the Install button of the snapcraft.io website.

First one I select is use the GUI app store. But nothing happens when click install button. Installing progress starts but go back to install. Click again and same thing is happens.

When using the command line that is I got the error of:

error: snap "telegram-desktop" has "install-snap" change in progress

How to fix?

ANSWER

The error is because you are telling Snap to install an app that has already been scheduled for installation. It’s in the queue. The GUI app store is not very informative about this scenario. Hence, it will seem like the installation process failed when in fact that is not the case.

My guess is it is put on schedule for installation because a higher priority install needs to be done first, most likely Snap core updates that have not yet been applied to the system yet.

Either wait for the core updates to finish and wait for Telegram to get installed after, or force it to update right away.

At the command line, do:

:~$ snap changes

It will show something such as:

ID Status Spawn Ready Summary
101 Done yesterday at 20:33 PST yesterday at 20:34 PST Auto-refresh snap "intellij-idea-community"
102 Doing today at 11:36 PST - Install "slack" snap

Abort the scheduled install for the app listed there, in your case “telegram-desktop” snap using the following command:

:~$ sudo snap abort 102

In the example above, I chose to abort install scheduled with ID 102. Choose the ID of the app you are trying to install that you will see on your terminal after the command above.

Then install the snap app manually:

:~$ sudo snap install telegram-desktop

This should force snap to go ahead with the install, but first it may start with its core updates, followed by the telegram-desktop snap app.

Change default app to open torrent magnet link

I installed a Popcorn-time desktop software on my Ubuntu linux to try that out. It appears to use a torrent technology to stream content as it downloads at the same time. Somehow that now gets the default to open magnet links for torrent files. Have not remembered any setting asking me to make the app open by default during installation or at download.

I don’t want this, don’t know how to change to my default torrent software – Transmission BitTorrent.

How to change back?

ANSWER

Add/edit it into the following files. Either or both is fine, but better to have it in for the system-wide list if you have multiple users.

  • System-wide: /usr/share/applications/defaults.list
  • User-specific: ~/.local/share/applications/mimeapps.list

The value of this entry – x-scheme-handler/magnet – needs to be set to the application you prefer.

For example, since you want it to be Transmission it will be similar as shown below:


x-scheme-handler/magnet=transmission-gtk.desktop

Just make sure the .desktop file for the desired application is correct. Again you can check for that file in the same directory where this list is found.

As an alternative, the following terminal commands will also help.

Find out what is the existing default app that will handle such mime-type for your existing user:

:~$ xdg-mime query default x-scheme-handler/magnet

Replace that by using the next command:

:-$ xdg-mime default transmission-gtk.desktop x-scheme-handler/magnet

Lastly, you can check again if the last command was successful by running the first one.

Base64-encoded value is slightly different at the end of string

Why is there slight differences in base64 encoding at the end of the encoded string. It could be one or more of characters that’s different.

Here an example done on base64encode.org using this text – Hey, Diddle Diddle – the output value is:

SGV5LCBEaWRkbGUgRGlkZGxl

But when I do same in base64 command line, I get this instead:

SGV5LCBEaWRkbGUgRGlkZGxlCg==

It is 4 more characters longer. Which one is correct encoding?

ANSWER

The most likely answer is caused by a non-visible character, or characters, being appended at the end of the text you are trying to encode that is causing the slight variation.

Normally this would be caused by the new line, or line feed character, that you won’t see but is there at the end of the text. It is a valid character that the base64 command will include when it encodes the text you give it.

It is not wrong, but most times it is not the intention to have the new line character encoded with it.

Thus, when doing so in command line make sure the new line character is trimmed off. It can be done this way,

:~$ echo -n "hello world" | base64

The result would be: aGVsbG8gd29ybGQ=

Without it, the output is: aGVsbG8gd29ybGQK

Of course, the case of the character/characters being encoded will also matter.

There any free, lightweight app to merge PDF files as one?

As the name of the title in this post says it all. Okay, maybe not all it says because I want it on Linux desktop.

Looking for a tool that can combine different PDF into one big PDF file. I don’t need to modify the content of the PDFs. All important is merging them together as a group.

Sorting it probably comes as second important feature. But I can get on without that as long as it stays in sequence however I added each PDF file.

Lastly simple. No over the top effects. Prefer GUI app. Open to command line.

ANSWER

For that purpose, I have personally used PDF-Shuffler, It is a GUI desktop application on Linux. I used it back then on Ubuntu, but it should be available in all other major distros. Google for it. I know it is included in the official package management repositories of Ubuntu.

PDF-Shuffler can collate, sort (through drag and drop) and rotate the PDF files individually. As an added bonus, it can crop PDFs too.

It is a straightforward app. Stable for all those times I’ve used. But my usage is fairly moderate only.

I also suggest using pdftk for command line if you fancy that kind of stuff. You can combine PDFs into one as simple as:

:~$ pdftk file-1.pdf file-2.df file-3.pdf output my-merged.pdf

This tool can do other stuff. You can read its manual for more information. Google about pdftk too for more examples.

Support for Ubuntu Unity Desktop after 16.04 LTS

Can still use the Unity Desktop after Ubuntu 16.04 Xenial Xerus? Is it still supported?

I like the Unity desktop way of things. Been using it many years now. Read about and tried the new Ubuntu that with Gnome Shell, but I don’t like it much at all. It look clunky with many of missing things from it.

Come April 2021 Ubuntu 16.04 will EOL. Starting to find alternatives, but if Unity is still out there, I’d pick it over the others.

ANSWER

In one word, Yes.

Still can run on both LTS versions of 18.04 and 20.04. Go ahead and install it with:

sudo apt install ubuntu-unity-desktop

Choose Lightdm display manager when asked during install. Best to restart your computer afterwards. Then enjoy.

Consider that many people have said some weird looks of Unity when installed on said LTS versions appear. I forget, but I think its the window decorations and such. This is supposedly caused by the newer Gnome versions, and unpatched by Ubuntu. Unlike before.

You may also like to try out an alternative in the Ubuntu Unity Desktop spinoff. Can be found at this website – https://ubuntuunity.org/

It is not official Ubuntu flavor, but being maintained by some other 3rd party group. The experience is different from just installing 20.04 and then install Unity DE afterwards. Try it out if it suits you.

How to convert For loop using Stream in Java

Creating a Map of Applicant object, where I filter out on the applicant’s age. I only need the first name and last name of the applicant. Using the application ID as the key. The ID is generated integer and unique. Also, testing for null, don’t want that in there. I am using a traditional for loop where I am most comfortable at. But I want to use the Java 8 Stream instead. How is it done?

My code for this is below:

        Applicant a1 = new Applicant();
        a1.setId(1001);
        a1.setFirstName("Joseph");
        a1.setLastName("Dey");
        a1.setAge(25);

        Applicant a2 = new Applicant();
        a2.setId(2001);
        a2.setFirstName("Maxine");
        a2.setLastName("Summers");
        a2.setAge(21);

        Applicant a3 = new Applicant();
        a3.setId(3001);
        a3.setFirstName("Jimmy");
        a3.setLastName("Cox");
        a3.setAge(17);

        Applicant a4 = null;

        List<Applicant> list = new ArrayList<>();
        list.add(a1);
        list.add(a2);
        list.add(a3);
        list.add(a4);

        Map<Integer, String> map = new HashMap<>();
        for (Applicant a : list) {
            if (a != null && a.getAge() > 18) {
                map.put(a.getId(), a.getFirstName() + " " + a.getLastName());
            }
        }

ANSWER

By Statement Lambda in Collectors.toMap – right-hand side is a block. This can become longer to write but sometimes when you have to do more transformations, then it can’t be avoided.

1       Map<Integer, String> map = list.stream()
2                .filter(applicant -> applicant != null)
3                .filter(applicant -> applicant.getAge() >= 18)
4                .collect(Collectors.toMap(applicant -> applicant.getId(), applicant -> {
5                    return applicant.getFirstName() + " " + applicant.getLastName();
6                }));

By Expression Lambda in Collectors.toMap – right-hand side is an expression.

1       Map<Integer, String> map = list.stream()
2                .filter(applicant -> applicant != null)
3                .filter(applicant -> applicant.getAge() >= 18)
4                .collect(Collectors.toMap(applicant -> applicant.getId(), applicant -> applicant.getFirstName() + " " + applicant.getLastName()));

In both cases above, line #2 the Lambda can be replaced with method reference too. It will look like:

.filter(Objects::nonNull)

And on line #4, the same can be done for the Lamba replacing it with a method reference. It will look like:

.collect(Collectors.toMap(Applicant::getId,  // rest of code ommitted

Avro – Unions

As a boolean:

{
	"fieldOne": "hello world",
	"fieldTwo": true,
	"foobar": {
		"boolean": false
	}
}

If value is null:

{
	"fieldOne": "hello world",
	"fieldTwo": true,
	"foobar": null
}

The above is what a field will look like as output where in Avro that field is defined as one of the Complex Types – Unions. Example below, it declares a schema which may be one of null or boolean.

{
  "type": [
    "null", 
    "boolean"
  ]
}

Convert a Map to POJO in Java

How do I convert a Map object to my other plain old Java object (POJO) without going into loops and having to write a class using Java reflection, or some other?

ANSWER

Well, yes, reflection is one but you didn’t want to do that yourself. For some good reason, I bet. It’s a good exercise if you have all the time in the world. But when faced with deadlines and having to write Unit tests for a whole class you wrote, there must be an easier way.

There is more than one way, but what I normally use is the Jackson ObjectMapper. Yes, the same one from the com.fasterxml.jackson library.

Anyway, with ObjectMapper it is pretty straightforward to do so. If I have a Person class like this:

    public class Person {
        private String firstName;
        private String lastName;
    }

My Map object will look like this:

        Map<String, Object> map = new HashMap<>();
        map.put("firstName", "Johnny");
        map.put("lastName", "Foo");

Then with ObjectMapper one can simply do this:

        ObjectMapper mapper = new ObjectMapper();
        Person person = mapper.convertValue(map, Person.class);

Alternatively, the keys in the Map may not align with the fields in the Person class. Well, I usually encounter this when working with JSON objects with lots of crazy looking field names. Something like this – NZT_Mor_First_Name__c – which I clearly don’t want my class field name to be like.

Well, we can use @JsonProperty annotation which is part of Jackson by the way and assign that our class field. The Person class will now look like:

    public class Person {

        @JsonProperty("NZT_Mor_First_Name__c")
        private String firstName;

        @JsonProperty("NZT_Mor_Last_Name__c")
        private String lastName;
    }

Again the Map will hold these values:

        Map<String, Object> map = new HashMap<>();
        map.put("NZT_Mor_First_Name__c", "Jose");
        map.put("NZT_Mor_Last_Name__c", "Yamut");

Now it will map out those weird looking key names to its corresponding class fields.

One thing to note is you might need to set ObjectMapper features such as ignoring unknown properties and make it case insensitive. Allow it a bit more room to wiggle, wiggle.

        ObjectMapper mapper = new ObjectMapper()
                .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
                .enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_VALUES);

Should I quote Strings in YAML?

Should I or should I not? Is it required? Will it work even without quotes – single or double?

ANSWER

I’ve asked myself these questions several times. Often I end up double-quoting long strings, but not for one word ones or shorter strings. Which makes it rather inconsistent. Especially if that string contains characters like a forward slash, a colon or semi-colon. Like when you have a URL as a value. I suppose it’s out of habit.

Thing is, it is not required. Strings can be quoted or not. There is no difference. It will still work with or without it. Even with spaces in that string. YAML allows it. Below are 2 examples:

phrase: 'The quick brown fox jumps over the lazy dog.'
poem: "Hey, diddle, diddle. The cat and the fiddle. The cow jumped over the moon."

The key part of the key-value pair can also be quoted too. The YAML won’t error out. Again, it’s allowed. So this is valid:

'foo':
  "bar": foobar

Single quote or double quotes don’t matter. It can be mixed. Above examples are both acceptable.

However, not quoting is not true in all cases. There are certain instances when it is required such as when there is a colon in the key. In this case, the key needs to be quoted.

'key:': value

What about quotes in the value itself?

CORRECT - phrase1: 'The quick ''brown'' fox jumped over the lazy dog.'
WRONG- phrase2: "The quick ""brown"" fox jumped over the lazy dog."
CORRECT - phrase3: "The quick \"brown\" fox jumped over the lazy dog."
WRONG - phrase4: "The quick '"brown"' fox jumped over the lazy dog."
CORRECT - phrase6: The quick 'brown' fox jumped over the lazy dog.
CORRECT - phrase7: The quick "brown" fox jumped over the lazy dog.

Finally, what does YAML mean?

It is short for – YAML Ain’t Markup Language.

What’s my Windows version

You’ll probably get asked this once or twice. Especially when your Windows computer is not working right, and you are running all over the Internet trying to look for answers. Perhaps would-be good Samaritans might ask this off you as well.

And you reply, “Windows 10”. But rightfully so.

After all, isn’t that the Windows that is installed on your machine right now. Well, yes. Then again, no. No not in the sense that you are wrong. But sometimes the answer to the question of what Windows version is installed on your PC might be something else. Sometimes support may ask you this, and likely they will tell you how to give them the answer they are looking for. If you don’t already know this, then this can save time and misunderstanding. Below are the steps on how to get that information.

What version is my Windows?

  • Go to the Start Menu. Click it. Press the Windows key
  • Type “Run”. The shortcut key is Windows key + R.
  • Type “winver” in the field labeled with Open. You may also type winver in the search box on your taskbar if you have that one.
  • Click OK or press enter
  • Small dialog Windows will pop out title – About Windows.

The information will be found on this pop up window. On the first few lines you should see something like:

Microsoft Windows
Version 2004 (OS Build 19041.630)

Note: Don’t include quotes when typing in those words in the steps.

Is there a Clipboard for Windows 10?

What are the freely available Clipboard programs, if any, for Windows 10? Are there such? I don’t want ads in it and I prefer it simple as possible. No crazy or complex features. I’m only after a simple copy-paste of the short history of what I’ve copied on my desktop. I find this useful for my productivity. I somehow always ending up in open a Notepad and copying the items in there. It works but a clipboard would be better in my opinion.

ANSWER

Windows 10 already comes with a built-in Clipboard Manager. This was from an update some time ago. However it is not enabled by default, buried somewhere in the Settings and you will have to activate it. This feature is not very well known. But it is there and it works as expected.

To activate:

Open Settings via any of the following ways:

  • You can either search for it if you have that search bar on your Windows taskbar.
  • Start typing “Settings” when you have the Windows Start Menu opened.
  • Open the Start Menu then, then click on the Gear icon on the left hand side of the menu.
  • Windows + i shortcut key combo.

Once you are in Settings, go to System. That should be the first icon entry at the top.

You will be taken to another page where there are items at the left hand side. Scroll down and find Clipboard.

Under Clipboard history, toggle the button to On.

To get to your clipboard history, simply press Windows + V shortcut key combo. It will appear as a floating box over your last active application. Otherwise, it will show up on the right side of the desktop on top of the system tray.

The clipboard can contain a max of 25 entries. It is a FIFO (first in, first out) stack so the oldest entry will go out first once that entry limit is hit.

It supports plain text, HTML and images up to 4MB size.

Your clipboard history can be synced across your Windows devices. Be warned that if you enable this it means you are allowing Windows to save the history on Microsoft servers. Make sure you don’t have sensitive information in there when the Sync functionality is enabled.