Categories
programming

SQL joins

Cross join

Cartesian product:

SELECT *
FROM movies
CROSS JOIN directors;

Full outer join

Like inner join but with all remaining rows from both sides:

SELECT *
FROM movies
FULL OUTER JOIN directors
  ON directors.id = movies.director_id;

Inner join

Only rows where condition is true:

SELECT *
FROM movies
INNER JOIN directors
  ON directors.id = movies.director_id;

Left join

All records from “left” table plus rows from the “right” table that match join condition:

SELECT *
FROM movies
LEFT JOIN directors
  ON directors.id = movies.director_id;

Use WHERE to filter results.

Right join

Reverse left join:

SELECT *
FROM movies
RIGHT JOIN directors
  ON directors.id = movies.director_id;

Source: freeCodeCamp

Categories
games

ScummVM

ScummVM is a virtual machine for running classic DOS games. Originally, ScummVM was intent for playing only SCUMM games. SCUMM stands for Script Creation Utility for Manic Mansion – an LucasArts engine for creating games. Most notable games created in this engine are Manic Mansion, Monkey Island series, Day of the Tentacle, Full Throttle, Sam & Max. Later ScummVM added support for lot of non-SCUMM games by implementing other game engines such ADL, AGI, SCI, ADRIFT, AdvSys, Level9, ZCode etc. This now gives it ability to play over 200 games.

ResidualVM is sister project of ScummVM and is capable of running GrimE (Grim Engine) games: Grim Fandango and Escape from Monkey Island. On a October 10 2020. it is announced merging of ResidualVM into ScummVM.

ScummVM is free open source project but many of games are still under license so you need original datafiles. ScummVM only replaces the original game executables allowing you to play them on new systems.

Categories
games

Sega Mega Drive and Genesis Classics Hub

Sega Mega Drive and Genesis Classics Hub is official Sega emulator for the Sega Mega Drive available on Steam. It puts the player into a 3D environment of a Sega fan’s bedroom in the early nineties. The player can then boot up the in-game CRT TV, choose the game they want to play off a virtual shelf and load up the Mega Drive to start playing. The Sega Mega Drive Classics Hub features local co-op for supported games, optional graphic enhancement filters, the ability to save at any point during gameplay and full controller and keyboard support.

Categories
interwebs security web server

Let’s Encrypt in manual mode

SSL and TLS are cryptographic protocols designed to provide secure conenction between web client and web server. This security is achieved by installing SSL/TLS certificate on a web server. Certificate contains the public key and additional information such as issuer, what the cert is supposed to be used for, and other types of metadata. Certificate is signed by a certificate authority (CA) using CA’s private key. This verifies the authenticity of the certificate. Secure connection between client and server is established over HTTPS protocol.

Let’s Encrypt is a CA. In order to get a certificate for your website’s domain from Let’s Encrypt, you have to demonstrate control over the domain. If you don’t have shell access (SSH access) to your web host, you can use Certbot software on your own computer in so called manual mode. In manual mode, you upload a specific file to your website to prove your control. Certbot will then retrieve a cert that you can upload to your hosting provider. Example:

certbot certonly --manual --preferred-challenges=http --email admin@domain.com --agree-tos -d domain.com

When you run command above, Certbot will ask you to put specific file on your website to prove ownership. After it is verified you will get your private key (privkey.pem) and chain/bundle (fullchain.pem). Chain files contains your certificate. To decode your cert you can type

openssl x509 -in certificate.crt -text -noout

or use tool such Online Decoder.

Now you need to send those files to your website administrator to make HTTPS work. Downside of this method is that it is time-consuming and you will need to repeat it several times per year as your cert expires every 90 days.

Categories
organization productivity programming

Good programming habits

  • volunteer for things you don’t know so you can constantly learn new things
  • ask to pair up because pairing session is a great way to kick off the work on a task; discuss requirements until you understand what is expected, then discuss the solution
  • talk about what you are doing and what you’re not doing
  • write a blog because writing with the intention to teach others (even if it’s just future you) is a great way of learning and growing
  • have a notebook and a system to convince your mind that whatever you put into the notebook will not be lost; create index, review notes and process them
  • have a time slot for important tasks
  • when stuck, take a break
  • don’t chase “silver bullets”

Source: freeCodeCamp.org

Categories
programming

PHP Exceptions

Example:

  1. exception is thrown
  2. following code is not executed
  3. PHP looks for catch block
  4. if catch block is not found, fatal error is issued with Uncaught Exception message

Solution:

  1. try – a function using an exception should be on a “try” block
  2. catch – a “catch” block retrieves an exception and creates an object containing the exception information
function x(){
  if(true) throw new Exception("error");
  return false;
}

try{
  x();
} catch (Exception $e){
  echo $e->getMessage();
}

