Moez Bouhlel @lejenome

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.

Show Comments

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)

dd if=/dev/zero of=efi1 bs=1M count=100
dd if=/dev/zero of=efi2 bs=1M count=1

Now that we have efi1 file of 100 MB (100 * 1M) and efi2 of 1 MB. Next, we create loopback devices from both files:

sudo losetup -f efi1
sudo losetup -f efi2

We will assume that the assigned devices are /dev/loop0 and /dev/loop1 for efi1 and efi2 respectively. To check the assigned devices, type:

losetup -a

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

sudo mdadm --build --verbose /dev/md0 --chunk=512 --level=linear --raid-devices=3 /dev/loop0 /dev/sda2 /dev/loop1

Time to create the partitions table of the new RAID disk reusing the same physical Windows partition. For this step, we will use parted utility. You can use another tool of your choice.

Partition your virtual RAID disk:

sudo parted /dev/md0
(parted) unit s
(parted) mktable gpt
(parted) mkpart primary fat32 2048 204799    # depends on size of efi1 file
(parted) mkpart primary ntfs 204800 -2049    # depends on size of efi1 and efi2 files
(parted) set 1 boot on
(parted) set 1 esp on
(parted) set 2 msftdata on
(parted) name 1 EFI
(parted) name 2 Windows
(parted) quit

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.

chown $USER:$USER /dev/md0  # We need to change the owner of md0
qemu-system-x86_64 \
    -bios /usr/share/ovmf/ovmf_x64.bin \
    -drive file=/dev/md0,media=disk,format=raw \
    -cpu host -enable-kvm -m 2G \
    -cdrom /path/to/windows.iso

Press Shift+F10 when Windows installer starts to open the terminal. We need to assign a letter to EFI volume (partition).

diskpart
DISKPART> list disk
DISKPART> select disk 0    # Select the disk
DISKPART> list volume      # Find EFI volume (partition) number
DISKPART> select volume 2  # Select EFI volume
DISKPART> assign letter=B  # Assign B: to EFI volume
DISKPART> exit

Finally, we create BCD boot entry for Windows partition on the same terminal.

bcdboot C:\Windows /s B: /f ALL

Now, you are ready to boot to Windows from inside Qemu.

qemu-system-x86_64 \
    -bios /usr/share/ovmf/ovmf_x64.bin \
    -drive file=/dev/md0,media=disk,format=raw \
    -cpu host -enable-kvm -m 2G

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.

Credit to Arch Linux Wiki. Enjoy!

Show Comments

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:

  1. Create a Slack team if you don’t have one.
  2. Add an Incoming Webhook URL to a channel on your team. It’s a simple URL that you can send feedback to.
  3. Finally, add your client-side implementation. This is a simple one:
<form id="feedback">
    <textarea name="text" required></textarea>
    <input type="submit" value="send feedback"></input>
</form>
let form = document.getElementById("feedback");
form.addEventListener("submit", function(e) {
    e.preventDefault();
    fetch(YOUR_WEBHOOK_URL, {
        method: "POST", // You should use POST method
        body: JSON.stringify({
            text: form.text.value, // the feedback message
            parse: "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:

{
    "text"       : "THE FEEDBACK MESSAGE",
    "parse"      : "none",
    "username"   : "resume",
    "icon_emoji" : ":briefcase:"
}
Show Comments

This is a list of useful websites and tools to check for Computer Science students.

Challenges:

Algorithms and Programming

System development and administration

Other

  • DevPost : Online and in-person challenges with prizes to win.

Tutorials:

E-learning:

Usefull tools:

  • GitHub : #1 Online project hosting service.
  • Could9 : Full-featured development environment, in the cloud.
  • Zeal : offline documentation for 195+ programming languages and APIs.
  • DevDocs : Online APIs documentation.

Freelancer & Money:

CV:

Show Comments

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):

sudo mdadm --build --verbose /dev/md0 --chunk=16 --level=linear --raid-devices=2 /dev/loop0 /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.

sudo parted /dev/sda unit s print

Partition your virtual RAID disk:

sudo parted /dev/md0
(parted) unit s
(parted) mktable gpt
(parted) mkpart primary ntfs -WINDOW_PARITION_SIZE -1
(parted) mkpart primary fat32 0 -WINDOW_PARITION_SIZE
(parted) quit

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.

sudo mkfs.ntfs -f -L Windows -C /dev/md0p1
sudo mkfs.msdos -F 32 -n EFI /dev/md0p2

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.

qemu-system-x86_64 \
    -enable-kvm \
    -bios /usr/share/ovmf/ovmf_x64.bin \
    -drive file=/dev/md0,media=disk,format=raw \
    -netdev user,id=windowsnic,hostname=windowshost \
    -device virtio-net,netdev=windowsnic \
    -cpu host \
    -m 2G \
    -vga qxl \
    -usbdevice tablet

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.

Credit to Arch Linux Wiki. Enjoy!

Show Comments