Skip to content

Instantly share code, notes, and snippets.

@pfrozi
pfrozi / truncate_all.sh
Created March 18, 2024 21:24
Get all the host's containers and show the log size of each one. Then truncate the log when the user presses any key.
#!/bin/bash
container_ids=$(docker ps -aq)
for id in $container_ids; do
log_size=$(docker inspect --format='{{.LogPath}}' $id | xargs du -sh | awk '{print $1}')
name=$(docker inspect --format='{{.Name}}' $id | sed 's/\///')
echo "Container ID: $id"
@pfrozi
pfrozi / killall.sh
Created February 16, 2024 18:56
Kill all processes with specific name
#!/bin/sh
# Call: killall forti
#
# Kill all process that contains the arg1 text
for p in `pgrep ${$1}`;
do echo "PID forti: ${p} Killing..." && kill $p && echo "${p} killed\!" ;
done
SELECT
DB_NAME() AS DatbaseName
, SCHEMA_NAME(o.Schema_ID) AS SchemaName
, OBJECT_NAME(s.[object_id]) AS TableName
, i.name AS IndexName
, ROUND(avg_fragmentation_in_percent,2) AS [Fragmentation %]
FROM sys.dm_db_index_physical_stats(db_id(),null, null, null, null) s
INNER JOIN sys.indexes i ON s.[object_id] = i.[object_id]
AND s.index_id = i.index_id
INNER JOIN sys.objects o ON i.object_id = O.object_id
@pfrozi
pfrozi / ssltest.sh
Last active October 27, 2023 19:59
ssltests
echo | openssl s_client -servername rubygems.org -connect rubygems.org:443 2>/dev/null | openssl x509 -text -noout
echo | openssl s_client -servername rubygems.org -connect rubygems.org:443 2>/dev/null | openssl verify -CApath /etc/ssl/certs/
@pfrozi
pfrozi / converter-pdf2jpg.sh
Created July 13, 2023 12:13
PDF to JPG converter via Ghostscript
#!/bin/bash
if command -v gs >/dev/null 2>&1 ; then
echo "gs found"
else
echo "GPL Ghostscript not found"
fi
out_pages=$(echo $1 | sed -e "s/\.pdf$/-p%02d\.jpg/g")
out_files=$(echo $1 | sed -e "s/\.pdf$/-p*\.jpg/g")
@pfrozi
pfrozi / opelssl.cnf
Created November 1, 2021 18:37
How to configure a openssl.cnf
#
# OpenSSL example configuration file.
# This is mostly being used for generation of certificate requests.
#
openssl_conf = default_conf
####################################################################
[ default_conf ]
@pfrozi
pfrozi / test.sh
Created October 20, 2021 20:12
FortiClient on ubuntu
# Add fortisslvpn repository
sudo add-apt-repository ppa:ar-lex/fortisslvpn
sudo apt-get update
sudo apt-get install
# Calling
openfortivpn vpn.xxxxxx.com.br:10443 -u pedro.xyz -p ****** --trusted-cert xyz
@pfrozi
pfrozi / locks.sql
Last active March 18, 2024 21:26
Get all sessions with some statistics on sqlsever
USE master
go
SELECT
sdes.session_id
,sdes.login_time
,sdes.last_request_start_time
,sdes.last_request_end_time
,sdes.is_user_process
,sdes.host_name
,sdes.program_name
@pfrozi
pfrozi / testregex.cs
Created June 23, 2021 17:44
Regex to test repeated character in C#
using System;
using System.Text.RegularExpressions;
public class Program
{
public static void Main()
{
var hasRepeatedCharacter = new Regex(@"^([0-9]+)\1$");
string text = "123123";
@pfrozi
pfrozi / TestFlags.cs
Created June 22, 2021 16:37
Flags example
using System;
public class Program
{
public static void Main()
{
var e = Teste.Cliente | Teste.Documentos;
Console.WriteLine(e.HasFlag(Teste.Cliente));
Console.WriteLine(e.HasFlag(Teste.Liberacoes));
Console.WriteLine(e.HasFlag(Teste.Documentos));