Quick ebook conversion with Calibre in console

calibre

I mostly use fbless ebook reader, because it works on console and don’t need to switch to X server for reading. Downside is that it recognize only .fb2 or .fb2.zip format, which is not so common. For quick conversion I use Calibre command line tool:

ebook-convert How.to.Convert.Ebooks.epub How.to.Convert.Ebooks.fb2

…quick and efficient.
Happy hacking….

Editing files over ssh in vim

archlinux-logo-dark-200dpi.b42bd35d5916

Need a quick file edit on remote server. With vim it’s easy, use:

vim scp://username@host:port//path/to/file

…or within vim:

:e scp://username@host:port//path/to/file

…or if you are not sure about name of the file, browse remote directory with:

:e vim scp://username@host:port//path/to/directory/

Directory path must end with /.Remote home directory is invoked with:

:e scp://username@host:port/~/

Use rcp instead of scp for ftp access.
Happy hacking….

inxi weather

archlinux-logo-dark-200dpi.b42bd35d5916

inxi, very versatile script to get various hardware and software data, have also interesting option -w which display local weather data:
Weather: Conditions: 36 F (2 C) - Clear Time: February 4, 8:15 PM CET

…or if you use verbose variante with -x, -xx or -xxx, the output contains more data:
inxi -wxxx
Weather: Conditions: 36 F (2 C) - Clear Wind: From the South at 2 MPH Humidity: 87%
Pressure: 30.21 in (1023 mb) Location: None None (SVN) Altitude: 280 ft
Time: February 4, 8:20 PM CET (Europe/Ljubljana) Observation Time: February 4, 8:00 PM CET

…and with option -W you can change location input:
inxi -wxxx -W vienna,austria
Weather: Conditions: 39 F (4 C) - Mostly Cloudy Wind: From the West at 13 MPH Humidity: 70%
Pressure: 30.15 in (1021 mb) Wind Chill: 32 F (0 C)
Location: Vienna (OS) Altitude: 171 ft
Time: February 4, 8:24 PM CET Observation Time: February 4, 7:50 PM CET

Happy hacking…

kodi – network ports

kodi-helix-14.1-600x336

If you use XBMC or now Kodi, those are the ports that should be open for full network access:
tcp 8080 – web interface, can be changed,
udp 1900 – dlna,
other ports:
tcp: 1084, 1308, 1131,
tcp (ipv6): 9090 (optional if you use ipv6 connections),
udp: 9777, 12374.
Those are ports that I opened and can be seen with console command:
netstat -ntulp
If you use iptables those are commands:

iptables -A TCP -p tcp --match multiport --dports 1084,1131,1308,8080 -m comment --comment "kodi" -j ACCEPT
iptables -A UDP -p udp --match multiport --dports 1900,9777,12374 -m comment --comment "kodi" -j ACCEPT
iptables-save > /etc/iptables/iptables.rules
systemctl reload iptables

…as root.
Happy hacking…

hstr – improved bash history completition

hh>

When working on command line most of the time, there is always a problem with long commands, for example:
find . -depth -name '* *' -execdir bash \-c 'a="{}";mv -f "$a" ${a// /.}' \;
(this command replace all spaces ‘ ‘ with dots ‘.’ recursively in directories and file names, see my post for explanation)

There is option with ctrl-r or you can use clipboard manager like anamnesis or CopyQ or some other helper. A while ago I stumbled upon hstr on ArchLinux AUR repository (it’s called hh there) and I’m using it since then. The advantages are easier and more efficient browsing with managed history (removing sensitive commands) and option to bookmark favorite commands.
When installed just configure hh with:
hh --show-configuration >> ~/.bashrc
and with the same ctrl-r keyboard shortcut.

For quick introduction you can view video tutorial on Youtube or, when installed read man hh.

Happy hacking….

goto – enhanced cd command

archlinux-logo-dark-200dpi.b42bd35d5916

