Skip to content

Instantly share code, notes, and snippets.

View humbertocastelo's full-sized avatar
🍓

Humberto Castelo Branco humbertocastelo

🍓
View GitHub Profile
def get_socket_socks5(proxy_host, proxy_port, proxy_username, proxy_password, host, port):
sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
sock.connect((proxy_host,proxy_port))
fd = sock.makefile()
sock.send("\x05\x01\x02")
server_status = sock.recv(8192)
if server_status != "\x05\x02":
return False
sock.send(struct.pack('B', 0x01) + struct.pack('B', len(proxy_username)) + proxy_username + struct.pack('B', len(proxy_password)) + proxy_password)
server_buffer = sock.recv(8192)
<?php
error_reporting( E_ALL );
ini_set( 'display_errors', true );
if ( !headers_sent() ) {
header( 'X-Accel-Buffering: no' );
}
function is_apache2() {
@humbertocastelo
humbertocastelo / wp_editor_set_quality_and_jpeg_quality.php
Last active October 13, 2017 16:47
wp_editor_set_quality and jpeg_quality
<?php
function my_prefix_wp_editor_set_quality( $quality, $mime_type ) {
if ( $mime_type === 'image/jpeg' ) {
$quality = 90;
} elseif ( $mime_type === 'image/png' ) {
$quality = 91;
} elseif ( $mime_type === 'image/gif' ) {
$quality = 92;
} else {
@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 );
?>
@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 / 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 / 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 / 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 / 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 / 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 );