Posts

Finding similar file names

Image
This is a story about the creation of a nice script... A friend of mine needed a script to find files which are similar, without reading their content. She suggested comparing the file attributes, like the file size and some other attributes. So, I gave her this script . It works great when there not many files which have the same size. So, you can safely say that the files are similar if they have the same attributes. But in some cases, this may be a real disaster because there may be lots of files that have the same attributes and are not actually similar. So, I came up with a new idea. I suggested grouping the files by size and compare their names. If the shortest name is contained in the biggest name, then the files are similar. But not so fast. We need some rules, because we can have two files like: ' A happy file name.txt ' and ' a.txt '! They are not similar, even if the shortest name ' a ' is found in the longest name ' A happy fil...

Find duplicate files

Image
fdf - a pretty clever Perl script to find duplicate files across directories. It is very simple and very fast. It doesn't use any checksum. It reads (through the File::Compare module) chunks of data from two files. If the chucks are not the same, we already know that the files can't be duplicates of each other. This is one reason why it is fast, but the other reason is that, if we have 3 duplicate files, let's say: "A", "B" and "C", we compare "A" with "B" and they are the same, then we compare "A" with "C", and are the same, we don't have to compare "B" with "C" because they are duplicates of "A", which tells us that they must be exactly the same. Yet another reason: files are grouped by file size. So we compare two files only if they have the same size. (Getting the size of a file it's a very simple and fast check). The script accepts one argument: either ...

clyrics

Image
It's a simple script to get and print the lyrics for the current playing song in the moc player. It uses the Google search engine to search for the lyrics with the song name, looking for popular lyrics websites, trying to get lyrics of the current song and print them to the standard output. One important feature is the easy way of adding support for more websites. UPDATE : The project evolved into clyrics! Github :   https://github.com/trizen/clyrics AUR :   https://aur.archlinux.org/packages/clyrics/

pview

Image
pview is a perl source code viewer. It highlights the code using a pretty good Perl tokenizer. The color scheme can be very easy customized inside the script. Download pview :  https://github.com/trizen/perl-scripts/blob/master/Visualisators/pview On the same concept, a new script has been created, called ' scgrep ' which grabs form a Perl script only the elements that the reader wants. (e.g.: regular expressions, operators, numbers, etc...) Download scgrep :  https://github.com/trizen/perl-scripts/blob/master/Greppers/scgrep Even better, this tools are now available as part of the Perl::Tokenizer CPAN module, which also include another interesting tool, called pl2html  which highlights Perl code in HTML.

disk-stats

Image
RAM and disk usage status. A very simple command line tool which displays a status bar with the used space for each partition. It uses the ` df ` command to get the information needed and automatically adjusts itself to the terminal width. It can, also, be very easily adjusted to your own preferences. Just for fun. :) Download:  https://github.com/trizen/perl-scripts/blob/master/Visualisators/disk-stats.pl

obbrowser

Image
obbrowser is a very simple script which displays files and directories in the Openbox menu. It recursively browse the filesystem through openbox3 pipe menus. (related to  fbrowse-tray ) The following line needs to be added inside the menu.xml file:   <menu id="obbrowser /my/dir" label="Disk" execute="obbrowser"/> Or, if you are using the obmenu-generator , add the following line inside the schema.pl file:   {pipe => ['obbrowser /my/dir', 'Disk', 'drive-harddisk']}, The script supports a large variety of icons, thanks to  File::MimeInfo  module. Github:  https://github.com/trizen/obbrowser AUR link:  https://aur.archlinux.org/packages/obbrowser/ Simple version, in C++ :     https://github.com/trizen/cpp-learning/blob/master/Apps/openbox-pipefs.cpp Simpler version, in Go:      https://github.com/trizen/go-learning/blob/master/Apps/openbox-pipefs.go

alsi