You can create custom exception class that inheres properties from PHP’s exception class and add custom functions to it.

try{
  x();
} catch (Exception $e){
  throw new CustomException();
}

Categories
android games linux

Anbox

Anbox is a compatibility layer that allows mobile applications and games developed for Android to run on Linux. To achieve this, it uses standard Linux technologies like containers (LXC) to separate the Android operating system from the Linux host.

While emulators creates an entire emulated system which has its own kernel etc., Anbox runs the Android system under the same kernel as the host operating system does. No emulation layer is necessary, everything runs directly on the hardware. This approach also allows a much better integration with the host operating system. Anbox puts Android apps into a tightly sealed box without direct access to hardware or your data by mounting Android directory structure whilst using the native Linux kernel to execute applications.

Project is open source, current version is having trouble with kernel 5.7.

Commands

systemctl start systemd-networkd
systemctl start systemd-resolved
systemctl start anbox-container-manager.service
anbox session-manager
adb install package.apk
anbox launch --package=org.anbox.appmgr --component=org.anbox.appmgr.AppViewActivity
Categories
web design wordpress

Elementor

Elementor is a live page builder for WordPress. It means that whole process of writing and designing is done directly on the page with no need to press “Update” or go to preview mode. Free version of this WordPress plugin comes with 30 of the most useful widgets such as button, image carousel, tabs, accordion, alert etc. Pro/paid version comes with even more.

Elementor Page Builder can work with basically any WordPress theme that follows general WordPress guidelines. There are also lot of templates, both free and commercial, that you can customize to match your needs. To start from scratch, use Hello Elementor, a lightweight, plain-vanilla theme for this page builder. Keep in mind that this theme is specifically designed to work with Elementor Pro.

Elementor drag and drop on Twenty Twenty theme

Envato, the company behind the ThemeForest marketplace, is also the author of free WordPress plugin called Envato Elements. This plugin offers hundreds Elementor templates for all website niches. Combination of those two plugins can be used to create awesome websites directly from your WordPress dashboard.

Both plugins are open source.

Categories
games linux

Steam Play

Before we understand what Steam Play is, let’s check some prerequisites…

Wine

Wine, originally an acronym for “Wine Is Not an Emulator”, is a compatibility layer capable of running Windows applications on several POSIX-compliant operating systems such as Linux, macOS and BSD. Instead of simulating internal Windows logic like a virtual machine or emulator, Wine translates Windows API calls into POSIX calls on-the-fly, eliminating the performance and memory penalties of other methods and allowing you to cleanly integrate Windows applications into your desktop.

CrossOver

Wine is an open-source technology and can be downloaded for free. CrossOver is commercialized version of Wine from CodeWeavers.

Proton

Proton, a tool released by Valve Software and CodeWeavers, allows games which are exclusive to Windows to run on the Linux operating system. It uses a custom version of Wine as well as additional libraries developed alongside it to facilitate this. These include Direct3D to Vulkan translation layers, namely DXVK for Direct3D 9, 10 and 11 and VKD3D for Direct3D 12.

Vulkan

Vulkan is 3D rendering API, successor of OpenGL. Vulkan offers lower overhead, more direct control over the GPU, and lower CPU usage. The overall concept and feature set of Vulkan is similar to Mantle later adopted by Microsoft with Direct3D 12 and Apple with Metal.

Steam Play

Steam Play is compatibility layer built into the official Steam client that allows you to play games from your library that were built for other operating systems. For example, Steam Play uses Proton to allow Linux users to play Windows games.

DOSBox

DOSBox emulates an IBM PC compatible computer running a DOS operating system including many IBM PC compatible graphics and sound cards. This means that original DOS programs and games are provided with an environment in which they can run correctly, even though modern computers have dropped support for the old environment.

Boxtron

Boxtron is Steam Play compatibility tool to run DOS games using native Linux DOSBox. It enables you to play games on Linux that don’t have a Linux build setup on Steam only this is for DOSBox games.

Categories
linux programming web server

Simple Laravel Docker setup

composer create-project laravel/laravel laravel-app
cd laravel-app
touch .docker/Dockerfile
touch .docker/vhost.conf

Content of Dockerfile:

FROM php:7.3-apache
COPY . /srv/app
COPY .docker/vhost.conf /etc/apache2/sites-available/000-default.conf
RUN chown -R www-data:www-data /srv/app && a2enmod rewrite

Content of vhost.conf:

<VirtualHost *:80>
    DocumentRoot /srv/app/public
    <Directory "/srv/app/public">
        AllowOverride all
        Require all granted
    </Directory>
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Building image:

docker build --file .docker/Dockerfile -t laravel-app .

Running container:

docker run --rm -p 8080:80 laravel-app

Source: BitPress