Skip to content

Instantly share code, notes, and snippets.

@sfinktah
sfinktah / upnp.sh
Created September 28, 2023 20:22
UPNP external IP query for Asterisk in BASH
#!/usr/bin/env bash
function wan_ip_connection() {
local host=$1
result=$( curl -s "http://$host/upnp/control?WANIPConnection" \
-H 'SOAPAction: "urn:schemas-upnp-org:service:WANIPConnection:1#GetExternalIPAddress"' \
--data-binary '<?xml version="1.0"?><s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:GetExternalI
PAddress xmlns:u="urn:schemas-upnp-org:service:WANIPConnection:1"></u:GetExternalIPAddress></s:Body></s:Envelope>'
)
REGEX='ExternalIPAddress>([0-9.]+)<'
@sfinktah
sfinktah / explode.sh
Last active September 20, 2023 16:36
string_between bash function
unset EXPLODED
declare -a EXPLODED
function explode
{
local c=$#
(( c < 2 )) &&
{
echo function "$0" is missing parameters
echo "$0 <delimiter> <string> <limit>"
echo "result is in EXPLODED"
@sfinktah
sfinktah / SingleInstanceLock.php
Last active September 20, 2023 11:22
single instance php lock
<?php
namespace Sfinktah\Locks;
class SingleInstanceLock {
private string $lockFile;
private int $pid;
public function __construct($scriptName = null) {
if (!$scriptName) {
@sfinktah
sfinktah / mysql-restore-tables.sh
Created September 14, 2023 04:17
modular mysql backup & restore
#!/usr/bin/env bash
## For speedy use:
## mysql-restore-tables *.schema.*
## parallel -j 8 mysql-restore-table *.data.*
# MySQL server credentials
DB_USER="your_username"
DB_PASS="your_password"
DB_HOST="localhost"
@sfinktah
sfinktah / build-php.sh
Created September 10, 2023 06:20
Building PHP 8.1 on Centos 8.5
sudo dnf install autoconf automake binutils bison curl-devel freetype-devel gcc \
gcc-c++ git glibc-devel libjpeg-devel libpng-devel libtool libwebp-devel \
libxml2-devel libzip-devel make openssl-devel sqlite-devel
sudo yum install re2c oniguruma-devel --enablerepo=powertools
git clone https://github.com/php/php-src.git --branch=PHP-8.1.23
cd php-src
./buildconf
make -j 4
@sfinktah
sfinktah / generate_html_tables.md
Created September 8, 2023 13:48
Generate HTML Tables

To allow for the creation of rows with horizontal bars in the HTML table, you can add another parameter to the generateHTMLTable function to specify which rows should have horizontal bars and then add CSS classes accordingly. Here's the modified function:

<?php
function generateHTMLTable($data, $tableClass = '', $headerRowClass = '', $dataRowClass = '', $barRowIndices = []) {
    if (empty($data)) {
        return ''; // Return an empty string if the data array is empty
    }

    $html = '<table';
@sfinktah
sfinktah / markmission.md
Last active July 24, 2024 13:55
OpenAI's idea of how to create a PWA for offline/online submission of form data

Creating a Progressive Web App (PWA) to store contact details from a form and submit them when internet access is available involves a combination of technologies like HTML, CSS, JavaScript, and service workers. Below is a simplified example of how you can achieve this:

  1. HTML Form: Create an HTML form to collect contact details. You can create an index.html file.
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
@sfinktah
sfinktah / autocomplete_sol2_lua.cpp
Created October 17, 2022 09:42
lua autocompletion for C++/sol3
#define SOL_ALL_SAFETIES_ON 1
#include <sol/sol.hpp>
#include <iostream>
#include <string>
#include <algorithm>
#include <pystring/pystring.h>
using namespace std::string_literals;
template <typename T>
bool is_in(const T& val, const std::initializer_list<T>& list) {
Sub RefStuff()
' https://docs.microsoft.com/en-us/office/vba/api/word.selection.insertcrossreference
myHeadings = _
ActiveDocument.GetCrossReferenceItems(wdRefTypeNumberedItem)
For i = 1 To UBound(myHeadings)
MsgBox InStr(1, LTrim(myHeadings(i)), "(a)", 1) & ":" & myHeadings(i)
If InStr(LCase$(myHeadings(i)), "3.xxxx") Then
With Selection
.Collapse Direction:=wdCollapseStart
.InsertAfter "paragraph "
#!/usr/bin/env bash
function wan_ip_connection() {
local host=$1
result=$( curl -s "http://$host/upnp/control?WANIPConnection" \
-H 'SOAPAction: "urn:schemas-upnp-org:service:WANIPConnection:1#GetExternalIPAddress"' \
--data-binary '<?xml version="1.0"?><s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:GetExternalI
PAddress xmlns:u="urn:schemas-upnp-org:service:WANIPConnection:1"></u:GetExternalIPAddress></s:Body></s:Envelope>'
)
REGEX='ExternalIPAddress>([0-9.]+)<'