Skip to content

Instantly share code, notes, and snippets.

View maietta's full-sized avatar

Nick Maietta maietta

View GitHub Profile
@maietta
maietta / liquidsoap.sh
Created July 17, 2017 20:51
LiquidSoap startup script debian/ubuntu flavors
root@bf1:/etc/init.d# cat liquidsoap
#!/bin/sh
### BEGIN INIT INFO
# Provides: liquidsoap
# Required-Start: $remote_fs $network $time
# Required-Stop: $remote_fs $network $time
# Should-Start:
# Should-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
@maietta
maietta / gist:1cd552cba5797c83548691282007aabb
Created December 10, 2017 22:26
Installing Docker CE on Ubuntu Zesty
sudo echo "deb https://download.docker.com/linux/ubuntu zesty edge" > /etc/apt/sources.list.d/docker.list
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 7EA0A9C3F273FCD8
sudo apt update && sudo apt install docker-ce
@maietta
maietta / gist:d54e4b6b05e19dd04d599246bd02feb8
Created December 10, 2017 22:41
Ubuntu/Debian Distros - Remove Old Kernels
sudo apt install -y byobu
sudo purge-old-kernels -y --keep 1
sudo apt-get -y autoremove --purge
public function splice($html, $new, $tag) {
$html = $this->getInstanceOfDom($html);
$element = $html->getElementById($tag);
$doc = new DOMDocument();
$doc->loadHTML('<?xml encoding="UTF-8">' . $new);
foreach ($doc->childNodes as $node) {
if ($node->nodeType == XML_PI_NODE) { $doc->removeChild($node); }
}
$xpath = new DOMXPath($doc);
$body = $xpath->query('/html/body');
@maietta
maietta / merge_arrays.txt
Created November 21, 2018 19:54
PHP: Merge two multidimensional object arrays
$combined = combine2ArraysByKey($featured_properties, $property_records, "L_ListingID");
function combine2ArraysByKey($first, $second, $key) {
$combined = [];
$first = (array) array_column($first, NULL, $key);
$second = (array) array_column($second, NULL, $key);
foreach($first as $key=>$items) {
if ( !empty($second[$key]) ) $combined[$key] = array_merge((array) $items, (array) $second[$key]);
}
return $combined;
@maietta
maietta / example.php
Created November 22, 2018 19:08
PHP: Return array of starting positions of all needles in a haystack
<?php
error_reporting(E_ALL);
$haystack = "An apple a day";
$needles = array("An", "da", "pp");
$array_of_starting_positions = findAnyNeedles($haystack, $needles, false); // This returns string by default.
header("Content-type: text/plain");
@maietta
maietta / command.txt
Last active April 22, 2019 14:49
PowerDNS on Ubuntu 18.04+
sudo systemctl disable systemd-resolved
sudo systemctl stop systemd-resolved
sudo ls -lh /etc/resolv.conf
sudo rm /etc/resolv.conf
sudo echo "nameserver 1.1.1.1" > /etc/resolv.conf
sudo apt-get update
sudo apt-get install pdns-server pdns-backend-mysql
@maietta
maietta / gist:6ba0cfd322f40c67536950a499ea9e84
Created January 25, 2019 16:44
PHRETS 2.x: Easy way to identify methods available for any object.
$objects = $rets->Search('Property', 'RE_1', '(L_ListingID=1800394)');
$test = get_class_methods($objects);
print_r($test);
// GIVES:
/*
Array
@maietta
maietta / gist:70b746c9497364a63b9bfbe36ec74f37
Last active January 28, 2019 07:10
PHP DOM. Find element, get parent, then find sibblings. Build JSON
<?php
$raw_content = file_get_contents("NBA_example.txt");
$dom = new DOMDocument;
$dom->loadHTML("$raw_content");
$block = $dom->getElementById("oddsGridContainer");
$results = [];
$assets = $block->getElementsByTagName('script');
{
"require": {
"troydavisson/phrets": "2.*"
}
}