Image
alsi is a system information tool, designed for Arch Linux, related to archey and screenfetch, but more configurable. All the configuration files are in:  ~/.config/alsi For example, to configure it for Gentoo, get the  gentoo logo  and put it in  alsi.logo  file, change something in  alsi.output  and  alsi.conf  files (if necessary) and then execute:  alsi -f -l -c1=blue -c2=purple Result: 1. Changing  alsi.output : my $ b = "\b\b\b\b" ; [ { HARDCODED => "\b\e[1;37m\e[41mTHIS IS ALSI\e[0m" } , { OS => $ b . '%13sOS:%s %s' } , # Operating system { HOSTNAME => $ b . '%4sHostname:%s %s' } , # Hostname { UPTIME => $ b . '%9sUptime:%s %s' } , # Uptime { KERNEL => $ b . '%9sKernel:%s %s' } , # Kernel version { SHELL => $ b . '%10sShell:%s %s' } , # Shell { PACKAGE...

Binary search

Image
When we are looking in a sorted list, we are looking for which part of the list begins with the character we want. This technique can be implemented in Perl known as binary search, because we divide the list in two pieces after each look. We are starting in the middle of the list and we check if the current word is lower or greater than the word we are looking for. If it is lower, we are going in the middle of the bottom half of the list, if it is higher, we are going in the middle of the top half of the list, and we are continuing the process, dividing the list in halves until we find the word we are looking for, or we are out of the list. This process is faster than linear searching because we skip quite a lot of words in large arrays. The biggest drawn back is that the list must be sorted, but this is fine if we sort the array once and then we make multiple checks to see if some words exists inside the list. This algorithm is best suited to look for some lines in a very large a...

Linux::DesktopFiles

Image
After a pretty long vacation, I'm back with some news :) I created this Perl module to use it for  menutray , fbmenugen and obmenu-generator . It requires the  Module::Build  for installation. It has been designed to be very fast and pretty easy to use. It parses the *.desktop files and returns a Perl data structure with the information required. It offers many configuration options (see the man page or the source code). It works only on Linux with a version of perl>=5.14.0; Download:  https://metacpan.org/module/Linux::DesktopFiles

file-monitor

Image
file-monitor is a simple Perl script to monitor a directory path for new files, updated files and deleted files. It can be set to look for new files in a given interval of seconds (e.g.: -n 30) and also can be set to check for updated and deleted files in another interval of seconds (e.g.: -c 12) Download:  https://github.com/trizen/perl-scripts/blob/master/Monitoring/file-monitor

Expanding a string

Image
The problem: We have a string like this: my $ str = 'perl-{file-{which,basedir,copy-recursive},pathtools,path-class}' ; ... and we need to expand it into: ( 'perl-file-which' , 'perl-file-basedir' , 'perl-file-copy-recursive' , 'perl-pathtools' , 'perl-path-class' , ) Solutions: One-line solution:  split q{ } , qx(echo $string) ; Go:  https://github.com/trizen/go-learning/blob/master/abs_string.go Perl:  https://github.com/trizen/perl-scripts/blob/master/Text/abs_string.pl Sidef:  https://github.com/trizen/sidef/blob/master/scripts/absolute_string.sf Sidef:  https://github.com/trizen/sidef-scripts/blob/master/Text/shell_string_expand.sf

GD::Simple

Image
GD::Simple is a simple interface to the GD  library, which is an open source code library used in dynamic creation of images by programmers. If you like math, this library will bring a lot of fun in your life. :) Images :  https://goo.gl/photos/6n1KzxZNxW6tTsxe8 Scripts :  https://github.com/trizen/perl-scripts/tree/master/GD

YouTube Viewer

Image
# GTK YouTube Viewer This application came to life in 12 September 2010 as my first GTK2/Glade learning project. gtk-youtube-viewer Its scope is to search and play YouTube videos in a native player.  It comes with various search options; it can search for videos, playlists and/or channels. The videos are streamed directly in a selected video player at the best resolution (customizable) and with closed-captions (if available). By default, the application supports three video players: MPV (recommended), MPlayer and VLC, but it allows the addition of more players inside the configuration file. For a better experience, the application also comes with built-in authentication support, using the OAuth 2.0 mechanism. After inserting the authentication token, a new tab will appear, named "My panel", which has the following buttons: Subscriptions Favorited videos Liked videos Disliked videos Uploads Playlists Log out For more details (+screenshots), see also: ...

obmenu-generator

Image
obmenu-generator  is a simple, lightweight, easily configurable Perl script that generates a full Openbox XML-menu based upon the information present in *.desktop application files (related to  fbmenugen  and  menutray ). It has full support for icons (respecting the current icon theme) and can generate either a static or a dynamic menu. The parsing of the *.desktop files is provided by the Linux::DesktopFiles module. In a dynamic menu, the entries are updated automatically when a new application is installed or when the current icon theme is changed by the user. Starting with version 0.61, obmenu-generator introduced a new smart-cache system which will store all the required data from the *.destkop files in a new cache.db file, which is also updated automatically when a new application is (re)installed or when the config.pl  or schema.pl are changed. With the new cache-system in place, a full menu with icons is generated in ~8ms (compared...

fbmenugen

Image
fbmenugen is a simple menu generator for the Fluxbox WM (related to  menutray  and  obmenu-generator ). It generates a valid Fluxbox menu file with the applications from the /usr/share/applications  directory, ordered on categories. It also provides a configuration file that allows the user to customize the menu. Github:  https://github.com/trizen/fbmenugen AUR Link:  https://aur.archlinux.org/packages/fbmenugen/

menutray

Image
Menutray is a simple menu generator (related to obmenu-generator  and  fbmenugen ). It generates a Perl script containing all the applications from the /usr/share/applications directory, ordered on categories. It also provides a schema file for customization. Starting with version 0.42, menutray supports Gtk3 with the  --gtk3 option . Github :  https://github.com/trizen/menutray AUR Link :  https://aur.archlinux.org/packages/menutray/

locatepm

Image
Find installed Perl modules matching a regular expression. It's very fast and efficient. Download : https://github.com/trizen/perl-scripts/blob/master/Finders/locatepm