Skip to content

Instantly share code, notes, and snippets.

@deviationist
deviationist / gist:281d371ca29dee774aa4
Last active August 29, 2015 14:16
Windows - Get motherboardinfo in command line
wmic baseboard get product,Manufacturer,version,serialnumber
wmic MemoryChip get BankLabel, Capacity, MemoryType, TypeDetail, Speed
wmic cpu get Name
wmic PATH Win32_videocontroller GET description
<?php
// Check if API request route contains a given segment
function route_contains($segment, $request) {
// Check if segment to check is array
if( ! is_array($segment) ) {
// If not create an array
$segment = array($segment);
#!/bin/bash
# Fire and forget
nohup ./shell.sh >/dev/null 2>&1 &
# Wait and suppress output
( ./shell.sh ) >/dev/null 2>&1
# Wait and return output
./shell.sh
<?php
/**
* Class NRK_Subtitle_Downloader
*
* This is a simple PHP script to help download subtitle files from NRK TV.
* The subtitle files are in VTT-format which is supported by Plex.
*
* Usage:
* php nrk-subtitle-downloader.php URL1,URL2,URL3 folder_path NOR
@deviationist
deviationist / levenshtein-ratio.sql
Last active February 17, 2020 16:57
Levenshtein MySQL-functions
CREATE FUNCTION `LEVENSHTEIN_RATIO`( s1 text, s2 text ) RETURNS int(11)
DETERMINISTIC
BEGIN
DECLARE s1_len, s2_len, max_len INT;
SET s1_len = LENGTH(s1), s2_len = LENGTH(s2);
IF s1_len > s2_len THEN
SET max_len = s1_len;
ELSE
SET max_len = s2_len;
END IF;
@deviationist
deviationist / multisite-post-type-index.class.php
Last active March 17, 2020 16:33
A class to index all post types on all blogs in a WordPress multi-site setup. This is helpful since function "get_post_types" does not respect multisite functions like "switch_to_blog" etc.
<?php
/**
* Class Multisite_Post_Type_Index
*
* This class creates and index of all the different post types on each blog in a multisite. As of now WordPress does not have a feature to list post types by blog, and hence this hacky but working solution.*
*/
class Multisite_Post_Type_Index {
/**
@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());
@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 / 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 / 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' => 'user@mail.com',