Posts

Showing posts from August, 2022

How to fix the Unbound module Graphics in an ocaml project

Image
From ~/pr/gitl/ocaml-gol In a constant effort to learn new programming languages, I'm currently trying to use ocaml , a free and open-source general-purpose, multi-paradigm programming language maintained at the Inria . It's basically an extension of Caml with object-oriented features. I'm mostly interested by its functionnal and pattern matching features but the module part of the language can be a bit difficult to understand for someone with little to none ML (Meta Language) background.   The error When trying to use the graphics module to create a graphical window and go just a little further than the simplest helloworld program, here is the result : If the project uses dune : (executable (name ocaml_project) (libraries lwt.unix graphics) ) with this code : let () = Printf.printf "Hello, world!\n";; Lwt_io.printf "Hello, world!\n";; Graphics.open_graph " 800x600";; The first times I built this project running the du...

How to handle loading progress using PubSub design pattern

Image
In the RainbruRPG 's LocalTest class, we show the map generation progress from libRLGL using a LoadingBar. The loading informations simply come from a Publisher/Subscriber design pattern from the LoadingBarListener override. Following examples are obviously implemented in C++. It should correctly build on every compiler with, at least, C++11 support. The PubSub design pattern This design pattern involves at least three classes. Here is an example UML diagram done with umbrello , a free and open source UML modeler licensed under GPL 2 or later : In this example, the Publisher class will be able to send message to an arbitrary list of classes that inherits the Listsner abstract type. From the Publisher point of view The publisher side needs at least a base class to be overridden by the subscriber and a list of subscribers : #include <vector> class Listener { public: virtual void message1()=0; virtual void message2()=0; virtual void message3()=0; }...

How to generate a file from a template using cmake

Image
If you use cmake to configure a project, whatever the programming language the project is written in, you can and certainly already use the configure_file() cmake function to copy a file and modify its content using variables substitution. The configure_file function While this trick is generally used to generate, often plateform-dependant config.h from a config.h.in template, it can be used to generate arbitrary file using variable substitution. For example, Doxyfile , the file used to generate doxygen API documentation Destination directory You can also change the destination directory of the file. For example, often, we use a build/ subdirectory to call cmake from to avoid project source tree pollution : configure_file( "${PROJECT_SOURCE_DIR}/config.h.in" "${PROJECT_BINARY_DIR}/config.h" ) The variables are PROJECT_SOURCE_DIR and PROJECT_BINARY_DIR to change the source and destination directory of the generated file. If you...

How to recover deleted files under GNU/Linux

Image
By mystake, I called rm on a complete directory and the result is awful and predictable : all files were correctly deleted. Just after, I searched for a solution. Install needed package We will use a free and open source software licensed under GPL v2+ called TestDisk . First, install the testdisk package using your distribution's package manager. On debian -based systems : sudo apt install testdisk or on arch -based distributions such as manjaro : sudo pacman -S testdisk Gathering informations Before starting the restoration process, you'll need some informations : The df -m command can help you find this information from the mount point the deleted file was on : Filesystem 1M-blocks Used Available Use% Mounted on udev 4949 0 4949 0% /dev tmpfs 999 10 990 1% /run /dev/sda1 23339 10168 11963 46% / tmpfs 4993 173 4820 4% /dev/shm tmpfs 5 1 ...