Skip to main content

Posts

Showing posts from September, 2020

JavaScript and CSS changes don't show up in my web page

 This could be a common issue you may face if you just started some web development. Sometimes you may feel that a change you made in your CSS or Javascript, never work in your browser. Practically you may waste more time troubleshooting your CSS or Javascript issues without actually understanding why it doesn't show up when you run it in the web browser. Mostly this happens when you have externalized Javascript or CSS with something like below. <link rel="stylesheet" href="mystyles.css" /> <script src="myjavascript.js"></script> The issue with this would be caching . Web browsers tend to cache any styles or javascript files in the clientside so the browser can save up bandwidth without downloading the same set of Javascript and CSS files every time you open the website. You can see this behavior if you open the developer tools' network section in the Chrome browser. Browser caching Yet, when you try to make some changes, it would

Fix XAMPP or LAMPP Error establishing a database connection for localhost

Issue: Cannot connect to the localhost DB from the local apache server running PHP. I've experienced this issue with a couple of machines and with LAMPP stack and XAMPP on both Linux and Ubuntu.  This is assuming you have correctly provided the DB username, password, and the database to the application and still getting this error when connecting to the DB. No matter what application you are trying to run Moodle, WordPress, or a PHP connection script you wrote, it doesn't connect if you give the localhost or 127.0.0.1 as the DB host. PHP DB connection error WordPress DB Connection error Solution: Make sure you have proper privileges given to the DB user in MySQL or MariaDB. Note that I'm trying to set up WordPress and my DB name is wordpress1. To check this, you have to select your DB in the PhpMyAdmin and navigate to the Privileges tab. Privileges  Once you are there, check the users. DB Users If you have already created a user account for the DB, make sure that you have a

Apply XOR operator for integers

I am writing this post to answer a question from a student who studies IT at school.  They had this MCQ question where this Python code of XORing two integers several times and finding the output.  Question a = 20 b = 30 a = a ^ b b = a ^ b a = a ^ b The question is to find the output results of a and b. If I type this code in the Python interpreter, I get the below outputs. XOR of two numbers - Hard way First I'll explain how to do this properly for the sake of completion. If you know this already, you can just skip this and follow the easy answer. First of all, it was not a computer-based exam, you have to think this through in your mind using pen and paper.  Second of all, how on earth do you apply XOR into integers? It's been a while I learned boolean algebra and I'm pretty sure boolean means true or false.  Then it kicked me, boolean also means 1s and 0s, where you can represent integers using 1s and 0s or binary and then apply the XOR. In fact, that's how actually