Skip to content

Instantly share code, notes, and snippets.

View mcunha98's full-sized avatar
🏠
Working from home

Mauricio Cunha mcunha98

🏠
Working from home
View GitHub Profile
#Count the access_log , group by ip and hits, sort by desc and cut to 50 top results
CC='\033[1;33m'
NC='\033[0m'
printf "Lista dos top ${CC}50${NC} enderecos IP e visitas na data de hoje\n"
echo "Baseado no arquivo /var/log/httpd/access.log"
cat /var/log/httpd/access.log | awk '{print $1}' | sort -t":" -k2,2 | uniq -c | sort -fr | head -n50
//generate a random string and return the substring of N chars at the end
var rnd = "ABCDEF23456789".split('').sort(function(){return 0.5-Math.random()}).join('').substring(0, 6);
//OUTPUT:
//BC3A095
//C3FA295
function xml2array($xmlstring)
{
$xml = simplexml_load_string($xmlstring);
$json = json_encode($xml);
return json_decode($json,TRUE);
}
function array2Xml($array, $rootElement = null, $xml = null)
{
$_xml = $xml;
1) Save into /usr/local/wtf_top.sh
#!/bin/sh
ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem | head -n20
2) Call into a cmdrunner wtfutil config
proccess:
title: Processos
type: cmdrunner
function hasLetterAndNumber($value)
{
$hasLetters = preg_match('/[a-zA-Z]/',$value);
$hasNumbers = preg_match('/\d/',$value);
return $hasLetters && $hasNumbers;
}
<!DOCTYPE html>
<html>
<body>
<?php
for ($i = 1; $i <= 10; $i++)
{
echo guid() . "<br>";
}
function guid()
grep -rl $'\xEF\xBB\xBF' /srv/httpd/suapasta > /tmp/files_with_boms.txt
while read l; do sed -i '1 s/^\xef\xbb\xbf//' $l; done < /tmp/files_with_boms.txt