Quick explanation of PHP property types

If you have little object-oriented programming experience in PHP you might be a little confused by all the new terms in OOP programming compared to regular functional programming. Before we begin, remember the difference between the terms initialize and instantiate. This is common for all programming languages, not just PHP.

Initialize = assign a variable to a value (all variables/properties must have an initial value when created, even if the compiler does this automatically)
Instantiate = create a new instance of an object (which could be assigned to a variable).

In other words, you could initialize a variable and assign it to a class instantiation. Now, take a look at the example class below with some methods to describe how they work in practice:

<?php
/* CLASS */
class ITDB
{
private function __construct()
{
// Constructor runs when class is instantiated,
// like this: $test = new ITDB();
}

private function hello1()
{
// Only accessible in current class
}
protected function hello2()
{
// Only accessible in current class AND
// child classes which inherits this one
}
public function hello3()
{
// Accessible to all classes
}

// By declaring the method as "static" we can call the
// methods without having to instantiate the class first
static public function hello4()
{
// Accessible without having to instantiate a
// new ITDB() instance first
}
}

/* CLIENT */
ITDB::hello1(); // Will not work because method is private

$sayhi = new ITDB(); // Instantiate class, assign to $sayhi
$sayhi->hello1(); // Will not work, hello1() is still private
$sayhi->hello3() // This is valid, hello3() is a public method

ITDB::hello4(); // Also valid, hello4() is a public static method

Let me know in the comments if you have any questions regarding this 🙂

Custom button in WordPress navigation for opening prompt() and mailto event

This is a neat little trick you could to do spice up the administration experience for your customers if you sell websites using WordPress as CMS.

First of all you’re gonna have to add a new entry/link in your admin sidebar. To do this, you could use a plugin such as Admin Menu Editor or code it manually through your theme functions.php file by following this instruction.

Now for the exciting part. In the URL for your menu/sidebar link, you’re going to use an inline javascript function which fires a prompt() dialog which shows some general contact information, in addition to actually firing a mailto() event if the user clicks OK.

Paste the following code as the target URL for your link. Remember to edit the text/mail/phone etc. \n just means a newline to make it look a little better. After all, this is just an ugly javascript prompt dialog, not some sexy bootstrap dialog. 

javascript:(function(){
    let subj = prompt("Hi! Contact us at\n\nEmail: support@company.com\nTelephone: 123 45 678.\n\nEnter subject below and press OK to send us an email.\n","Issue regarding WordPress");
    if(subj) { window.location.href = "mailto:support@company.com?Subject="+subj+""; }
})();

Once that’s done, refresh your admin panel and it could look something like this:

For more inline javascript bullshittery you can take a look at this browser bookmark which appends stupid emojis all over the website.

List disks with fdisk without showing loopback disks created by snap apps

You might’ve noticed that Snap apps creates a loopback disk used for mounting the image file for the app. This clutters the UI of fdisk, df and other disk related tools.

A typical fdisk -l could show you this:

Since most regular drives starts as /dev/sd* you could simply grep the output:

sudo fdisk -l | grep "Disk /dev/sd"

Or even better, use sudo fdisk -l | grep -v "loop". The -v parameter means grep reverts the keyword so anything containing “loop” will not be shown.

Another example: df -h:

Now: df -h | grep -v loop

Note regarding grep: You only need to add quotation marks around the keyword if it’s a string which contains spaces. Single words don’t need quotes.

You can also pipe it several times through grep, like this:

sudo df -h | grep -v loop | grep -v tmp

Or take a look at this Stackoverflow thread for more grep variants

How to add HTML support in Bootstrap title/tooltip

The solution is really easy. Simply append the tag data-html="true" to the element and you can use HTML code within the title="" tooltip.

Code example:



Preview

You can use a wide array of HTML tags within the title="", such as <marquee>. Yes, that actually works.

<span data-html="true" title="<marquee>Welcome to the 90s</marquee>"> Do not hover me </span>

Runas Error 193: *.msc is not a valid Win32 application

If you’re trying to run compmgmt.msc (Computer Management) or any other MMC snap-in via the runas command, you might’ve seen Error 193: compmgmt.msc is not a valid Win32 application. This is simply due to some complications with the runas command. If you just type compmgmt.msc without runas, it’ll open successfully. The reason is some complications with the runas command.

