Skip to content

Tag: Linux

Notes on Python venv

Python 3.3 or later comes with venv. For Python 3.* < 3.3 with apt:

$ sudo apt install python3-venv

To create, activate and pip install packages:

$ python -m venv my_venv
$ source my_venv/bin/activate
(my_venv)$ pip install gimpformats

To deactivate the venv:

(my_venv)$ deactivate

This allows to have Python virtual environments with isolation. It’s particularly useful when using systems that don’t allow to use pip directly as WSL (Windows Subsystem for Linux).

tmux save scrollback to a file

Before each command, run the prefix (default Ctrl+B).

:capture-pane -pane -S -3000
:save-buffer buffer.txt

This will write all scrollback from that pane to a file ~/buffer.txt.

endless tail in a file

tail -n 50 -f your.log
  • –folow or -f FILE to output appended data as the file grows
  • –lines or -n K output the last K lines of the file

Alternatively,  you can also use watch.

Bash Brace Expansion

photo by whiskeyandtears at https://www.flickr.com/photos/whiskeyandtears/2140154564

[bash]$ echo {0..9}
0 1 2 3 4 5 6 7 8 9[/bash]

[bash]$ echo b{a,e,i,o,u}
ba be bi bo bu
[/bash]

[bash]$ echo x{0..9}y
x0y x1y x2y x3y x4y x5y x6y x7y x8y x9y[/bash]

[bash]$ echo {a..z}
a b c d e f g h i j k l m n o p q r s t u v w x y z[/bash]

[bash]$ echo {1..3} {A..C}
1 2 3 A B C[/bash]

[bash]$ echo {1..3}{A..C}
1A 1B 1C 2A 2B 2C 3A 3B 3C[/bash]

[bash]echo {a,b{1,2,3},c}
a b1 b2 b3 c[/bash]

[bash]$ mkdir -p {project1,project2}/{src,tst,bin,lib}/
$ find .
.
./project1
./project1/tst
./project1/bin
./project1/lib
./project1/src
./project2
./project2/tst
./project2/bin
./project2/lib
./project2/src
[/bash]

[bash]$ echo {{A..Z},{a..z}}
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z[/bash]

[bash]$ for i in {a..f} 1 2 {3..5} ; do echo $i;done
a
b
c
d
e
f
1
2
3
4
5[/bash]

The examples below requires Bash version 4.0 or greater.

[bash]$echo {001..9}
001 002 003 004 005 006 007 008 009
[/bash]

[bash]$ echo {1..10..2}
1 3 5 7 9
[/bash]

find a process running a deleted library

sudo find /proc -maxdepth 2 -name maps -exec grep -HE ‘\(deleted\)’ {} \; | cut -d/ -f3 | sort -u | xargs –no-run-if-empty ps

Looking for libssl in specific:

sudo find /proc -maxdepth 2 -name maps -exec grep -HE ‘/libssl\.so.* \(deleted\)’ {} \; | cut -d/ -f3 | sort -u | xargs –no-run-if-empty ps

Killing all process using a deleted version of libssl:

sudo find /proc -maxdepth 2 -name maps -exec grep -HE ‘/libssl\.so.* \(deleted\)’ {} \;| cut -d/ -f3 | sort -u | xargs –no-run-if-empty sudo kill

if host pings execute command

[bash]#!/bin/sh
HOST="silveiraneto.net"
if ping -c 1 $HOST > /dev/null
then
echo your command
fi
[/bash]

  • replace silveiraneto.net for your desired hostname or ip
  • ping sends only one package (-c 1) and ignores the text output
  • a ping is successful returns 0 and the if proceeds
  • replace the echo line with your command

printing only odd or even lines using sed

$ cat AtoF
A
B
C
D
E
F

Print only odd lines

sed -n 'p;n' AtoF
A
C
E

-n suppress automatic printing of pattern space, p print the current pattern space, n read/append the next line of input into the pattern space.

Alternatively:

$ sed -n 1~2p AtoF
A
C
E

-n suppress automatic printing of pattern space, 1~2 from the 1st line match every line every 2 steps, p print the current pattern space. sed -n 0~p has the same effect . print only the even lines.

Print only even lines

$ sed -n 'n;p' AtoF 
B
D
F

or

$ sed -n 2~2p AtoF
B
D
F

0~2p would also work. I prefer

DIY recycle your old tv

When I came here to this room I found this old big tv laying around. Old but perfectly functional.

First I put a tv cable on it with hundreds of channels but after one month I realized that mostly of them are crap and I was watching everything on my laptop (mostly shows from Netflix and BitTorrent). Obviously I wanted to connect my laptop video output on it.  As an old television it doesn’t have any HDMI port. It have a RCA video and audio ports so after some research I bought a VGA-to-RCA converter. Besides watch movies on it there is a lot of cool things I could do with it to decorated the room or create a environment while we are jamming.

In this article I’ll show how to create a fireplace.

You will need

Getting a high definition fireplace video

You can search in Youtube for high definition fireplace videos.

There is a lot of ways to extract the videos from Youtube and it’s not the point explain it here but I can say one the best ways today is using JDownloader. Using it you can extract sound and video in any available resolution.

Choose a fireplace video and download the highest resolution available (usually 720p). Here I stored it at /home/silveira/Videos/fireplace_hd.flv.

Screen layout

I’m using the TV as a second display in the right. The width of my laptop monitor is 1920.

Creating a shortcut

First, right click in the upper panel of Gnome and select Add to Panel.  Select the Custom Application Launcher option.

Let’s fill it like this:

On the command put:

/usr/bin/mplayer /home/silveira/Videos/fireplace_hd.flv -nosound -loop 0 -geometry +1900+0 -fs

Explaning:

  • /usr/bin/mplayer the mplayer full path (probably you have the same path but you can try “whereis mplayer” in a terminal to find it).
  • /home/silveira/Videos/fireplace_hd.flv as I said, where I put the video.
  • -nosound no sound. 🙂 Usually I have some music playing so I don’t want any fire sound. But if you want  the fire crackling sound omit this parameter.
  • -loop 0 the video I took have 10 minutes. If I put -loop 6 it would loop for 1 hour. Zero means infinite times.
  • -geometry +1900+0 you can specify the size of the screen and position but here I’m justing saying I want it on horizontal position 1900 (bigger than my first screen) so it goes to the tv.
  • -fs fullscreen

Now drink the wine and cheese in front of your low carbon footprint fireplace.  😉

Bonus

Now you can use the same idea and make an virtual aquarium, ant farm, an interactive art piece or anything!

Miojo Script

O pre-requisito é o notify-send, um utilitário de linha de comando do libnotify. No Ubuntu:

sudo aptitude install libnotify-bin

E aqui o script em si:

sleep 5m; notify-send "aviso" "tirar o miojo do fogo"

Pronto, depois de cinco minutos isso vai aparecer:

Congelando e Ressuscitando Processos

batman mr freeze

Nem só de morte vive o kill.

Suponha que você tem um processo chamado program e quer congelar seu funcionamento. Para congela-lo sem mata-lo você pode mandar um sinal SIGSTOP com:

kill -s stop `pidof program`

Para ressuscitar o mesmo processo:

kill -s cont `pidof program`