?? Answers

  • 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 list = new ArrayList();
            list.add(a1);
            list.add(a2);
            list.add(a3);
            list.add(a4);
    
            Map 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 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 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
    https://www.worldofnubcraft.com/4174/kafka-consumer-error-avro-with-field-type-as-a-union-of-null-and-boolean/

    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 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 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.

  • Re-publish Kafka record not setting partition number?

    Well, I plan to re-publish Kafka records that my app is consuming to another Kafka topic on another host (internal only). This sort of lets other groups consume data from this topic without having to create connections outside of the private network, since the original data source is a 3rd party vendor. They can then also do their own transformations or other business logic on it as if they were consuming from the original source. Delay from source to re-publish should be minimal. Will still be close to real time.

    What I normally do when producing records is not to set a partition by default. Would this be okay when re-publishing records? Will there be conflict with original record partition number to the target topic partition?

    ANSWER

    How many partitions does your target topic have? Do you have freedom to create as many partitions as the source?

    (1) If you can create 1:1 partitions then my suggestion is to retain the original partition number of that record when you publish to the destination topic.

    (2) You can also assign the partition in a round-robin way when you have lesser partitions on your target topic. Save metadata info of that record in the headers, such as original partition assignment and etc. Perhaps that will be useful down the line for your consumers.

    (3) Lastly, you can NOT assign a partition number. Instead, let Kafka do the magic for you. When no partitions are set, Kafka will determine the next partition in a round robin method. You can do this with a null value instead of an int for partition number.

    Bottom line is that it depends on the project requirements, I suppose, or more so on the infrastructure of your destination Kafka.

  • Can’t copy text from webpage?

    Sometimes I come upon a website that I cannot copy text from a HTML web page. Simply cannot click and highlight the lines I try to select for copying. I thought that my browser/mouse was not working. But I go to other sites, I am able to highlight/copy normally. They must’ve done something on that page probably to prevent content from being lifted of the page easily?

    Why is this and how do they do it? Is this a javascript in the page that prevents me from copying?

    ANSWER

    Could be a script on the webpage. I’m certain that can be done or already been done through Javascript before.

    I know that the same effect can be achieved via CSS alone. It is easier, cleaner and does not add to another Javascript messing up or slowing down a site. I prefer this method over the other.

    Below are the CSS lines that does what you want. Different ones for different browsers. It is vendor specific for some, but does the same exact thing.

       user-select: none; /* Supported by Chrome, Firefox & Opera */
      -moz-user-select: none; /* Firefox (older) */
      -ms-user-select: none; /* Edge */
      -khtml-user-select: none; /* Konqueror */
      -webkit-touch-callout: none; /* Safari for iOS */
      -webkit-user-select: none; /* Safari for Mac */
    

    Try it out. You can make it for entire page/site.

    * {
         /* CSS lines go here */
    }

    Or you can make it so only targeted content will have it using Class or ID selectors.

    #text-no-select {
         /* ID selector -  CSS lines go here */
    }
    
    .text-no-select {
         /* Class selector -  CSS lines go here */
    }

    Be aware this does not totally prevent anyone from copying content on a website. There are many other ways to go around this or even with a Javascript impementation. It is a minor roadblock.

  • How to make IntelliJ check and create SerialVersionUID

    When the class implements Serializable I want the serialVersionUID field to be auto-created by IntelliJ IDE. This feature comes in automatically in Eclipse. But the former does not.

    How do I make IntelliJ create the field or warn me that it is not defined in the class yet?

    ANSWER

    It is not turned on by default in IntelliJ. Can be easily done by going to the following:

    File > Settings > Editor > Inspections > Java > Serialization Issues

    Then find and select – Serializable class without ‘serialVersionUID’ – by checking on the box to the right of it.

    Similarly, you can search for it once in File > Settings. Keyword for search can be – ‘serialVersionUID’ – without the quotes.

    The path or location of this feature on IntelliJ may vary. It should be the same on Linux and Windows for versions 2019 and 2020.

    This will only throw a warning. It does not magically create the field in all those classes that implements Serializable straight away. But then IntelliJ will help you create it, like any other decent IDE out there. Go to the class name declaration, you may find that it is subtly highlighted in yellow to hint that there is a user action that can be done. Hover then click on the option – Add ‘serialVersionUID’ field – and you will get the desired result like this one:

    private static final long serialVersionUID = 6265605531073886420L;
  • Database tables map One To Many without foreign key in @JoinColumn

    Possible to not have foreign key relationship in child table to its parent in the database, while in JPA it will still be able to map out fine? How will this be done?

    Can I still use @JoinColumn to define the field for reference back to the parent table?

    This is a one-to-many relationship. One parent record, many child records.

    I only care about writes to the database tables right now.

    ANSWER

    Yes, no FKs defined in the database is fine. JPA will still be able to map out there relationships as defined in your entity classes.

    In fact, enabling – spring.jpa.generate-ddl – in your application properties file will create the necessary Foreign Key and/or Unique Key constraints in the database. This is vendor dependent however.

    For a One To Many relationship, it is straightforward to do. Example below definition below:

        @OneToMany(cascade = CascadeType.ALL)
        @JoinColumn(name = "recommendation_id")
        private List commentList;

    This will map out the entity object values to the Comment table, assuming that is the name of the target table. Each one will be persisted to the child table along with the ID of the parent Recomendation under the recommendation_id column.

  • How to ignore unknown fields when parsing JSON using Jackson

    In Java, there is Jackson 2 library that is very popularly used when reading JSON objects and mapping those values out to a POJO.

    Happy path, as long a I have all the fields from the JSON defined in the POJO then okay. In a perfect world it will work 100%.

    But there is no perfect world. The JSON object in other scenarios can contain unknown fields. These are not in my POJO. Application fails from reading that JSON to POJO.

    Getting this error:

    Exception in thread "main" com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "status" (class com.example.dto.Evaluation), not marked as ignorable (6 known properties: "Book",

    ANSWER

    Use this Jackson annotation at a class level. This has to be configured per class. That should do it. Will ignore any unknown properties silently including nested objects.

    @JsonIgnoreProperties(ignoreUnknown = true)

    When you are using Jackson ObjectMapper directly, that can be configured to ignore unknown properties globally as well.

    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

  • How Do I Decode An OpenShift Secret In A Mounted Volume?

    Mounting an OpenShift Secret to its own volume is straightforward. There are plenty of examples on how to do it. The Web is littered with examples. Next, the most common thing any manual, guide or tutorial would say is to encode the secret in Base64.

    For example I have a SSL certificate stored in a Java KeyStore file format or JKS. The recommended way is to store it in a Secret instead of ConfigMap since it is sensitive information. Of course, that goes without saying the JKS file is password-protected.

    Second, it must be as a Base64 string before I save it as OpenShift Secret.

    How do I get the Base64 string to be decoded in the mounted volume? This one does not seem to get many answers.

    Do I need to include shell commands to decode it and write it to a folder?

    Which folder should I write it to as best practice?

    ANSWER

    #1 The encoded JKS Secret as an environment variable

    This is an option but I’m not a fan of it. The JKS file when encoded can become very long, especially when the file size is large. I don’t think environment variables were meant to be used like this – hold very long text values. That said, this is an easier implementation.

    Map out the secret as an env var in OpenShift or Kubernetes. Then you can use that env var to echo the value and write it out to a file.

    echo -n $SECRET_JKS_VAR | base64 --decode > /file/path/to/decoded-secret.jks

    #2 Mount for read, mount for write

    You have the secret mounted to a file path. That is for reading. Now you need to decode, which means writing to a file so your application can read it back unencoded.

    First, define a mount point as and empty directory. It must be writable. Then make it memory only.

    Next, read the JKS file from its mount point, write it out to the empty dir mount point.

    cat /mount/file/path/for-reading/encoded-secret.jks | base 64 --decode > /mount/file/path/for-writing/decoded-secret.jks

    I like this approach better. It makes more sense rather than mapping a very long base64-encoded text value as an environment variable. The caveat is here is slightly more configurations to be made. Also if I’m not mistaken the in-memory volume count against your app memory quota. Should be negligible unless you write thousands of files into it.

    #3 Lastly, write where you can

    Underneath that container is a file system. Where you have permission to write, then do so there. If it’s Linux, then this decision is pretty much arbitrary IMHO. Put it in /tmp or /home or /mnt. Security wise, others might have access to your app’s pod, that means they can get to the Secret as well. But that is another topic.

  • WorPress Editor Won’t Load Content Anymore

    Got this weird WordPress behaviour recently. While most pages load successfully, editing something – like a post or a page – will draw a blank browser tab. Zero content whatsoever. It has the same result for both Firefox and Chrome. Not tried on other browsers.

    ANSWER

    Uncaught EvalError: Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "default-src 'unsafe-inline'

    This was the error that I got when I went into the page, opened developer tools, then reloaded the page.

    Caused by additional custom Header policy on the web server of the website. Looks something like this:

    Header set Content-Security-Policy "default-src 'unsafe-inline' 

    Add ‘unsafe-eval’ to go around it. Use of eval() is usually considered bad practice and not secure hence it’s getting blocked until it is allowed by adding it into the policy. Now the Header will look like this after modifying it. Don’t forget to restart the web server.

    Header set Content-Security-Policy "default-src 'unsafe-inline' 

    More detailed explanations can be had here: https://scotthelme.co.uk/content-security-policy-an-introduction/

  • How to Fix Gradle Wrapper Permission Denied Error

    I am getting this “gradlew permission denied” error after pushing my code to my GitLab repository. The build is not able to continue because the gradle wrapper is not able to run.

    What is causing this and how to fix it?

    ANSWER

    From a local terminal/command line, use the Git command that follows to fix this issue:

    git update-index --chmod=+x gradlew
    

    Continue to commit the modifications to the gradlew file.

    Push the changes to your Git repository.

    You can read more at this page: https://www.joseyamut.xyz/2020/08/15/fix-gradlew-permission-denied-on-openshift-deploy/

  • How to show Snap app icon properly on Ubuntu Unity desktop

    Had this issue where after I logged into my Ubuntu desktop all Snap apps icons do not show properly. Instead I see a plain icon in place of what the app icon should be. Have you the same experience?

    This might have been fixed in later Ubuntu LTS releases, I really don’t know. But I am still on 16.04 Xenial Xerus until its EOL. Also, the reason is that I love the Unity Desktop. The Gnome Shell replacement just doesn’t cut it for me.

    I have been looking for a solution on this issue for some time. The 2 main things people point out are:

    – Add /snap/bin to the /etc/environment file, and;

    – Something to do with the profile.

    Neither of those solutions worked for me. But it did work for others according to what I have read so far.

    ANSWER

    To fix this icon issue, create a symlink of the Snap’s .desktop shortcut file to your user’s .local/share/applications directory.

    It is as simple as that. Once done the problem will go away, and you will be left with a nice-looking icon that came with the Snap installation. This won’t go away on following restarts.

    For more details on how to do this fix exactly, refer to this article – https://www.joseyamut.xyz/2020/08/13/getting-that-ubuntu-snap-icon-right-on-unity-shell/

  • How Do I See the List of Users Allowed on a MS SQL Server Database

    I want to know the users that are allowed access to a MS SQL Server database. I only want a specific database. Is there a user list hidden somewhere?

    What are the ways to go about doing this? Is there an app or through a SQL query?

    ANSWER

    Use Microsoft SQL Server Management Studio. That is the fastest way to do it. Find the database from the explorer menu on the left-hand side. Expand the folder icon. Go to the Security folder, then click on Users next. That’s it!

    If you’re using a different SQL client and you can’t see Security > Users from the GUI. Then your other option is through a SQL query.

    This is the query below. More details at this page here: https://www.joseyamut.xyz/2020/08/06/get-user-list-in-a-microsoft-sql-server-database/.

    USE ;
    SELECT name AS username,
           type_desc AS type,
           authentication_type_desc AS auth_type
    FROM sys.database_principals
    ORDER BY type;

    Happy user hunting! =)

  • Kafka Consumer Error – AVRO with Field Type as a Union of null and boolean

    Recently I ran into some issues in consuming Kafka AVRO messages. Everything went well up to the de-serialization of the record from the Kafka topic. It all just went crazy once it was being serialized into JSON. That’s pretty much where the proverbial buck stopped.

    I was scratching my head on why this odd behavior was happening. Looking at the message published on the Kafka topic, it was following the defined AVRO schema as expected. There were no deviations.

    Somehow when being converted to JSON it started throwing an exception. It was always at the same spot every time. It would not go any further.

    Debugging the flow of the program, it showed me that what should have been this:

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

    Became something like this:

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

    And that is why the program was throwing an error!

    ANSWER

    The solution I did was to remove null as a field type. Set the field to be strictly boolean. What I wanted was to initially have the state of this field as null. Then further down the line it can be set to either true or false.

    After the AVRO schema was updated, the error went away.

    This was reported to Apache AVRO Jira. More details about this problem here – https://www.joseyamut.xyz/2020/07/29/de-serializing-kafka-messages-with-union-defined-field/

  • Link in Java returns HTTP instead of HTTPS

    Many times your application can be running behind a reverse proxy or a load balancer, and often in between the protocol is just plain old HTTP. This is a very common setup and one that has been around for several years.

    When this happens, when generating URLs through the Java Link class on Spring boot, you might get the wrong scheme or protocol. What should have been HTTPS becomes HTTP. When you’re building APIs that follows HATEOAS/HAL, this becomes an issue. With just a single letter ‘S’ your URLs become invalid.

    First off, this should be already handled properly by the underlying framework but if the proxy in front of your app was misconfigured this leads to the problem happening and it is then difficult, maybe impossible, to tell whether the client connecting to the app used HTTP or HTTPS.

    Luckily, you can force it somehow to use the proper protocol. This is a solution nonetheless, which works, but I would say having the reverse proxy or load balancer configured correctly is the proper way to do it.

    ANSWER

    The band-aid solution is to manipulate your Spring Boot app depending on the environment.

    For example, if I’m just developing/using it locally HTTP is fine. With profiles setup as it ought to be – dev, test, prod – you can get the correct environment and have your URL use HTTP or HTTPS depending on it. When you deploy it to your server, you know you want it to be using secure HTTP so now you can override the Link to use the right scheme in this case.

    Here is a one way on how to do manipulate the protocol or scheme of a Link.

    Oh, and getting the profile can be done in 2 ways that I know of in Spring Boot.

    First is injecting it via annotation.

    @Value("${spring.profiles.active}")
    private String activeProfile;

    and/or autowiring Environment

    @Autowired
    private Environment environment;
     
    public void getActiveProfiles() {
       for (String profileName : environment.getActiveProfiles()) {
          System.out.println("Active profile: " + profileName);
       }  
    }

  • SSH Time out Error

    I am looking for new ideas on how can I do more better.

    Home laptop (home Laptop can access only Linux VM)
    Linux VM (This machine can access only jump box)
    jump box VM

    I can ssh fine from Linux VM to jump box keys are setup.

    one user is set up in Linux VM called joe and Joe .bash_profile looks like this.

    ssh 10.0.0.1 || ssh 10.0.0.2

    Note: There is two nic on jump box if one is down we can use the other nic for login.

    Let’s say first nic is down and when I do telnet from my home laptop (telnet Linux VM) and provide user name joe it should automatically connect us to 10.0.0.1 but one is down it’s giving message timeout and taking a long time to connect to other nic.

    is there any way when I do telnet and give user name check first ssh connection if down automatically connects to other second one like in 2-3 secs?

    Right now it will give us a message

    Time out
    time out
    time out
    And then it will try to connect the second nic.

    I can more clarify if you guys have any more questions for me.

    Go to Source
    Author: John

    ANSWER

    Resolving hosts can add up to the connection attempt, so specifying an IP address directly can shave off some of those precious milliseconds. If it’s only in a local network with the IP addresses all laid out that should not be the case. At least that’s what I think.

    Perhaps explicitly setting the ConnectTimeout option to a shorter one. Like so,

    ssh -o ConnectTimeout=10 user@host

    This can help. Adjust the number to a sweet spot that works for your ssh setup as necessary.

  • How to configure Krusader’s extract context menu to use something other than ark?

    I’ve found this context menu in krusader to be very unreliable over the years, it has hardly ever worked for me. Surely it’s possible to configure the context menu to use a custom command, like simply using the zip , ot tar CLI command. I don’t find this in the application settings.

    The VFS plugins work great, how come this context menu has to use ARK?

    Go to Source
    Author: barrymac

    ANSWER

    Being KDE, it is a very highly configurable desktop environment to the point that it can become overwhelming. It gives you practically a myriad options for customizations for just about everything. I know because I had been a KDE fan/user for several years.

    But I think the issue here is on file associations. Krusader, being a KDE application should follow system-wide settings. I don’t see any reason why it should not. As such, it is in my opinion that the file manager by default will use whatever is associated to handle or open a certain file. I’d look for KDE’s file association settings in the Control Panel or some such. Then assign a different application for that file to your liking. That should do the trick.

    As for more customizations like using your own script perhaps? It could be possible still under file associations to assign a different application. Don’t have a KDE desktop installed right now so I can’t check this out. Certainly can’t remember too, nor have gone to the extent of doing something like this to handle archives.

  • Copying a MySQL 5.6 server settings for a new environment?

    I have a MySQL 5.6 Server running on a Windows 8 VM on a steel case server. It’s been having issues (The Windows 8, which is then causing the MySQL to have issues). Therefore I was tasked with putting the MySQL 5.6 Server on a Windows 10 VM for stability reasons. The amount of ram the server is allowed and other settings have been tweaked over time. Is there an way I can export these settings, so when I install MySQL on my Windows 10 VM, I can just tell it to use the same?

    Go to Source
    Author: bjk116

    ANSWER

    This should be as straightforward as copying the configuration file – my.ini is the default – of the old MySQL server to the new one. It is a regular text file so copying it should not be an issue at all.

    If there are other supporting configuration files for the DB server you might have customized, copy those as well.

    Restart the MySQL server as necessary. If there are issues, like for example when using InnoDB engine, deleting the datadir should fix that quickly. Of course, I’m assuming this is on a fresh MySQL install. Don’t do this otherwise. You can migrate the data properly through a mysqldump for example.

  • What firewall should I use?

    What is the most comprehensive free firewall solution available for Windows? Personal machine, not work machine. I see a ton of choices online, but not sure which one to pick.

    Go to Source
    Author: PerpetualLearner

    ANSWER

    For home use I am fine with the built-in and free Windows Firewall (or Windows Defender Firewall) most of the time. It serves its purpose. Does the job. Not overwhelming to use. Customizable enough.

    I would also explore the security options that comes with my home router. Many have it included nowadays, and with a little tweaking, should be able to add an extra layer of protection to one’s home network..

  • Easy way to bypass password on my computer

    I was not able to formule a question so maybe this was already solved, and if that’s the case, sorry.
    But I found a huge vulnerability on my computer. It’s a portable computer with a Win10/Ubuntu 20.04 dual boot.
    When I’m logged in, and that I lock my session, this sends me to the login screen, okay. But then, if I do Ctrl+Alt+F3 to go to the terminal mode, and then do Ctrl+Alt+F7 to leave terminal mode, this simply unlocks my session !
    It doesn’t work at computer start though, the session must be started and locked.
    Note that when I close my computer this doesn’t lock my session even if it’s activated in the settings.
    This is a critical vulnerability but it’s doesn’t work at all on my friend’s computer which is also a Win10/Ubuntu 20 dual boot.
    I don’t know why this happens to me, any idea of solving this ?

    Thanks for you time

    Go to Source
    Author: Double Vé

    ANSWER

    This does not seem to be a normal behavior from what I’ve experienced at all as far as I can remember. I know before I was fond of having my Linux desktop auto-login on startup. I think I also opted to have it login automatically after sleep/suspend. Perhaps the switch to a different TTY/console constitutes as the same behavior. This looks a lot like buggy behavior to me.

    I would go so far as to document on how to replicate it, and report it as a bug. Call the attention of the developers so this can be looked into and fixed if necessary.

  • Need help with .htaccess redirection for WordPress websites

    I am changing the domain of my website.

    But, I am struggling with the domain redirection. I need to implement this wildcard redirection.

    So that I visit.

    https://www.oldomain.com/page1

    It should go to

    https://newdomain.com/page1

    Note: The new domain is without www.

    Can anyone help me how to implement this?

    Go to Source
    Author: Nirmal Kumar

    ANSWER

    A 301 Redirect, or permanent redirect, is recommended when dealing with something similar to this one.

    If you just want to hard redirect anything hitting oldomain.com to newdomain.com then a simple Redirect should do like so:

    	ServerName oldomain.com
            ServerAlias www.oldomain.com
    	Redirect 301 / https://newdomain.com
    

    The above example is also something that you will want to write in a server config like httpd.conf but not in a .htaccess file somewhere on your site directory. It is also clumsy since your old site’s pages – e.g https://www.domain.com/some/page/123 – will redirect only to https://newdomain.com which is the index page of the site.

    So the other option would be Rewrite. It is also in case you don’t have root access to the server, and/or other sites that are not yours are sharing it as well. It would look like the following:

    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^oldomain.com [NC,OR]
    RewriteCond %{HTTP_HOST} ^www.oldomain.com [NC]
    RewriteRule ^(.*)$ http://newdomain.com/$1 [L,R=301,NC]

    The above considers whether the request is written with or without the www subdomain in it. The old links or pages will also get carried over to the new one.

  • Ubuntu 20.04 Does Not Boot

    ANSWER

    Looks like this one just needs to have their GRUB re-written to MBR again. It’s not so hard. But given that I did something like this 8 years ago… The concept should still be the same. Steps of what I did to fix it here.

    I originally had Ubuntu 18.04 installed on my dell xps 13 (2017). A couple days ago, I replaced it with Ubuntu 20.04 due to constant error messages. Until today, I was able to use it without any trouble.
    However, I had to use Windows earlier today, and now when I was trying to boot Ubuntu back, I am unable to do so.

    First error message

    Unexpected return from initial read: Volume Corrupt buffersize 1000 Failed to load image EFIubuntugrubefi: Volume Corrupt start_image() returned Volume Corrupt

    and then windows booted automatically.

    In trying to resolve the issue,

    1. Tried reinstalling Ubuntu 20.04 using LiveUSB, but got the error saying the system doesn’t have EFI System Partition
    2. Consulted the forum https://ubuntu.forumming.com/question/5394/unexpected-return-from-initial-read-volume-corrupt.
      In running Boot Repair, I received an error message, sayin EFI System Partition is needed.
    3. Used GPart to try to tweak disk settings (changing the disk partition that holds Ubuntu File System from ext4 to fat32… I didn’t document this process very well)
    4. Followed a tutorial that used Windows command prompt and diskpart, creating an ESP.
    5. Reran Boot Repair (successfully this time)

    However, now I encountered a GRUB error

    “Minimal BASH like line editing is supported. For the first word, TAB lists possible command completions. anywhere else TAB lists possible device or file completions.”

    I’ve been looking up different solutions, but I am having trouble understanding them, and afraid I am messing my disk more and more.

    Thank you in advance.

    Go to Source
    Author: Amanda Jeong

  • how to get specific character from a log file in linux

    ANSWER

    Assuming that (1) the log file looks as it is AND (2) it is multi-line, then a simple Linux grep command like below should work (even with multiple lines of that line you’re looking for in one log file):

    INPUT | Tested it on dummy logs from sample

    COMMAND | grep -Pn "^Id\s+:\s+(.*)$" *.log

    OUTPUT |

    log101.log:2:Id : UN123P

    log102.log:2:Id : HELLO321

    log103.log:2:Id : STUDE23P

    log104.log:2:Id : Lorem

    log104.log:7:Id : IPsum

    log104.log:12:Id : Dolor

    have a log file , having multiple contents inside the file like and example below is the content of U123.log . I have n number of logs..

    Accepted password for hoover from 10.0.2.2 port 4792 ss
    
    Id : UN123P 
    
    ID_MTCH : UnixProduction
    
    Accepted password for hoover from 10.0.2.2 port 4792 ss
    
    Accepted password for hoover from 10.0.2.2 port 4792 ss
    

    Is there any we can fetch “Id : UN123P” as an output of linux command. We have some 1000’s of logs and from all the logs , trying to fetch the value only starts with ID : and output as “Id : UN123P”

    Pls suggest

    Go to Source
    Author: Arya