Skip to content

Instantly share code, notes, and snippets.

@TaoK
TaoK / gist:31d198c05b9e1bdb0b29e743168199cb
Last active October 5, 2022 10:24
Query pihole DB for recent domains by a client IP
# Prerequisites: raspberry pi with static IP, pihole, and sqlite3, set up with dhcp, and router dhcp disabled
# look up the client IP in the admin interface
INTERESTING_IP=192.168.1.242
# raw domains in 7 days, ordered by frequency
sqlite3 /etc/pihole/pihole-FTL.db "SELECT domain, count(1) FROM queries WHERE timestamp > (SELECT strftime('%s', datetime('now', '-1000 day'))) AND status IN (2, 3, 12, 13, 14) AND client='$INTERESTING_IP' GROUP BY client, domain ORDER BY count(1) DESC"
# second level domains in 7 days, ordered by frequency
sqlite3 /etc/pihole/pihole-FTL.db "SELECT substr(domain, length(rtrim(substr(domain, 0, length(rtrim(domain, replace(domain, '.', '')))), replace(domain, '.', ''))) + 1), count(1) FROM queries WHERE timestamp > (SELECT strftime('%s', datetime('now', '-1000 day'))) AND status IN (2, 3, 12, 13, 14) AND client='$INTERESTING_IP' GROUP BY substr(domain, length(rtrim(substr(domain, 0, length(rtrim(domain, replace(domain, '.', '')))), replace(domain, '.', ''))) + 1) ORDER BY count(1
@TaoK
TaoK / CDOSysEmbeddedImages.vbs
Created August 30, 2012 09:53
VBScript/VBA function for sending HTML email with embedded images
'This function is intended to make it a little easier to add images to emails when sending them
' through CDOSYS (CDO.Message). If all the following are true, this may help:
' - You want to send an HTML email, with one or more images in the email body
' - You want the images to be in the email itself, so that they display without any security or privacy warnings
' - You don't want the images to show up explicitly as "Attachments" in email clients like Microsoft Outlook
' - You don't want to use the images to "track" who has read your emails (that requirement would be incompatible with the rest)
' - You are using VBScript (ASP, WSH) or Office Visual Basic for Applications (VBA), or Visual Basic 6 (VB6)
'
' This code is loosely based on a collection of prior resources/examples online:
' - VBS/VBA versions using "AddRelatedBodyPart":
@TaoK
TaoK / Diff.cs
Created May 8, 2012 08:01
C# port of JS 3-way merge implementation in Synchrotron
// Copyright (c) 2006, 2008 Tony Garnock-Jones <tonyg@lshift.net>
// Copyright (c) 2006, 2008 LShift Ltd. <query@lshift.net>
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation files
// (the "Software"), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
@TaoK
TaoK / jQuery.base64.js
Created January 12, 2012 18:23
jQuery BASE64 functions (yet another)
/**
* jQuery BASE64 functions
*
* <code>
* Encodes the given data with base64.
* String $.base64Encode ( String str )
* <br />
* Decodes a base64 encoded data.
* String $.base64Decode ( String str )
@TaoK
TaoK / Invoke-ElevatedCommand.ps1
Created January 9, 2012 09:33
Invoke-ElevatedCommand for Administrator-level commands in a common powershell pipeline
Function Invoke-ElevatedCommand {
<#
.DESCRIPTION
Invokes the provided script block in a new elevated (Administrator) powershell process,
while retaining access to the pipeline (pipe in and out). Please note, "Write-Host" output
will be LOST - only the object pipeline and errors are handled. In general, prefer
"Write-Output" over "Write-Host" unless UI output is the only possible use of the information.
Also see Community Extensions "Invoke-Elevated"/"su"
.EXAMPLE
@TaoK
TaoK / JQuerySerializeCheckbox.js
Created January 6, 2012 21:38
JQuery Serialize Method with Checkbox False Output
(function ($) {
$.fn.serialize = function (options) {
return $.param(this.serializeArray(options));
};
$.fn.serializeArray = function (options) {
var o = $.extend({
checkboxesAsBools: false
}, options || {});
@TaoK
TaoK / ClrXmlShredder.cs
Created June 19, 2011 21:16
ClrXmlShredder - a CLR Stored Procedure for shredding the Xml result of "FOR XML"
/*
ClrXmlShredder - a CLR Stored Procedure for shredding the Xml result of "FOR XML"
Copyright Tao Klerks, June 2011, tao@klerks.biz
Licensed under the modified BSD license (license text below).
--------
Overview
--------
@TaoK
TaoK / TextFileEncodingDetector.cs
Last active July 21, 2023 08:56
Simple class to automatically detect text file encoding, with English-biased "best guess" heuristic based on byte patterns in the absence of BOM.
using System;
using System.Text;
using System.Text.RegularExpressions;
using System.IO;
namespace KlerksSoft
{
public static class TextFileEncodingDetector
{
/*