Skip to content

Instantly share code, notes, and snippets.

@zmf
zmf / gist:077de84b1516996fd7b79e952ee21992
Created October 27, 2020 00:41
WordPress: delete attachments without author
function delete_attachments_without_author()
{
foreach (get_posts(['post_type' => 'attachment', 'posts_per_page' => -1]) as $att) {
if (!$att->post_author) {
wp_delete_post($att->ID, true);
}
}
}
@zmf
zmf / vertical_to_horizontal_array.php
Created December 26, 2019 14:54
vertical_to_horizontal_array.php
<?php
$flat = [ 'this', 'seems', 'a', 'bit', 'strange'];
$nested = [];
function v2h_array(&$flat, &$nested) {
$nested[$flat[0]] = [];
while (count($flat) > 1) {
v2h_array(array_splice($flat, 1, count($flat)-1), $nested[$flat[0]]);
}
@zmf
zmf / gitlab_pipeline_status.go
Created November 24, 2017 09:42
small Go program to get last status of gitlab CI pipeline
package main
import (
"encoding/json"
"flag"
"fmt"
"io/ioutil"
"log"
"net/http"
"net/url"
@zmf
zmf / git_specific_file_commit_id_restore
Created June 7, 2017 15:08
Restore specific file(s) from specific git commit
git checkout c5f567 -- file1/to/restore file2/to/restore
<?php
// sort 'inventory' array by 2nd level value 'price'
$price = array();
foreach ($inventory as $key => $row)
{
$price[$key] = $row['price'];
}
array_multisort($price, SORT_DESC, $inventory);
@zmf
zmf / object_walk_as_assoc_array.js
Created March 10, 2017 11:56
walk through a JS object as it was an assoc array
for (var key in obj) {
if (obj.hasOwnProperty(key)) {
console.log(key + " -> " + obj[key]);
}
}
@zmf
zmf / top_extensions
Last active March 9, 2017 22:56
find top used extension inside a directory (recursively)
find ./ -type f | grep -E ".*\.[a-zA-Z0-9]*$" | sed -e 's/.*\(\.[a-zA-Z0-9]*\)$/\1/' | sort | uniq -c | sort -rn
@zmf
zmf / s3-pitr.py
Created November 10, 2014 23:07
Point in time restores from S3 versioned bucket
#!/usr/bin/python
import os
import sys
import getopt
import boto
from datetime import datetime
from dateutil.tz import tzoffset
from dateutil.parser import parse as parse_date
from time import strftime