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
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
<!DOCTYPE html>
<html>
<body>
<?php
for ($i = 1; $i <= 10; $i++)
{
echo guid() . "<br>";
}
function guid()
function hasLetterAndNumber($value)
{
$hasLetters = preg_match('/[a-zA-Z]/',$value);
$hasNumbers = preg_match('/\d/',$value);
return $hasLetters && $hasNumbers;
}
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 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;
//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
#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
[abc] A single character: a, b or c
[^abc] Any single character but a, b, or c
[a-z] Any single character in the range a-z
[a-zA-Z] Any single character in the range a-z or A-Z
^ Start of line
$ End of line
\A Start of string
\z End of string
. Any single character
\s Any whitespace character
//Examples :
placeholder.php?size=200x100&bg=eee&fg=000&text=Hello
placeholder.php?size=200x100&bg=eee&fg=000
placeholder.php?size=200x100
<?php
$getsize = isset($_GET['size']) ? $_GET['size'] : '100x100';
$dimensions = explode('x', $getsize);
$image = imagecreate($dimensions[0], $dimensions[1]);
@mcunha98
mcunha98 / php auto check enumerations
Created December 30, 2020 12:52
Check if current class has constant/enumeration based on value
class Assets
{
const ASSETS_BANNER = 'banner';
const ASSETS_BLOG = 'blog';
const ASSETS_TEMPLATE = 'template';
private static $constants;
public static function isConstant($value)
{