Rename files according to date
I recently wrote a Perl script, that renames the files in a directory according to the date, in the format “YYYYMMDD ##” where “##” is the running number.
Rationale
Because I used to download the photos using the mobile apps like Weibo or Twitter, however the file names are almost random. This made me hard to organize these photos on my computer.
The artists (or celebrities) usually share a set of their photos, so when I download these photos, the files should have mtime (modified time) in the correct order.
Inheritance and composition
The modern JavaScript with the ES6 syntax and the rise of the popularity like ReactJS, functional programming becomes more and more common. When using React, one of the common practice is to use composition instead of inheritance.
Because I started learning programming when the OOP was the most prevailing paradigm, I was trained to solve the problem by using OOP concepts like polymorphoism, inheritance, encapsulation, etc.
I think JS is the most interesting programming language in the modern technology. It supports server-side and client-side development. With the ES6, it supports OOP keywords like class and also using FP (functional programming) syntax like fat arrow (=>).
Coin Flip Conundrum
I watched this video,
[youtube https://www.youtube.com/watch?v=IAiNqQi30-Y]
Very interesting.
So, I managed to prove it through some scripting.
https://gist.github.com/allencch/36544a84fdb8159756618290209f1750
And I get some result like this,
[code lang=text] Result: Target: [0, 1] average steps = 3.987 Target: [0, 0] average steps = 5.9505 [/code]
P/S: Wrote a robust flip coin script, which can accept the coin tossing sequence with any length. [here]
C++ future
Recently updating my hobby project Med, memory editor for Linux, still under heavy development with various bugs.
In this project, I use several C++1x features (compiled with C++14 standard). Most recent notable feature is multi-threading scanning. In memory scanning, scan through the accessible memory blocks sequentially is slow. Therefore, I need to scan the memory blocks in parallel. To implement this, I have to create multiple threads to scan through the memory blocks.
PHP programming
PHP was a great programming language in web development. It surpasses the VBscript for ASP and Perl for CGI. It is favoured because of the syntax based C and C++. It supports procedural programming paradigm and object-oriented paradigm. A lot of functions resemble C functions such as printf, fprintf, sprintf, fopen, etc. Similarly, it can work directly to the C library such as expat, zlib, libxml2, etc. A lot of great content management systems (CMS) are written in PHP, such as Drupal, Wordpress, Joomla, etc.
Closure
In JavaScript, we can create closure like this,
[code language=“javascript”] var foo = (() => { let x = 0; return () => { return x++; } })();
for (var i = 0; i < 10; i++) { var x = foo(); console.log(x); } [/code]
But translating above code into C++, it cannot work as expected for the variable, unless the variable is outside the lambda function.
[code language=“cpp”] // In a function int x; // variable here auto foo = [&x]() { x = 0; return [&x]() { return x++; }; }(); for (int i = 0; i < 10; i++) { int x = foo(); cout « x « endl; } [/code]
CSV to something
Just revived my old script into a project in GitHub, csv_to_something. An old simple script that was created to manage some student data. Because the students data were collected through Google Forms, so I convert it to CSV, then from CSV to SQLite. So that I can use the SQL to query whatever data I need.
Using SQLite software such as sqliteman and sqlitebrowser, I can create any new table, grouping, sorting etc.
Coding and cognitive functions
When I was doing programming as a hobbyist, I thought that writing source code is to communicate to the computer. Then lately working as software developer, I realised that coding is not just communicating to the computer, it is also communicating with other software developers.
When we are working on a big project, working alone is impractical. Then we need to work as a team. Consequently, our coding style needs to be conformed to ease the code review. Because at the end, the code is belong to the team, not an individual. That is why, practicing “clean code” is very important.
A brief comparison of GTK+ and Qt
I used to like C language, because it is a basic of programming, and it is portable, and it is low-level. When writing program with C language, it is just like showing off your advanced programming skill, how you manage the memory, how you manage the pointers and creating the linked list. However, in terms of efficiency, C++ is much more powerful, because of object-oriented and the syntax.
Because I like C language, so I chose GTK+ over Qt for long time ago. Not only that, I am also fond of GTK+ desktop environments like GNOME, Xfce4, LXDE, Cinnamon, but not Mate. I feel that KDE is heavy weight.
Heading, anchor, and bookmarking
Sometimes I read online articles, and these articles are usually long pages and have outlines at the beginning. These outlines are the hyperlinks to the subtopics headings. Technically, you click the outline hyperlink, your browser will browse to the “anchor”, the URL will append with hash (#). Therefore, it is useful for bookmarking, so that you can share the URL target on the topic to someone else, or re-visit your bookmark.