Skip to content

Instantly share code, notes, and snippets.

View deviationist's full-sized avatar

Robert S. deviationist

  • Oslo-area, Norway
View GitHub Profile
@deviationist
deviationist / audio-reduce-sample-rate.sh
Last active November 20, 2021 02:23
FFMPEG reduce audio sample rate (AIFF, WAV)
#!/bin/bash
toConvertFolder="to-convert/"
convertedFolder="converted/"
maxKhz=48000
mkdir -p $convertedFolder
formats=( "aiff" "wav" )
for i in "${formats[@]}"
@deviationist
deviationist / audio-convert.sh
Last active November 20, 2021 02:24
FFMPEG audio convert script (FLAC ➜ AIFF, WAV ➜ AIFF, M4A ➜ MP3)
#!/bin/bash
toConvertFolder="to-convert/"
convertedFolder="converted/"
mkdir -p $convertedFolder
# FLAC to AIFF
find $toConvertFolder -type f -name "*.flac" | while read line; do
newFilename="${line/%.flac/.aiff}"
@deviationist
deviationist / WordPress.org Plugin Repository - delete tag from SVN
Last active April 29, 2021 09:37
A quick and easy way to delete a tag from a WP plugin using CLI.
svn delete http://plugins.svn.wordpress.org/plugin-slug/tags/1.0.0/ -m "Revert" --username your-username
#!/bin/bash
find . -type f -name "*.flac" | while read line; do
newFilename="${line/%flac/aiff}"
ffmpeg -y -nostdin -i "${line}" -write_id3v2 1 -c:v copy "${newFilename}"
rm "${line}"
done
@deviationist
deviationist / Ghost Inspector - checkbox state checker v2
Last active September 24, 2020 00:46
A neat JS function that you can use with Ghost Inspector to check if a checkbox/radio button is checked, and it also gives a visual feedback (like the native ones from other checks)
function GI_itemHaveCheckedState(element, state, delay) {
var valid = element.checked === state;
if ( valid ) {
if ( ! delay ) delay = 0;
setTimeout(function() {
element.style.outline = '5px solid rgba(98, 191, 103, 1)';
setTimeout(function() {
element.style.outline = 'initial';
}, 500);
}, delay);
@deviationist
deviationist / .htaccess
Last active July 3, 2020 09:47
Prevent access to WP Admin and wp-login.php via .htaccess, but allow access to admin-ajax.php
# Prevent WP Admin from being accessed (except admin-ajax.php)
#RewriteCond %{HTTP_HOST} ^(|www\.)yourdomain\.(com|net|org)$ [NC] # This line is optional, but useful if you only want to apply the rules to certain domains
RewriteCond %{REQUEST_URI} ^/wp-admin/ [NC]
RewriteCond %{REQUEST_URI} !^/wp-admin/admin-ajax\.php$ [NC]
RewriteRule (.*) %{REQUEST_SCHEME}://%{HTTP_HOST}/ [L,R=301]
# Prevent the WP login form from being accessed
#RewriteCond %{HTTP_HOST} ^(|www\.)yourdomain\.(com|net|org)$ [NC] # This line is optional, but useful if you only want to apply the rules to certain domains
RewriteCond %{REQUEST_URI} ^/wp-login\.php$ [NC]
RewriteRule (.*) %{REQUEST_SCHEME}://%{HTTP_HOST}/ [L,R=301]
@deviationist
deviationist / laravel-check-if-item-is-already-added-to-the-queue.php
Last active April 29, 2020 17:26
This function will help you determine whether an item is already added to the queue or not. Note: only works when using the database queue driver.
<?php
/*
Example usage:
// The payload of the job
$userQueueItem = [
'id' => 5,
'username' => 'user',
'email' => '[email protected]',
@deviationist
deviationist / wp-image-size-debug.php
Last active April 30, 2020 12:06
A page template to debug the image sizes on WordPress. It will display images in the media library in all sizes with additional dimension and ratio information.
<?php
/**
* Template Name: Image test
*
* Requires PHP version 7 >=.
*
* Available GET parameters:
*
* ?posts_per_page=5
* ?order=ASC
@deviationist
deviationist / exctract-wordpress-image-size-from-url.php
Last active April 22, 2020 13:15
Extract the dimension from an uploaded image URL in WordPress. Only works for images with the image size in the filename.
/**
* Extract the width and height from the URL of a resized image file in Wordpress.
*
* @param $url
*
* @return array|bool
*/
function exctract_wordpress_image_size_from_url($url) {
preg_match('/-(?P<width>[0-9]+)x(?P<height>[0-9]+).(.+)$/', $url, $matches);
if ( array_key_exists('width', $matches) && array_key_exists('width', $matches) ) {
@deviationist
deviationist / get-domain-with-ccsld.php
Created April 18, 2020 23:24
Get a domain without its subdomain (taking ccSLD into consideration)
<?php
// composer require jeremykendall/php-domain-parser
require_once __DIR__ . '/vendor/autoload.php';
$manager = new Pdp\Manager(new Pdp\Cache(), new Pdp\CurlHttpClient());
$domain = $manager->getRules()->resolve('this.is.a.very.long.domain.co.uk');
var_dump($domain->getRegistrableDomain());