Skip to content

Instantly share code, notes, and snippets.

View JohnL4's full-sized avatar

John Lusk JohnL4

View GitHub Profile
Physical display pixels/in. = # of pixels on diagonal / diagonal size of monitor
e.g., Phililps PHL 346B1C is a 34" ultra-wide at 3440x1440
PowerShell:
> $d = 3440*3440 + 1440*1440
> [Math]::Sqrt($d) # Pixels on the diagnoal
> [Math]::Sqrt($d)/34 # Pixels/in., matches manufacturer claim of 110 ppi.
@JohnL4
JohnL4 / howto-create-gmail-alias.txt
Last active December 15, 2020 16:39
Creating yet another new alias in gmail
I usually UNCHECK the "treat as alias" checkbox
server: smtp.gmail.com (no "@", dummy)
user: [email protected]
password: app password from google acct mgmt ("security/sign on")
yay, google sends you a verification email
@JohnL4
JohnL4 / passwd-securestring-mechanics.ps1
Last active November 20, 2020 21:11
Store and retrieve a password using Microsoft's magical amazing SecureString functions
$passwd = ConvertTo-SecureString 'hunter2' -AsPlainText -Force
[Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($passwd))
# Another way to get the password in w/out putting it in a command line as above.
$passwd = Read-Host -AsSecureString
[Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($passwd))
$bytes = (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16)
$bytes.length # Should be 16
@JohnL4
JohnL4 / create-grafana-annotation.ps1
Created November 5, 2020 22:33
Create a Grafana annotation via the api in PowerShell
$grafana = "http://yerhost:3000"
$headers = @{ Accept = "application/json"; Authorization = "Bearer yerApiKey" }
# This is how you get your timezone handled properly. Also, this lovely .ToUnixTimeMilliseconds() is just the ticket.
#
$timeEpoch = (new-object DateTimeOffset -ArgumentList $(get-date)).ToUnixTimeMilliseconds()
# Panel id is optional.
#
@JohnL4
JohnL4 / grep-sort-uniq-PowerShell-vs-Unix.md
Last active September 30, 2020 15:01
grep | sort | uniq in PowerShell vs. Unix

PowerShell:

cat Temp\dashboard-plus-reset-filters-to-default-plus-turn-off-one-cascading-filter.json `
  | Select-String '"count": [0-9]+' `
  | select -expand Matches `
  | % {$_.Value} `
  | sort `
  | gu
@JohnL4
JohnL4 / httpServer.py
Created September 23, 2020 14:59
Use Python to simply server files from local dir, giving javascript the correct MIME type.
# Use to create local host, server javascript modules w/the correct mimetime.
# See https://stackoverflow.com/a/60638762
#
import http.server
import socketserver
PORT = 8080
Handler = http.server.SimpleHTTPRequestHandler
Handler.extensions_map.update({
@JohnL4
JohnL4 / log-config.yaml
Created September 10, 2020 21:38
Complex logging configuration in python, using the "logging" module and yaml configuration
version: 1
formatters:
# Note that the following formats may use the 'hostname' attribute, which is non-standard. Be sure to use an adapter
# or a filter to get that info into the LogRecord context or ugliness will result.
# See:
# - mem_cleaner2.HostnameLoggerAdapter
# - https://docs.python.org/3/howto/logging-cookbook.html#adding-contextual-information-to-your-logging-output
#
oneLine:
@JohnL4
JohnL4 / index.html
Last active September 2, 2020 19:37
Vivid CSS3 Spinner
<section class="wrapper">
<div class="spinner">
<i></i>
<i></i>
<i></i>
<i></i>
<i></i>
<i></i>
<i></i>
</div>
@JohnL4
JohnL4 / insert-current-line-number.el
Created July 13, 2020 14:55
Insert current line number at a place in a file (emacs lisp)
; For use in editing files of programming languages that don't have "current line number" functions.
; Looking at you, k6.io.
; Include in macro or defun, obviously.
(insert (format "%d" (line-number-at-pos)))
@JohnL4
JohnL4 / converting-epoch-timestamps.py
Created July 10, 2020 16:52
Converting epochs as given in jwt iat fields to human-readable timestamps
# PS S:\JLusk\Play\k6> python
# Python 3.8.3 (tags/v3.8.3:6f8c832, May 13 2020, 22:37:02) [MSC v.1924 64 bit (AMD64)] on win32
# Type "help", "copyright", "credits" or "license" for more information.
from datetime import *
dt = datetime.fromtimestamp(1594396899)
dt.strftime( "%c")
# 'Fri Jul 10 12:01:39 2020'
quit()