Skip to content

Instantly share code, notes, and snippets.

@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:
@kopiro
kopiro / wait_childs.sh
Created March 22, 2017 15:26
Wait child (fork) to exit
#!/bin/bash
trap 'kill $(jobs -p)' EXIT
mkdir -p build-web/scripts
watchify web/scripts/main.jsx -o build-web/scripts/main.js -t [ babelify ] &
watchify web/scripts/memories.jsx -o build-web/scripts/memories.js -t [ babelify ] &
wait
@kopiro
kopiro / three.doc.js
Created March 21, 2017 16:12
ThreeJS DeviceOrientationControls
/**
* @author richt / http://richt.me
* @author WestLangley / http://github.com/WestLangley
*
* W3C Device Orientation control (http://w3c.github.io/deviceorientation/spec-source-orientation.html)
*/
THREE.DeviceOrientationControls = function( object ) {
var scope = this;
@kopiro
kopiro / agent.sh
Last active February 26, 2017 11:29
S3 Backup in Bash
#!/bin/sh
# 0 2 1 * * /root/agent.sh
TIME=`date +%Y-%m-%d`
mkdir -p "/tmp/backup"
tar -cpzf "/tmp/backup/uploads.tar.gz" /var/www/uploads
tar -cpzf "/tmp/backup/other.tar.gz" /var/www/other
@kopiro
kopiro / raii_class.cc
Created January 18, 2017 14:20
Test RAII Class
#include <iostream>
class Two {
public:
void test() { std::cout << "Hello"; }
};
class TwoRAII {
public:
Two* two;