How to remove a trailing comma at the end of a string in Oracle

So I'm working in a database and in a particular column there is a trailing comma that I need to remove, a simple solution is something like this: We have something like this

SELECT 'a, b, c, d,' test From  dual;
The output is:

a, b, c, d,
To clean the last comma we can use RTRIM

SELECT RTRIM('a, b, c, d,', ',') new_test From  dual;
The output is:

a, b, c, d
Pretty neat!!!! RTRIM function Source 2

Trying to connect to oracle with Pentaho Ketlle and failed

So I was trying to connect to a Oracle database when I got this error


Connection failed. Verify all connection parameters and confirm that the appropriate driver is installed.
Listener refused the connection with the following error:
ORA-12505, TNS:listener does not currently know of SID given in connect descriptor
 

The configuration for the connection that I have is using the "Service Name" so in this case is an easy fix, just put a "/" in the beginning , like this.

Check ports if we don't have access to Telnet

In a project I'm helping sometimes as the support guy,so in the machine that I was working isn't posible to install anything and Telnet wasn't installed, one solution is using curl.

Command Line


curl -v telnet://ip:port
ip: the host that we want to check.
port: the port that we want to validate.

Example

Let's try to check if my RasberryPi is using the default ssh port.

curl  -v telnet://192.168.1.138:22
The response is something like this:
*   Trying 192.168.1.138:22...
* TCP_NODELAY set
* Connected to 192.168.1.138 (192.168.1.138) port 22 (#0)
SSH-2.0-OpenSSH_8.4p1 Debian-5+deb11u1
source

Format an USB with the command line in windows


I needed to format a USB after putting an ISO in it, here's how it can be done.

Now in D.O.S write:

diskpart.exe

Now we are in the dispar utility so let's put the commands

list disk

Disk ### Status Size Free Dyn Gpt
-------- ------------- ------- ------- --- ---
Disk 0 Online 238 GB 6144 KB
Disk 1 Online 1943 MB 0 B

select disk 1
Disk 1 is now the selected disk.
clean
DiskPart succeeded in cleaning the disk.
create partition primary
DiskPart succeeded in creating the specified partition.
select partition 1
Partition 1 is now the selected partition.
active
DiskPart marked the current partition as active.
format fs=ntfs quick
100 percent completed
DiskPart successfully formatted the volume.
exit
Leaving DiskPart...

Add and subtract days to a Date in Python 2

A few days back in the place where i work in the moment one of the reports was failing or at least one of the day was missing, the problem was the way of how it was getting the name of a file in it, the code was something like this in the script.

import datetime
now = datetime.datetime.now()
# we need the file of yesterday
myfile = '/home/dev/file_' + str(now.day - 1) + '_' + str(now.month) + '_' + str(now.year) +'.csv'

This look pretty and all but the problem was when the day is 1 the file of yesterday is not present because the day zero doesn't exist, so a better way of doing this is like:

import datetime
yesterday = datetime.datetime.now() - datetime.timedelta(1)
# we need the file of yesterday
myfile = '/home/dev/file_' + str(yesterday.day) + '_' + str(yesterday.month) + '_' + str(yesterday.year) + '.csv'

We can add days if we want like this

source

Download youtube videos as a mp3 using youtube-dl

so you only need youtube-dl and ffmpeg and if you want your mp3 file with metadata like the artist and title we can use the next command line:

youtube-dl --prefer-ffmpeg --extract-audio --audio-format mp3 --audio-quality 1 -o '%(title)s.%(ext)s' --metadata-from-title '%(artist)s - %(track)s' --add-metadata

Let's explain some of the argument


--extract-audio: Convert video files to audio-only files
--audio-format: Format of the audio file
--audio-quality: Quality of the audio can be between 0 (better) and 9 (worse)
-o or --output: How we want to name the file
--metadata-from-title: Parse additional metadata from the video title the format like --output
--add-metadata: Actually write the metadata in the file

Documentation