Stannum

FreeBSD cheatsheet

2019-09-29 Permalink

Generate a secure password:

$ head -c 30 /dev/random | uuencode -mr -

Recover partitions (including exfat):

$ testdisk /dev/disk-or-section

Create then extract an encrypted backup (split into chunks):

$ tar -cf - input/ | openssl aes-256-cbc -md sha256 -pbkdf2 | split -b 100M -a 4 -d - output/backup.tar.
$ cat output/backup.tar.* | openssl aes-256-cbc -md sha256 -pbkdf2 -d | tar -xfv -

Set time in current timezone:

# date 2315

To set ISO date format, go to /usr/share/locale/en_US.UTF-8/LC_TIME (or similar) and change %m/%d/%Y to %Y-%m-%d. It's not respected by software that relies on their own date formatting (offender: Qt).

After tweaking the MIME Applications Associations, update the cache through

$ update-desktop-database ~/.local/share/applications/

Packages

Display the post-install message:

$ pkg query %M firefox

List non-automatic packages:

$ pkg query -e '%a = 0' %o

Audio

Keep reading...


True encapsulation in C++

2019-04-25 Permalink

Access specifiers are taught as the encapsulation mechanism in C++. However, I’ve mentioned before how poorly they perform their function.

For example:

class A {
public:
	// ... public interface ...
private:
	void f(C);
	B b;
};

In order for this code to compile, B must be previously defined and C must be previously declared. Both of these types, as well as the function f and the layout of the private members of A are an implementation detail. Yet they leak out to the users of A. This in turn has negative impact on compile times (of incremental builds in particular), makes headers harder to comprehend, and makes it harder to change A implementation without breaking the ABI.

In the following text I refer to this approach as the ‘traditional’ method.

Keep reading...


Useless language features

2019-03-01 Permalink

It strikes me how language designers don’t get this simple truth:

If the feature usefulness does not outweigh the complexity it adds to the language, it shall be left out.

In particular, if the feature is of the ‘no-op’ kind—i.e. it can be removed while retaining an identically functioning program without significantly sacrificing code clarity, or there is another way to express the same idea within the language in perhaps even better way. Many such features are better to be turned into implementation specific annotations (like C++ attributes), compiler warnings, or left out completely.

Let’s take a look at how it applies to C++ .

Access specifiers

C++ has three access specifiers: public, private and protected. They are the glorified mechanism for encapsulation in C++. However, if you ever wrote C++ code before, you know how poor the encapsulation they provide:

Keep reading...


Sony ARW distortion correction

2018-05-09 Permalink

Raw output of Sony cameras is saved in its proprietary ARW format. It is a TIFF-based format that stores lots of undocumented and partially encrypted metadata in its TIFF directories. Some have already tried to reverse engineer the format, but most of it still remains undocumented.

Here I summarize my findings of how the distortion correction is applied. The following is my best guesses based on the ILCE-7RM2 camera I have.

Overscan

The first thing to notice is that the camera produces JPEGs of 7952×5304 pixels in size, whereas the ARW contains a 8000×5320 raster. One source of discrepancy is the 32 pixels of overscan on the right; they simply repeat the rightmost Bayer cell 16 times.

A crop from the right edge of a raw image, featuring overscan.

Cropping the overscan yields a 7968×5320 raster.

Keep reading...


Read all posts...