Skip to content

Instantly share code, notes, and snippets.

View humbertocastelo's full-sized avatar
🍓

Humberto Castelo Branco humbertocastelo

🍓
View GitHub Profile
sudo chmod 0755 /var/www
sudo chmod 0755 /var/www/html
sudo chmod 0640 /var/www/html/wp-config.php
sudo chown -R www-data:www-data /var/www/html
sudo find /var/www/html -type d -exec chmod 0755 {} \;
sudo find /var/www/html -type f -exec chmod 0644 {} \;
sudo find /var/www/html/wp-content/plugins -type f -name "*" -not -name "*.o" -exec sh -c '
case "$(head -n 1 "$1")" in
?ELF*) exit 0;;
MZ*) exit 0;;
@humbertocastelo
humbertocastelo / wp-add-concatenate-scripts.sh
Last active February 9, 2018 00:54
WP Add CONCATENATE_SCRIPTS
#!/bin/bash
files=()
for home in /home/*; do
if [[ -d "${home}/public_html" ]]; then
if [[ -f "${home}/public_html/wp-config.php" ]]; then
files+=("${home}/public_html/wp-config.php")
fi
for folder in ${home}/public_html/*; do
@humbertocastelo
humbertocastelo / install.sh
Created January 25, 2018 22:55
Stamping text on all PDF pages
#!/bin/bash
sudo apt-get install -y xvfb
sudo apt-get install -y wkhtmltopdf
sudo apt-get install -y pdftk
@humbertocastelo
humbertocastelo / replace-scripts-with-src.php
Created January 7, 2018 05:37
Replace Scripts With SRC
<?php
function replace_scripts_with_src( $html ) {
$html = preg_replace( '`\<script\b[^\x3e]*\bsrc\b[\x00-\x20\x7f]*\=[\x00-\x20\x7f]*(?:[\x22](?:[^\x22]*)[\x22]|[\x27](?:[^\x27]*)[\x27]|[^\x20\x3e]*)[^\x3c]*(?:(?!\<\/script\>)\<[^\x3c]*)*\<\/script\>`i', '', $html );
return $html;
}
$old_html = file_get_contents( 'https://www.facebook.com' );
$new_html = replace_scripts_with_src( $old_html );
@humbertocastelo
humbertocastelo / remove-scripts-with-src.php
Created January 7, 2018 05:13
Remove Scripts With SRC
<?php
function remove_scripts_with_src( $html ) {
$use_errors = libxml_use_internal_errors( true );
$dom = new \DOMDocument();
$dom->loadHTML( $html );
$scripts = $dom->getElementsByTagName( 'script' );
for ( $i = $scripts->length - 1; $i >= 0; $i-- ) {
if ( !( $item = $scripts->item( $i ) ) ) {
continue;
@humbertocastelo
humbertocastelo / count-chars-delimiter.php
Created November 12, 2017 17:53
Count Chars Delimiter
<?php
function count_chars_delimiter( string $str, string $delimiter = ',' ) {
$arr = [];
foreach ( array_filter( array_map( 'trim', explode( $delimiter, $str ) ), function( $v ) { return ( $v !== '' ); } ) as $value ) {
$arr[$value] = isset( $arr[$value] ) ? $arr[$value] : 0;
$arr[$value]++;
}
return $arr;
}
@humbertocastelo
humbertocastelo / apache_htaccess_php_value_memory_limit.txt
Created October 29, 2017 13:11
Apache .htaccess php_value memory_limit
<IfModule mod_php5.c>
php_value memory_limit 512M
</IfModule>
<IfModule mod_php7.c>
php_value memory_limit 512M
</IfModule>
@humbertocastelo
humbertocastelo / ipadd.php
Created October 26, 2017 04:53
ipadd = ip2long + long2ip
<?php
function ipadd( $ip, $add ) {
if ( ( $long = ip2long( $ip ) ) === false ) {
return false;
}
return long2ip( $long + $add );
}
$old_ip = '198.162.0.2';
@humbertocastelo
humbertocastelo / hasTouchEventJqueryTouchSwipe.html
Created October 19, 2017 00:42
hasTouchEvent jQuery TouchSwipe
<script type="text/javascript">
function hasTouchEvent() {
try {
document.createEvent("TouchEvent");
return true;
} catch(e) {
return false;
}
}
if (hasTouchEvent()) {
@humbertocastelo
humbertocastelo / jpeg_quality_90.php
Created October 14, 2017 03:55
jpeg_quality 90
<?php
function my_prefix_jpeg_quality( $quality, $context ) {
return 90;
}
add_filter( 'jpeg_quality', 'my_prefix_jpeg_quality', 10, 2 );
?>