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 / 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 / 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;
<?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
#!/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
// 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);
@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