GitHub and Bitbucket provide webhooks support to notify external services when certain events happen with a repository. The most commonly used webhook event is push.

The following code is a PHP implementation of GitHub webhook that will update a repository clone and execute required deployment code when a new commit was pushed.

After adding this file to your server, you need to make the following changes before adding the webhook to GitHub:

Sett SECRET_TOKEN to a randomly generated token. You can use this command to generate a truly random secure token on Linux:

head /dev/urandom | tr -dc A-Za-z0-9 | head -c 40

Change $commands list to matches your need for every repository. An example of updating both a static website repository and a Django based application repository is provided on the code above as a reference.

Add write access to the process running PHP (FastCGI, mod_php, …) which is mostly either running within the group www-data or www depending on the Linux distribution running on your server.

If your repository is private, generate an ssh key and add the pubkey as a read-only deployment key to your repository settings. This key should be generated using the same user as the PHP process.

Finally, add a webhook to your repository settings. Make sure to set the content type to application/json and the secret to the secret token you have already generated.

Recently, I needed to set up a new Windows system for use in an Internship project. Like the old setup which was described in an older post, I needed to have access to the same Windows from inside Qemu and from dual-boot for performance reasons. But instead of requiring to install Windows two times (once directly on PC as host and the other inside Qemu) which caused some issues including slow filesystem operations when booting as the host system, I did an update to setup instructions this time.

For the virtual machine, we will use Qemu/KVM with Ovmf EFI bios.

First, Install Windows directly on your PC then reboot back to Linux. Check that loop and linear modules are loaded:

sudo modprobe loop
sudo modprobe linear

Now, we need to create a virtual RAID disk for Qemu that will hold our physical Windows partition. As we will use GPT partitions table schema, we will allocate few megabytes efi1 for GPT metadata (34 Sectors) and for EFI partition before Windows partition and one megabyte efi2 after Windows partition for GPT secondary metadata (even we need just 34 Sectors, we will use one megabyte for best RAID performance)

Your final layout will have 2 partitions; Windows partition /dev/md0p2 and EFI partition /dev/md0p1. The EFI partition needs to be formatted.

sudo mkfs.msdos -F 32 -n EFI /dev/md0p1

Now let add Windows boot entry to the virtual RAID disk.

Boot to Windows live DVD from inside Qemu virtual machine with /dev/md0 as disk after changing /dev/md0 owner to the current user and installing Ovmf EFI bios, which in my case, it is available at /usr/share/ovmf/ovmf_x64.bin.

After each Linux system reboot, you need to create the loopback devices, merge the partitions into the RAID disk and change the owner of the device before launching the virtual machine. You can find the script I use as a reference.

Recently, I wanted to add a feedback form to my résumé page to help my friends review it. I was using GitHub pages to host my static website and I didn’t want to host the server-side of the feedback on a different server. So I was looking for a simple solution that works well with my static website. Most of the available ones were either paid or have too many unneeded features.

At the end, I decided to use my Slack team to receive feedbacks. It does not require any third-party library or any server-side code. And it’s simple to implement:

Create a Slack team if you don’t have one.

Add an Incoming Webhook URL to a channel on your team. It’s a simple URL that you can send feedback to.

letform=document.getElementById("feedback");form.addEventListener("submit",function(e){e.preventDefault();fetch(YOUR_WEBHOOK_URL,{method:"POST",// You should use POST methodbody:JSON.stringify({text:form.text.value,// the feedback messageparse:"none",// tell Slack it's not a formated text});});});

Improvements:

You can add more entries to the send JSON. Check Slack documentation for more details. The most useful ones are username and icon_emoji.

You can set a different username and a different icon_emoji entry for every page. For example, you send this JSON from your résumé page:

Freelancer & Money:

CV:

Update: A new version of the article with better solution is available here.

Even Linux is my main system, I frequently need to use Windows for school homework when Mono does not support desired features. Running Windows inside a virtual machine may has limits especially when running Visual Studio on the guest machine. The best solution was to set up a single windows system accessible from both the virtual machine and from the physical dual boot.

For the virtual machine, we will use Qemu/KVM with Virtio devices and a disk partition for Windows.

First, you need to install Windows on your PC to get the boot entry with right configurations (I couldn’t find a workaround BCD boot entry issue other than this one). Then reboot to your Linux system to reinstall Windows on the same partition but using the virtual machine this time.

Before we start, check that loop and linear modules are loaded:

sudo modprobe loop
sudo modprobe linear

Because the virtual machine needs a whole disk with both the Windows partition and the EFI partition, We need to create a virtual RAID. Let’s create a small file to hold the EFI partition:

dd if=/dev/zero of=efi count=200000

Now you have efi file of 100 MB (200000 * 512 Bytes). Next, we create a loopback device from the file:

sudo losetup -f efi

It will assign the first available loopback device to the file. We will assume that the assigned device is /dev/loop0. To check the assigned device:

losetup -a

Next, we will merge the loopback device and the real Windows partition into a single linear RAID disk image (We will assume that the windows partition is /dev/sda2):

Time to create the partitions table of the new RAID disk with reusing the same physical Windows partition. For this step, we will use parted utility. You can use other tools on your own. We need to get the size of real Windows partition on sectors.

Your final layout will have 2 partitions; Windows partition /dev/md0p1 and EFI partition /dev/md0p2. You may get few warning messages when creating partitions, ignore them. The new partitions need to be formatted.

Now, you are ready to launch the virtual machine and reinstall Windows. Change /dev/md0 owner to the same user Qemu is running as and install ovmf EFI bios for Qemu, in my case, it will be available at /usr/share/ovmf/ovmf_x64.bin.

Adapt Qemu script to your use case. You may need to download and install Virtio drivers on your guest machine. After each reboot, you need to create the loopback device, merge the two partitions into the RAID disk and change the owner of the device.