Posts

Showing posts from September, 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 capture ruby console output

Image
While writing unit tests for a ruby project, headers-date , I had to unit test a function that print some useful debugging informations in terminal using IO#puts stdlib function. This code originally was posted to the following google group . The tested class Let's imagine a to-be-tested class that use puts , print or p IO methods to print some text to stdout (or stderr ). class TestMe def print puts "Some useful text" end end The capture trick To help testing the printed text, we will implement a new function called util_capture . It simply temporarily replace both $stdout and $stderr variables. The dollar sign prefix (sometimes called a sigil )in ruby is used to identify global variables . Here are really sparce official documentation on $stddout and $stderr The yield keyword will be replaced by your block. def util_capture require 'stringio' orig_stdout = $stdout.dup orig_stderr = $stderr.dup captured_stdout = ...

How to create a C++ Singleton using the boost serialization library

Image
A singleton is a class that can only be instantiated once. The design pattrern restricts the class to one single instance and further access will always return the same, first one. As explained in the singleton.html page, the boost serialization library has a Singleton class defined in the shipped Singleton.hpp C++ header. Dependencies On arch -based distributions, such as manjaro , this header is part of the extra/boost package. On Debian Bullseye , it is part of the libboost1.74-dev one but it's a dependency of the libboost-dev dependency package. So, according to your distribution, use the needed command : sudo pacman -S boost or sudo apt-get install libboost-dev Usage As seen in the boost class interface documentation, to use it, you just have to create a class that inherits the singleton one. Here is an example class that use boost's singleton to ensure one and only one instance will be in use : #include <boost/serialization/singleton.hpp> ...

Using the fox toolkit FileDialog static public functions

Image
This trick comes from a brand-new project I hosted at github : elecrud , more specifically the MainWindow::onFileOpen() method you can find in the src/editor/MainWindow.cpp file.   The dialog class The FXFileDialog class reference can be found online here for the 1.6 version of the fox toolkit library. So, obviously, you could instantiate FXFileDialog but the simplest way to use it is to use Static Public Member Functions , for example getSaveFilename() or getOpenFilename() : FXString filename = FXFileDialog::getOpenFilename(this, "Open a project...", "~"); // use filename here The owner class The only limitation is that you must have a valid owner as first parameter. If you try nullptr you may have a silly segmentation fault . The simplest solution is to call it from a class that inherits a Fox class, for example a MainWindow : class MainWindow : public FXMainWindow { // Macro for class hierarchy decla...

Introducing elecrud, a C++/electron based multi-user CRUD operator generator

Image
Well, this name is a bit weird but the project's still cool and since it's a new project, here it is : elecrud is a C++ fox-toolkit-based multi-user CRUD operator electron application generator. The goal is to create a lightweight yet portable graphical application used to edit and generate an electron application used to feed and edit a persistant set (i.e. a database) via standardized CRUD operations. Presentation This project is mainly a way to keep learning fox-toolkit , a very lightweight, open source and cross-platform widget toolkit libray licensed under LGPL. The main advantage of this toolkit, apart being lightweight is to have the same lookn-n-feel on all plateforms. While the first steps of the project seems pretty straightforward ( mainwindow and menu stuff), project serialization thing, the electron application squeleton and generation may fastly become challenging. The application is available under GPL v3 or later and hosted at github : https:/...