goto – enhanced ‘cd’ command replacement tool with fuzzy file finder and a directory bookmark saver, similar to autojump.

The usage is simple and effective:

goto -h, -help, h, help  # Prints the Usage

goto "location address"  # Takes you to the "location address"

goto s, -s "shortcut"  # Saves the Current Directory location as "shortcut"

goto l, -l  # Lists all the Bookmarks saved

goto d, -d "shortcut"  # Deletes the "shortcut" saved

goto p, -p "shortcut"   # Prints the GOTO directory for "shortcut"

goto f, -f, find, -find "term"  # Fuzzy-Finds all the file/folder matching REGEX in the working directory

Give it a try…

…and happy hacking.

world in ASCII code

asciiworld

asciiworld – that’s how world is represented in ASCII code. Interesting project which come equiped with some interesting tools: geoIP, day/night, satelite tracking, different world projections.

If you are on ArchLinux instalation is simple, just use AUR repository, for others compiling is the option, just read README files and Makefile for dependencies.

Anything else…, oh yes, the words of author vain aka.Peter Hofman: “Having a little bit of fun.”

Happy hacking….

Recursive change of file permissions and attributes

ratpoison_logo-60

This is just quick sequel to previous post:
#changing directory permissions to 755
find . -depth -type d -name '*' -execdir bash \-c 'a="{}";chmod 755 -f "$a"' \;

#changing file permissions to 644
find . -depth -type f -name '*' -execdir bash \-c 'a="{}";chmod 644 -f "$a"' \;

…of course you must be root to do so…
Happy New Year!

Recursive Batch Rename in Console

ratpoison_logo-60

One quick one for the end of the year…
Recursive batch rename of directories and files in the same time:

#replace ” ” with “.”:
find . -depth -name '* *' -execdir bash \-c 'a="{}";mv -f "$a" ${a// /.}' \;

#replace “-” with “_”:
find . -depth -name '*-*' -execdir bash \-c 'a="{}";mv -f "$a" ${a//-/_}' \;

#replace “if” with “or”:
find . -depth -name '*if*' -execdir bash \-c 'a="{}";mv -f "$a" ${a//if/or}' \;

…if you want to rename just directories or files just add:

-type d #for directories
-type f #for files

…after…
-depth

Happy New Year….

sox and remind alarm clock

sox console output

I’m long time user of remind, which by the way is excellent calendar,reminder and alarm program, also with text-based front-end wyrd and both text and graphical front/back-end wxRemind. It is also possible to use iCal data with remind, thanks to the two scripts, ical2rem for conversion from iCal to remind format and rem2ics for oposite conversion.

Beside text reminders I’m using remind as everyday alarm with the assistance from sox, known as ‘the Swiss Army knife of sound processing programs’ or as ‘command line utility that can convert various formats of computer audio files in to other formats. It can also apply various effects to these sound files, and, as an added bonus, SoX can play and record audio files on most platforms.’

remind use simple text file for executing various reminders, calendars and alarms:

REM sunday AT 10:00 MSG "Don't forget to write WordPress post about remind."

This reminder can be executed with, for instance xorg-xmessage or gxmessage:

remind -z '-kxmessage %s' .reminders &

…were .reminders is the name of text file…
another option is use of RUN command, for executing scripts or programs. This is very useful for various alarm options to start various audio players and this is where sox come into play for me:


#.alarms
REM monday AT 6:30 RUN sox -q "~/alarms/file.mp3" -t alsa default
REM tuesday AT 6:15 RUN sox -q "~/alarms/file1.mp3" -t alsa default
REM wednesday, thursday AT 7:00 RUN sox -q "~/alarms/file2.mp3" -t alsa default
...
...

…and alarms with:

remind -z .alarms &

There are many ways to start both remind instances, with .bashrc, .xinitrc ar in my case with .ratpoisonrc:

#Remind
exec remind -z '-kxmessage %s' .reminders &
exec remind -z .alarms &

…With remind, possibilities are endless.