Skip to content

Instantly share code, notes, and snippets.

@dukechem
dukechem / touchpad-disable-mid-button-emu.sh
Created March 14, 2021 15:14
Inadvertent middle-button on touchpad closes browser tabs, pastes in terminal. Add lines below to .bashrc to Disable mouse middle button emulation by touchpad
# Disable mouse middle button emulation by touchpad
# Add these lines to your .bashrc on linux. Tested with debian
# You may need to change $5 to $6 as explained here:
# Ref: https://forums.linuxmint.com/viewtopic.php?t=284009
# xinput --set-prop (your id number) (your libinput Middle Emulation Enabled number) 1
# That is, setting "Emulation Enabled" to "1" actually disables emulation (confusingly).
# If `xinput not found` then `sudo apt install xinput` or alternatively
# `brew install xinput`
# XINP="/home/linuxbrew/.linuxbrew/bin/xinput"
@dukechem
dukechem / powerchange.sh
Created January 16, 2021 05:26
Low battery warning by audio and notification for macos laptops
#! /usr/bin/env sh
# When battery has less than 25%, pops up notifier counting down integer % of battery left 24, 23, 22, 21 ...
# When battery is less than 15% also announces "Low Battery" verbal warning.
# INSTALL: Put this powerchange.sh file in /Users/Shared/ folder on your mac laptop, then chmod a+x *.sh
# And put com.me.powerchange.plist (below) in ~/Library/LaunchAgents/ (or /Library/LaunchAgents/ for every user).
# This file is run by com.me.powerchange.plist whenever charger is disconnected
# When charger is unplugged, the date of this file changes: Library/Preferences/com.apple.powerlogd.plist
## https://stackoverflow.com/questions/14108471/launchd-watchpaths-will-not-trigger-simple-hello-world-script-os-x-10-8
## See also https://github.com/Goles/Battery/
@dukechem
dukechem / gist:f25dc3934f23a0097b5cff2d9225ada7
Created September 23, 2020 17:09
Easy way to get csv list of files with each md5-sum using free TREESIZE.EXE from https://downloads.jam-software.de/filelist/FileList.zip
cd <path to parent folder of the files>
echo "Do not open c:\temp\filelist-with-md5.csv until you see current time displayed"
filelist /md5 > c:\temp\filelist-with-md5.csv
time /t
@dukechem
dukechem / fetch-macos-throttled-resume.py
Last active February 14, 2023 14:58
Download full macos installers with curl --limit-rate and can resume partial downloads
#!/usr/bin/python
# encoding: utf-8
#
# Copyright 2017 Greg Neagle.
# https://github.com/munki/macadmin-scripts/blob/main/installinstallmacos.py
# 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
@dukechem
dukechem / macos-vnc-join-console-session.sh
Created February 10, 2020 19:43
Fix for no/broken login screen when vnc to remote mojave macos... connects to existing console session I think? See URL for more...
sudo defaults write /Library/Preferences/com.apple.RemoteManagement VNCAlwaysStartOnConsole -bool true
# https://apple.stackexchange.com/questions/342161/macos-mojave-remote-access-login-screen-stuck-on-infinite-loading-spinner
@dukechem
dukechem / batch-conv-portfolio-pdf
Created February 4, 2020 20:00
batch-conv-portfolio-pdf
Unlike ordinary pdf files, portfolio.pdf files cannot be viewed on tablets or phones, and most software that can open them is available only on windows or mac, not on linux (until recently). They really should have a different extension like .pdfp or similar. Google finds lots of folks looking to batch convert portfolios to individual files, as the portfolio breaks *lots* of automated workflows, especially if you upload them to systems that can't handle them. If you try to open them in other viewers, like a link in a browser, you'll see a misleading messages ending in "get adobe reader now!", like:
http://dev.datalogics.com/cookbook/portfolios/portfolio-sample.pdf
You get that brain-dead message even if you already have adobe-reader. The work-around is to download the pdf then open in some awful adobe-reader or acrobat software (version 10 or newer is needed, I believe).
If you have a bunch of such pdfs, this is a place folder for upcoming script to batch convert portfolio pdf files.
@dukechem
dukechem / rdate-windows-howto.txt
Last active August 5, 2020 21:02
howto have older windows (not on internet) just get the right date from newer windows on internet. In this example winXP/7/8 uses psrdatesvc to get datetime on private non-internet network without NTP from a windows or linux pc serving RFC868 time (default port 37).
In example scenario below, the "XP" box can also be vista/win7-8-8.1 (maybe even 10), 32 or 64 bit.
How to keep XP on minimally on network, but not internet, using network only to update time and push files via scp/sftp.
Both old XP and Server are kept safe by closing all ports on XP, and allow that XP computer to connect only to port 37 on a (rfc868 aka "rdate") time-server. The device providing TIME service on port37 should get its own time from internet/intranet (by ntp, etc).
(The time-server does not have run a server-os: it can be almost any linux device, or even a windows-pc.)
With all ports closed on XP, the time-server cannot infect XP. If XP is infected, such as by a usb-key, it cannot spread over
network to time-server (unless time-server has vulnerability known to virus. Turn off smb1 on time-server (if windows)!
On XP/7/8/8.1, rdatesvc.exe (= prdatesvc = PermaSoft Rdate service) safely keeps system time and date correct by periodically from
port 37 on a specified time SerVeR, such time.nist.go
@dukechem
dukechem / python.rb
Last active February 11, 2020 16:46 — forked from SamuelMarks/python.rb
python3.6.9 brew formula. Proof of concept that generally fails: brew switch python3 does not really work right: i.e. pip3 fails. Use pyenv/miniconda instead.
class Python < Formula
desc "Interpreted, interactive, object-oriented programming language"
homepage "https://www.python.org/"
url "https://www.python.org/ftp/python/3.6.9/Python-3.6.9.tar.xz"
sha256 "5e2f5f554e3f8f7f0296f7e73d8600c4e9acbaee6b2555b83206edf5153870da"
revision 1
bottle do
sha256 "1bc5a2d3f0a8602bf2f46de7c43fcb6dde4f110c0f4518d4e802cb1f733a43de" => :high_sierra
sha256 "131d39120ac6ca2f21bf231de7414c08916cea472bc5219e0bcb49541f77cb9f" => :sierra
@dukechem
dukechem / csvcol.sh
Last active February 10, 2020 19:46
csvcol.sh displays how many rows & cols, and shows first 2 rows of csv file(s). Bash/sh script using head, tail, wc, and awk.
#!/bin/bash
if [ $# -eq 0 ]
then
bnam=$(basename "$0")
echo "Usage: $bnam *.csv (displays how many rows & cols, and shows first 2 rows of csv file(s))"; exit
fi
# EXAMPLE OUTPUT
# Total Rows Words Size = 76 76 5587 foobar.csv
# Line 1 has 20 Cols = MW,HBA,HBD,N,O,LOGP,ROTB,TPSA,LOGD,RINGS,ARRINGS,HETRINGS,SYSRINGS,SYSRR,FSP3,NSTEREO,ASA,RELPSA,TC,VWSA
# Line 2 has 20 Cols = 391.43,6,0,4.54,4,71.33,3.22,4,2,4,4,2,2,2,0.27,1,576.35,0.13,-1,538.32