Skip to content

Instantly share code, notes, and snippets.

@djsipe
djsipe / set-ssh-key.sh
Last active October 31, 2019 16:44
Automat SSH Key Configuration on Remote Host
#!/bin/bash
echo This script will attempt to set your public SSH key on the server you designate.
Host=$1
KeyFile=`eval echo "~$USER"`"/.ssh/id_rsa.pub"
KeyFile=${2:-$KeyFile}
# Attempt to ssh without a password
ssh -o BatchMode=yes $Host true 2> /dev/null
@djsipe
djsipe / SPL Exceptions.md
Created December 5, 2017 15:06
Consolidation of PHP manual for SPL Exceptions

SPL provides a set of standard Exceptions.

Class Meaning / Use
\BadFunctionCallException Exception thrown if a callback refers to an undefined function or if some arguments are missing.
\BadMethodCallException Exception thrown if a callback refers to an undefined method or if some arguments are missing.
\DomainException Exception thrown if a value does not adhere to a defined valid data domain.
\InvalidArgumentException Exception thrown if an argument is not of the expected type.
\LengthException Exception thrown if a length is invalid.
@djsipe
djsipe / serialize-to-xml.js
Last active October 27, 2017 16:43
Serialize a `Document` to a XML string.
/**
* Serialize a document to a string the hard way (using lodash)
* @param {Document} xml
* @return {String}
*/
function documentToXmlString(xml) {
var xmlString = "";
function serialize(xmlDoc) {
_.forEach(xmlDoc.childNodes, function (el) {
@djsipe
djsipe / detect_duplicates.sql
Created August 11, 2017 14:29
Detect duplicates in a SQL table.
-- SQL Server
IF EXISTS(
SELECT
row_identifier,
COUNT(*)
FROM table_to_check
GROUP BY row_identifier
HAVING COUNT(*) > 1
)
BEGIN
@djsipe
djsipe / Markdown.js
Created July 6, 2017 20:47
This script can be used to export a data table result from DataGrip (or other JetBrains IDEAs) as a basic Markdown table. Helpful for documentation.
/*
Markdown Table Export Script for DataGrip
-----------------------------------------
This simple script is a modified version of the HTML script that allows you to
output a table of data as a Markdown table. The output isn't pretty, but it
should be rendered correctly.
@author Donald Sipe
*/

Assuming you are using the official PHP Docker image...

# ---------------------------------------------------------------
# PHP Extension: Gearman
# Download Gearman PECL extension for Gearman supporting PHP 7
RUN apt-get -y --allow-unauthenticated install \
    libgearman-dev
RUN cd /tmp \
 && git clone https://github.com/wcgallego/pecl-gearman.git \

To convert you should run a regex find/replace.

Pattern:

[a-zA-Z]+\(([^\)]+)\)

Replace with:

@djsipe
djsipe / Check Installed Packages.md
Created June 27, 2017 14:50
Check installed packages in Ubuntu.

To List all Installed Packages

Here "less" is a simple text reader used to scroll through the list of packages in a new buffer that opens in the existing terminal window. The list will not be mixed with other terminal commands and output. Hit 'q' to return to terminal prompt. See "man less" for more info.

dpkg -l | less

To check whether a package is installed or not:

@djsipe
djsipe / TestProtectedTrait.php
Last active February 10, 2017 14:29
PHP Trait for Testing Protected Methods and Properties
<?php
/**
* Trait to expose protected methods and properties.
*/
trait TestProtectedTrait
{
/**
* Call protected/private method of a class.
*
* @param object|string $object Instantiated object that we will run method on or the class name.