Skip to content

Instantly share code, notes, and snippets.

@kopiro
kopiro / Dockerfile OCI8
Created May 24, 2018 09:58
Dockerfile-oci8
FROM php:7.1-fpm
RUN set -ex && \
apt-get update && \
apt-get -y --no-install-recommends install \
apt-utils \
unzip \
nano \
git
@kopiro
kopiro / aws-say.js
Created April 24, 2018 14:14
Convert text to mp3 using AWS Polly
const aws = require('aws-sdk');
aws.config.loadFromPath('aws.json');
const locale = 'it-IT';
const fs = require('fs');
const pollyClient = new aws.Polly({
signatureVersion: 'v4',
region: 'eu-west-1'
@kopiro
kopiro / ImplicitGrantWithPostmessage.php
Created April 12, 2018 08:03
Implicit Grant with Postmessage for Laravel Passport
<?php
namespace App\Libraries\OAuth;
class ImplicitGrantWithPostmessage extends \League\OAuth2\Server\Grant\ImplicitGrant
{
public function completeAuthorizationRequest(\League\OAuth2\Server\RequestTypes\AuthorizationRequest $authorizationRequest) {
$response = parent::completeAuthorizationRequest($authorizationRequest);
$reflectionClassResponse = new \ReflectionClass($response);
@kopiro
kopiro / README.md
Last active September 29, 2024 13:42
Execute sudo commands asking password interactively via macOS security dialog only one time

sudoize.sh

Asks for admin privileges via macOS security dialog and writes in the /etc/sudoers file this string:

youruser ALL=(ALL) NOPASSWD:ALL

allowing you to execute next sudo commands without asking for password via terminal.

@kopiro
kopiro / monitor-alpine.sh
Last active March 18, 2021 12:12
Monitor directory change and execute a command
#!/bin/sh
while (true); do
inotifywait . -m -r -e create -e modify -e move -e delete
./execute-command.sh
done
@kopiro
kopiro / spotify-castv2-client-example.js
Last active November 27, 2020 11:31
Spotify CastV2 Client example
const Client = require('castv2-client').Client;
const Spotify = require('./Spotify');
const mdns = require('mdns');
const browser = mdns.createBrowser(mdns.tcp('googlecast'));
browser.on('serviceUp', function(service) {
console.log('found device "%s" at %s:%d', service.txtRecord.fn, service.addresses[0], service.port);
if (service.txtRecord.fn === process.env.SPOTFIY_DEVICE) {
ondeviceup(service.addresses[0], service.txtRecord.fn);
@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;