Skip to content

Instantly share code, notes, and snippets.

@yudi-matsuzake
Last active August 29, 2015 14:12
Show Gist options
  • Save yudi-matsuzake/6a38c1d2e96daeb908e6 to your computer and use it in GitHub Desktop.
Save yudi-matsuzake/6a38c1d2e96daeb908e6 to your computer and use it in GitHub Desktop.
Log informal de algumas coisas - ao meu ver - interessantes.

Bibliotecas necessárias para o Spotify rodar músicas locais

  • libx264-123

  • ffmpeg

Alterando as metatags de um mp3 com ffmpeg

ffmpeg32 -i out.mp3 -metadata title="The Title You Want" -metadata artist="" -metadata album="Name of the Album" out2.mp3

wget imagens

wget -r -P /save/location -A jpeg,jpg,bmp,gif,png http://www.domain.com

More information:

-r enables recursive retrieval. See Recursive Downloadfor more information.

-P sets the directory prefix where all files and directories are saved to.

-A sets a whitelist for retrieving only certain file types. Strings and patterns are accepted, and both can be used in a comma separated list (as seen above). See Types of Files for more information.

Comando de hardwares

lscpu

Lista as cpus disponíveis e suas características

lshal

Precisa ter HAL instalado (Hardware Abstraction Layer)
Lista todos os hardware visíveis pelo HAL

lshw

Disponível nas distribuições baseadas no Debian.
Usa entradas para detectar todo hardware: Kernel, HAL, DMI, etc.
‘-html’ gera relatórios

lspci

Comando padrão
Lista todo hardware que o kernel consegue detectar que esteja conectado a PCI

lsusb

Comando padrão
Lista todo hardware conectado às portas USB detectadas pelo kernel.

dmidecode

Comando padrão
Lista todo hardware reportador por interfaces DMI.

#Bibliotecas

  • ldd [executável] Lista as depedências de bibliotecas do sistema do [executável].

  • ld.so é o executável que garante os links dinâmicos do sistema;

  • LD_LIBRARY_PATH diretórios padrão para procurar as bibliotecas;

  • /etc/ld.so.cache cache de bibliotecas

  • /etc/ld.so.conf adicionar novas entradas ao cache

  • ldconfig comando para atualizar e recarregar o arquivo /etc/ld.so.cache

  • ldconfig -p lista todas as bibiotecas contidas no cache

#Lista todos os pacotes instalados (apt)

dpkg --get-selections | grep -v deinstall | awk '{ print $1 }'

It depends on what you want to do with the script (or any other program you want to run).

If you just want to run the script system is the easiest thing to do, but it does some other stuff too, including running a shell and having it run the command (/bin/sh under most *nix).

If you want to either feed the shell script via its standard input or consume its standard output you can use popen (and pclose) to set up a pipe. This also uses the shell (/bin/sh under most *nix) to run the command.

Both of these are library functions that do a lot under the hood, but if they don't meet your needs (or you just want to experiment and learn) you can also use system calls directly. This also allows you do avoid having the shell (/bin/sh) run your command for you.

The system calls of interest are fork, execve, and waitpid. You may want to use one of the library wrappers around execve (type man 3 exec for a list of them). You may also want to use one of the other wait functions (man 2 wait has them all). Additionally you may be interested in the system calls clone and vfork which are related to fork.

fork duplicates the current program, where the only main difference is that the new process gets 0 returned from the call to fork. The parent process gets the new process's process id (or an error) returned.

execve replaces the current program with a new program (keeping the same process id).

waitpid is used by a parent process to wait on a particular child process to finish.

Having the fork and execve steps separate allows programs to do some setup for the new process before it is created (without messing up itself). These include changing standard input, output, and stderr to be different files than the parent process used, changing the user or group of the process, closing files that the child won't need, changing the session, or changing the environmental variables.

You may also be interested in the pipe and dup2 system calls. pipe creates a pipe (with both an input and an output file descriptor). dup2 duplicates a file descriptor as a specific file descriptor (dup is similar but duplicates a file descriptor to the lowest available file descriptor).

Capturando imagem pela webcam

fswebcam -r 640x480 --jpeg 85 -D 1 teste.jpg 

Pegar o ESSID da rede (nome de rede)

iwgetid -r

Só pra você lembrar de um dia ver a libxdo

Dá pra fazer altas trakinagens...

Ativar a sintaxe inteligente do vim

Dependendo do pacote vim que é instalado, a sintaxe não é ativada sempre, por padrão. Para fazer isso, vá no arquivo ~/.vimrc colocar a seguinte linha:

syntax on

Realça um padrão em um arquivo

grep --color -E 'padrao|$' arquivo.txt

Lista todos os pacotes instalados no gerenciador APT

dpkg --get-selections | grep -v deinstall

Mostrar processos, como na ordem PID e nome do comando

ps axco pid,command

Contar recursivamente .h .cpp do diretório

{ find . -name "*.h" ;  find . -name "*" | grep ".cpp"; }| xargs  wc -l

Milissegundos no c/c++@Linux

#include <sys/time.h>
#include <iostream>
#include <unistd.h>

using namespace std;


int main()
{
    struct timeval start, end;

    long mtime, seconds, useconds;    

    gettimeofday(&start, NULL);
    sleep(2);
    gettimeofday(&end, NULL);

    seconds  = end.tv_sec  - start.tv_sec;
    useconds = end.tv_usec - start.tv_usec;

    mtime = ((seconds) * 1000 + useconds/1000.0) + 0.5;

    cout << "Elapsed time: " <<  mtime << " milliseconds" << endl;

    return 0;
}

Enviar dados para o clipboard

(Mesma coisa que o ctrl+c)

echo "oi" | xclip -selection clipboard

xclip -selection clipboard < arquivo.txt

Ler arquivo linha por linha no shell

while read line           
do           
    echo -e "$line\ n"           
done < file.txt

Desliga o monitor

xset dpms force off

Nome da rede conectado

nmcli dev wifi|grep yes| cut -d\' -f2

Dump de arquivo em Hexadecimal

xxd file

Dump de arquivo em Octal

od file

Criar um live usb debian

 dd if=<file.iso> of=<device> bs=4M ; sync
  • Onde:

<file.iso>: é a imagem do cd;

<device>: é o dispositivo (geralmente /dev/sdx onde x pode ser b, c ....;

bs=4M: cópia por blocos de 4M, para uma melhor performance;

sync: O comando sync garante que o disco será escrito;

Instalar a biblioteca de desenvolvedor do sqlite

sudo apt-get install libsqlite3-dev
  • Daí Pra compilar é só colocar o link
-lsqlite3

Iniciar o servidor X

startx

Escrever na entrada padrão de um processo com o PID=28689

echo "oi" >> /proc/28689/fd

Fazer um "cat" do arquivo com a saída em hexadecimal

xxd -p file

Implementações dos drives de entrada do linux

https://www.kernel.org/doc/Documentation/input/

PS.: Dá pra fazer coisas do tipo para ver as entradas:

cat /deb/input/mouse0

Ferramenta de utilidades de comunicação com o servidor X

`

xdotool

Altera a posição do mouse por linha de comando:

xdotool mousemove x y
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment