Skip to content

Instantly share code, notes, and snippets.

@jrwarwick
jrwarwick / generate_intent_test_specs.sh
Last active May 11, 2018 23:08
Generate Mycroft AI skill intent testing specs
cd /opt/mycroft/skills/$MYSKILLNAME
mkdir -p test/intent
cd test/intent
grep 'IntentBuilder(' ../../__init__.py | cat -n -- | sed 's/^\s\+\([0-9]\+\).*intent_handler(IntentBuilder("/00\1./ ; s/").*$/\.intent\.json/' | awk '$1'
echo '{
"utterance": "verbal imperative or interrogative after normalization",
"set_context": {"_TestRunner": "data", "test": ""},
"intent_type": "IntentObjectNameFromSkillPythonSource",
"intent": {
@jrwarwick
jrwarwick / mycroft_ws_test.py
Last active May 24, 2018 23:22 — forked from forslund/wstest.py
Connecting to the mycroft message bus.
#! /usr/bin/env python
#pip install websocket-client
#python mycroft_ws_test.py localhost recognizer_loop:utterance '{"utterances": ["what time is it"]}'
import sys
from websocket import create_connection
uri = 'ws://' + sys.argv[1] + ':8181/core'
ws = create_connection(uri)
print("Sending " + sys.argv[2] + " to " + uri + "...")
if len(sys.argv) >= 4:
data = sys.argv[3]
@jrwarwick
jrwarwick / apex_https_oracle_wallet_populate.sh
Created June 22, 2018 23:32
Oracle Wallet population with Trusted Certificate Authority SSL Certificates extracted from Windows
#Use a powershell exporter script to get all the current trusted root CA certs in a folder, then copy up to db server
for sslcert in /tmp/ssl_trusted_cert_export/* ; do openssl pkcs12 -in $sslcert -nokeys -out $( echo $sslcert | sed 's/\.p12/.pem/' ) ; done
mkdir /tmp/ssl_trusted_cert_export/pem && mv /tmp/ssl_trusted_cert_export/*.pem /tmp/ssl_trusted_cert_export/pem/
su - oracle
# Select source ora env
mkdir -p $ORACLE_BASE/wallets/apex
cd $ORACLE_BASE/wallets/apex
@jrwarwick
jrwarwick / authlog_review.sh
Created August 2, 2018 23:18
Portable quick review of the /var/log/authlog file, particularly for when users are logging in with SSH keys
#!/usr/bin/bash
# requires sshd logging in verbose level
# recommended usage:
# ./fp && egrep 'Accepted publickey|Found matching' /var/log/authlog
while read l; do
#[[ -n $l && ${l###} = $l ]] && echo -n "$l: " | cut -f3 -d' ' && echo $l > /tmp/ssh.key.fingerprint.$EUID.$BASHPID && ssh-keygen -l -f /tmp/ssh.key.fingerprint.$EUID.$BASHPID
if [[ -n $l && ${l###} = $l ]] ; then
TAG="$( echo -n "$l" | cut -f3 -d' ' )"
TMPFILE="/tmp/${EUID}.${BASHPID}__ssh.key.fingerprint.$TAG"
@jrwarwick
jrwarwick / listening_ports.sh
Created September 14, 2018 19:59
List unique listening ports on Solaris
netstat -naf inet | grep LISTEN && echo "##" && netstat -naf inet | grep LISTEN | sed -e 's/^ *//' -e ' s/^[^ ]*\.//' | sort -un
@jrwarwick
jrwarwick / windows_print_log_search.ps1
Last active January 25, 2019 23:30
When you need to find out when or if a user sent a print job through the print server.
#!PowerShell
# Assumes print logging is turned on. This is usually the case on print servers,
# yet usually not the case on desktop workstations.
$searchstring = Read-Host -Prompt 'Target username'
$WinEventXMLFilter = '
<QueryList><Query Id="0" Path="Microsoft-Windows-PrintService/Operational">
<Select Path="Microsoft-Windows-PrintService/Operational">*[System[(Level=4 or Level=0) and (EventID=307)]]</Select>
</Query></QueryList>'
$PrintEvents = Get-WinEvent -FilterXml $WinEventXMLFilter -Computer $(Read-Host -prompt 'Print Server computername')
@jrwarwick
jrwarwick / counting_and_multiplying_race.ps1
Created March 13, 2019 14:46
Demo: Computers are Fast at Counting and Simple Math
$multiple = 2
$currentNumber = 1
while ($currentNumber -lt 562949953421310) {
$currentNumber = $currentNumber * $multiple
$currentNumber
}
$vox = New-Object -com SAPI.spvoice
$vox.speak("Sorry, too late. I have already reached $($currentNumber). As you can see, computers really are amazingly, blazingly fast.")
@jrwarwick
jrwarwick / der_to_pfx_conversion.sh
Created April 3, 2019 17:18
PFX/PKCS12 SSH Certificate renewal preparation from DER
#!/bin/sh
#Scenario: some issuer reissues to you a renewed certificate in DER/x509 format,
#but you need it in PFX/PKCS12 format (perhaps to utilize in some Windows PowerShell scripts).
#quick sequence to perform the conversion and sanity check.
#To extract the private key embedded in the (soon to expire) PFX:
openssl pkcs12 -in old_about_to_expire.pfx -nocerts -out extracted_private_key.pem
#To sanity check the incoming renewed cert:
openssl x509 -inform der -in renewed_certificate_as_issued.der -noout -text | grep -v '\([a-z0-9]\{2\}:\)\{10,\}'
@jrwarwick
jrwarwick / generate_glados_utterances.sh
Last active May 31, 2019 23:39
GLADOS-like voice synth
#!/bin/bash
# rapidly rattle off a bunch of eerily familiar utterances
# Credit to https://a3nm.net/blog/glados_espeak.html
while read LINE </dev/tty ; do
TITLE=$( echo $LINE | sed 's/[^a-zA-Z0-9 ]//g; s/ \+/_/g; s/_the_//g; s/_to_//g;' )
echo $LINE | for a in `cat`; do
V=$(((($RANDOM) % 100) - 50)); echo -n "<prosody pitch=\"+$V\">$a</prosody> " |
sed 's/+-/-/' ;
done | espeak -ven+f3 -m --stdout -p 55 -s 150 | oggenc -q1 - > GLADOS_${TITLE}.ogg
done
@jrwarwick
jrwarwick / generate_quicksql_for_existing_tables.sql
Created June 13, 2019 22:49
Generate Oracle QuickSQL from all visible tables
-- Quick, dirty, and incomplete. Look to dgielis/model_to_quicksql.sql for more power
select table_name||chr(10)||listagg(' '||column_name||' '
||case data_type
when 'VARCHAR2' then 'vc'||to_char(data_length)
when 'NUMBER' then 'num'
when 'INTEGER' then 'int'
when 'DATE' then 'date'
when 'INTEGER' then 'int'
END,chr(10)) within group (order by column_id) quicksql
from all_tab_cols