Luckily there’s an easy solution. Since compmgmt.msc is not a regular win32 (or a typical exe) application, you have to prepend “mmc” in order to tell Microsoft that you’re trying to run a Microsoft Management Console snap-in.

runas /user:domain\username "mmc compmgmt.msc"

This is also the case for every other *.msc snap-in, such as lusrmgr.msc.

I’ve mentioned this briefly in an earlier post as well:

Composer failed to install Laravel because of missing zip extension

I was trying to install Laravel by running the command composer global require laravel/installer but it failed because laravel/installer v2.0.x requires ext-zip.

Turns out it wasn’t installed on my system. To fix it, first find out your php version by running php -v. Then use the php version number to install the missing extension like php7.2-zip

sudo apt install php7.2-zip

This will also work for other extensions like php7.2-mbstring and php7.2-dom

Start a simple web server anywhere using python

Python has a builtin web server which is great for development environments and can be started anywhere on your computer with 1 simple command.

Examples below are given for Python2.x and Python 3.x and will start the server on port 80.

Python 3:
python3 -m http.server 80 

Python 2:
python -m SimpleHTTPServer 80 

Simply close the terminal window or press CTRL+C to shut down the server.

Extract OEM key from Windows 8/8.1/10

First of a quick clarification regarding Windows licenses.

  • An OEM Windows license are bundled with prebuilt computers from hardware manufacturers (like Dell and Asus). These keys are only valid for that specific computer. An OEM key can not be used on any other computers, even if you extract the license key.
  • A Retail Windows license works similarly that it will only work on 1 computer, but you can choose which computer to use it on and reassign it to another computer if you’d like to.

To sum it up; an OEM key belongs to the computer while a retail key belongs to you.

Now there are still valid reasons to extract the OEM license key and that’s what we’re going to do today. The OEM key for Windows 8, 8.1 and 10 are now stored in the BIOS/UEFI (using ACPI) and no longer written on physical stickers like it used to.

 

Easiest method is to use the builtin wmic interface by running this command in command prompt:

wmic path softwarelicensingservice get OA3xOriginalProductKey

Alternatively you can start PowerShell and type get-wmiobject and enter SoftwareLicensingService when it prompts for what Class to use.

get_win8key from Christian Korneck

https://github.com/christian-korneck/get_win8key

This application reads the license key directly from the firmware/ACPI. It’s built in Python but has a binary .exe file ready to use on the github repo.

 

ProduKey from Nirsoft

http://www.nirsoft.net/utils/product_cd_key_viewer.html

Nir Sofer gets the job done as usual. This will also list other used license keys, not just the operating system. See example screenshot below, but note that my hardware has been modified and therefore has no OEM key.

 

RW Everything

https://rweverything.com

This is a very powerful tool which you should use with great caution. This application talks directly with your firmware and since it also can WRITE data in addition to READ, you must be very careful so you don’t break anything. If the other steps above did not work, you can give RWEverything a try. See further instructions from this Stackexchange thread: https://superuser.com/a/593795/312773

Missing the new community theme Yaru after upgrading from Ubuntu 18.04 to 18.10

I just upgraded from 18.04 to 18.10 yesterday, but to my dismay, the new fancy theme, Yaru, was nowhere to be found. Looked around in Gnome Tweaks to no avail. Turns out some of the theme packages were not properly installed, more specifically the yaru-theme-gtk package. 

Enter the command apt search yaru-* to see installation status of every package containing “yaru-*”. If they are installed they will state [Installed] inside the square brackets, like so:

If they’re not installed, you can simply fix the issue by running sudo apt install yaru-*. Once complete, log out and back in, and the theme files will be available in Gnome Tweaks

Voila! Remember to also set CursorIcons and Sound theme to Yaru in Gnome Tweaks if desired.

Fix twitchy/wobbling touchpad for Ubuntu based distributions

On two occasions I have experienced that my Dell Latitude laptops has twitchy touchpads. This has happened on both Ubuntu 18.04 and elementaryOS 0.4 some years ago.

The fix, so far, has simply been to reinstall the xserver driver plus some additional software:

sudo apt remove xserver-xorg-input-libinput

sudo apt install xserver-xorg-input-all xserver-xorg-input-evdev xserver-xorg-input-synaptics

Then reboot computer.