Skip to content

Instantly share code, notes, and snippets.

View jkniiv's full-sized avatar

Jarkko Kniivilä jkniiv

  • Hämeenlinna, Finland, the EU
View GitHub Profile
@jkniiv
jkniiv / generate_directory_index_caddystyle.py
Last active March 18, 2021 14:13 — forked from glowinthedark/generate_directory_index_caddystyle.py
Generate directory index (recurse subfolders with `-r` or `--recursive`). Use `-h` or `--help` for all options
#!/usr/bin/env python3
# ---
# Copyright 2020 glowinthedark
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
#
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
@jkniiv
jkniiv / lsofdrv.awk
Last active June 18, 2020 23:06
On Windows filter handle.exe output to list any open files on a certain drive (yes I know you can use findstr but this one prints also the process name)
BEGIN {
# drive = "E";
print "* The ‘drive’ parameter as specified was ‘" drive "’ (variable value in single quotes)";
# print "* Searching for all references to " drive ":\\ in the third column of the input";
}
/pid:/ {
pidline = $0;
}
@jkniiv
jkniiv / profiles.json
Created January 30, 2020 00:11
Windows Terminal settings (profiles.json) with an ability to launch an elevated Powershell session via sudo.ps1
{
"$schema": "https://aka.ms/terminal-profiles-schema",
"defaultProfile": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
"profiles":
[
{
// Make changes here to the powershell.exe profile
"guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
@jkniiv
jkniiv / Get-URLBeingIndexed.ps1
Created November 28, 2019 01:53
Gets the URL/file that is currently being indexed by Windows Search via the ISearchCatalogManager::URLBeingIndexed() method
# Gets the URL that is currently being indexed by Windows Search via
# the ISearchCatalogManager::URLBeingIndexed() method.
# N.B. This needs to be called elevated, i.e. with admin privileges!
# Load the dll (easiest to be found here https://github.com/IntelliTect/PSToolbox/tree/master/Lib)
Add-Type -Path .\Microsoft.Search.Interop.dll
$searchManager = New-Object Microsoft.Search.Interop.CSearchManagerClass
$catalog = $searchManager.GetCatalog("SystemIndex")
@jkniiv
jkniiv / Show-SearchScopeRules.ps1
Created November 28, 2019 01:43
Returns a GridView of all the "scope rules" for the standard search index of Windows Search
# Returns a visual list via PowerShell's Out-GridView of all the "scope rules" for the standard search index
# in Windows Search. These are objects that represent files and folders to be included in or excluded from
# the search index while Windows Search is indexing (also called "crawling") your files.
# This code is basically from here (except for some re-formatting and new comments by me [Jarkko Kniivilä aka
# 'jkniiv']):
# https://powertoe.wordpress.com/2010/05/17/powershell-tackles-windows-desktop-search/
# See also the following script (not mine) for inspiration if you're interested:
# https://github.com/IntelliTect/PSToolbox/blob/master/Functions/WindowsSearchIndex.ps1
# Load the dll (easiest to be found here https://github.com/IntelliTect/PSToolbox/tree/master/Lib)
@jkniiv
jkniiv / dpinst.xml
Created November 20, 2019 16:55
Installing Lenovo's SCCM-packaged Windows drivers for ThinkPad X250 w/ dpinst.exe (place this xml in c:\drivers\sccm and run dpinst)
<?xml version="1.0" ?>
<dpinst>
<search>
<subDirectory>*</subDirectory>
</search>
<scanHardware/>
<quietInstall/>
</dpinst>
// ==UserScript==
// @name Aliexpress
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://trade.aliexpress.com/orderList.htm*
// @grant unsafeWindow
// @grant GM_xmlhttpRequest
// @grant GM_setClipboard
@jkniiv
jkniiv / .tmux.conf.local.TXT
Created September 17, 2018 04:05
A snippet from my .tmux.conf.local, i.e. the local configuration file of Oh My Tmux! (https://github.com/gpakosz/.tmux)
# (jkniiv, 2018-08-16) replace C-b by C-x instead of using both prefixes
# The reason I use Ctrl-x with tmux is that it's comfortable and it works fine with nano and others (not a vim guy).
# Ok, so it conflicts with nano's exit function but that's just a plus in my view to have to issue a double C-x to exit :)
set -gu prefix2
unbind C-a
unbind C-b
set -g prefix C-x
bind C-x send-prefix
@jkniiv
jkniiv / apt-update+list.sh
Last active July 20, 2021 13:35
The new apt(8) high-level command, when run with the subcommand 'update', kindly suggests you run 'apt list --upgradable' when upgrades are available. Let's automate that :)
#!/usr/bin/env bash
# Run 'apt update' and print every (nonempty) line except the last one with the suggestion to run
# 'apt list --upgradable'.
# In fact we do as suggested instead. :)
apt update 2>&1 | \
awk '
BEGIN { eatnextemptyline = 0 }
/^$/ { if (eatnextemptyline) { eatnextemptyline = 0; next } }
/WARNING: apt does not have a stable CLI interface. Use with caution in scripts./ { eatnextemptyline = 1; next }