Skip to content

Instantly share code, notes, and snippets.

View kopiro's full-sized avatar

Flavio Maria De Stefano kopiro

View GitHub Profile
@kopiro
kopiro / wp-remove-comments.php
Created January 13, 2018 15:52
Remove comments in WP
<?php
add_action('wp_loaded', function() {
remove_post_type_support('posts', 'comments');
remove_post_type_support('posts', 'trackbacks');
add_filter('comments_array', function() { return []; }, 20, 2 );
add_filter('comments_open', function() { return false; }, 20, 2 );
add_filter('pings_open', function() { return false; }, 20, 2 );
if (is_admin()) {
add_action('admin_menu', function() {
@kopiro
kopiro / docker-compose-example.yml
Last active January 13, 2018 11:31
Docker proxy with NGINX companion + LE
version: '3'
networks:
proxy:
external:
true
services:
app:
image: [IMAGE]
@kopiro
kopiro / filter-wp-uploads.php
Created January 10, 2018 19:19
Filter wordpress uploads
<?php
add_filter('wp_get_attachment_url', function($url) {
if (getenv('USE_S3_UPLOADS')) {
$url = 'https://' . getenv('AWS_S3_BUCKET') . '.s3.amazonaws.com' . str_replace(WP_CONTENT_URL, '', $url);
}
return $url;
});
add_filter('wp_calculate_image_srcset', function($sources) {
@kopiro
kopiro / wp_handle_upload.php
Last active February 13, 2020 21:23
Resize on the fly Worpdress uploads
<?php
/*
By default, wordpress create thumbnails of uploaded media, but doesn't resize the original one.
With this simple hook, original image (only jpg allowed) will be resized and compressed
*/
add_action('wp_handle_upload', function($data) {
$max_width = 1800;
$max_height = 1800;
@kopiro
kopiro / resize-wp-uploads.sh
Last active February 23, 2018 20:37
Resize WP uploads in batch
#!/bin/bash
images=$(find uploads -type f | egrep -v "\-[0-9]+x[0-9]+\." | egrep "\.(jpg|png)")
for f in $images; do
echo $f
convert "$f" -strip -quality 86 -resize "1800x1800^>" "$f"
done
@kopiro
kopiro / parse-headers.php
Last active April 24, 2020 18:27
Parse headers in PHP
<?php
$headers = [];
foreach (explode("\r\n", substr($response, 0, strpos($response, "\r\n\r\n"))) as $i => $line) {
if ($i === 0) continue;
list ($key, $value) = explode(': ', $line);
$headers[$key] = $value;
}
@kopiro
kopiro / tor_exit_nodes.md
Last active October 20, 2022 13:30
ProTip: Specify country exit nodes

With TOR, you can specify the country of exit nodes to test a particular website from a specific country.

Just add these 4 lines in the torrc file.

ExitNodes {jp}
StrictNodes 1
GeoIPExcludeUnknown 1
AllowSingleHopCircuits 0
@kopiro
kopiro / install-docker.sh
Last active April 23, 2018 15:49
Install Docker + Docker-compose on Ubuntu
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
sudo apt-get update
apt-cache policy docker-ce
sudo apt-get install -y docker-ce
sudo curl -o /usr/local/bin/docker-compose -L "https://github.com/docker/compose/releases/download/1.11.2/docker-compose-$(uname -s)-$(uname -m)"
sudo chmod +x /usr/local/bin/docker-compose
@kopiro
kopiro / sslrenewal
Last active December 13, 2017 16:03
SSL Renewal with LE using same CSR
#!/bin/bash
CONTAINER="/var/www/html"
DOMAIN="kopiro.it"
PUBLIC_DIR="$CONTAINER/public"
BACKUP_DIR="$CONTAINER/conf/backup/$(date +%s)"
mkdir -p "$BACKUP_DIR"
cp -v $CONTAINER/conf/*.pem "$BACKUP_DIR/"
@kopiro
kopiro / keybase-proof
Created April 4, 2017 13:30
Keybase Proof
### Keybase proof
I hereby claim:
* I am kopiro on github.
* I am kopiro (https://keybase.io/kopiro) on keybase.
* I have a public key whose fingerprint is 3579 CA25 0F27 FED2 BF3F D0DF EDE5 1005 D982 268E
To claim this, I am signing this object: