Skip to content

Instantly share code, notes, and snippets.

View chalvorson's full-sized avatar

Carl Halvorson chalvorson

  • United States
View GitHub Profile
@chalvorson
chalvorson / SendLink.gs
Created March 17, 2019 03:41
Email a link to Google Sheet via Google Apps Script
@chalvorson
chalvorson / dataframe_googlesheets.py
Created March 18, 2019 00:28
Helper functions to read/write a Pandas DataFrame to/from Google Sheets
def gsheet_to_dataframe(sheet_service, sheet_id, sheet_range):
result = sheet_service.values().get(
spreadsheetId=sheet_id, range=sheet_range).execute()
values = result.get('values', [])
# Assuming the first row is column names
df = DataFrame(data=values[1:], columns=values[0])
return df
@chalvorson
chalvorson / LoadLibraries.gs
Created March 21, 2019 18:06
Load and cache local or remote javascript libraries into Apps Script
/*
* LoadLibraries.gs - App Script for cached local and remote javascript libraries
*
* Built from the ideas at:
* https://ctrlq.org/code/20380-load-external-javascript-with-eval
* https://stackoverflow.com/questions/18646554/importing-external-javascript-to-google-apps-script
* https://stackoverflow.com/questions/22410210/how-do-i-use-momentsjs-in-google-apps-script/49934393#49934393
* https://stackoverflow.com/questions/16149760/calculating-year-month-days-between-dates-in-google-apps-script/18171101#18171101
*
*/

Keybase proof

I hereby claim:

  • I am chalvorson on github.
  • I am chalvorson (https://keybase.io/chalvorson) on keybase.
  • I have a public key ASDvn4ssYPI88gggFwG5y3movH3Zvyy1_GSKyz055_rFXwo

To claim this, I am signing this object:

@chalvorson
chalvorson / cisco_ios_backup.py
Created December 8, 2019 22:16
Backup running configuration of a list of Cisco IOS switches
'''
This script uses netmiko to take a backup from cisco ios switches. The config files
are stored in config/ and the log files are stored in log/
Arguments: -u - login username
-p - login password
-s - enable password
-f - file with list of switch ip addresses
Output is an .ios file for each switch with date stamp
Requirements: netmiko, loguru
@chalvorson
chalvorson / WSUS-ApproveUpdatesFromFile.ps1
Created March 5, 2020 02:48
Approve list of updates for computer group on WSUS
[CmdletBinding()]
Param (
[Parameter(Mandatory=$true,
Position=0)]
[string]
$WsusServer,
[int]
$Port = "80",
[Parameter(Mandatory=$true)]
[ValidateScript({Test-Path $_ -PathType 'Leaf'})]
@chalvorson
chalvorson / motd.sh
Created July 3, 2020 05:48
Custom Raspberry Pi MOTD
#!/bin/bash
let upSeconds="$(/usr/bin/cut -d. -f1 /proc/uptime)"
let secs=$((${upSeconds}%60))
let mins=$((${upSeconds}/60%60))
let hours=$((${upSeconds}/3600%24))
let days=$((${upSeconds}/86400))
UPTIME=`printf "%d days, %02dh%02dm%02ds" "$days" "$hours" "$mins" "$secs"`
# get the load averages
@chalvorson
chalvorson / impersonate.py
Created August 27, 2021 21:35
Simple context manager for impersonating the current logged-in user under Windows OS.
"""Simple context manager for impersonating the current logged-in user
under Windows OS.
Requires:
pywin32
"""
import ctypes
from win32process import GetWindowThreadProcessId
from win32api import OpenProcess
@chalvorson
chalvorson / mapper.py
Created August 27, 2021 21:44
Map a network share as the current logged-on user
import win32wnet, win32netcon
from impersonate import ImpersonateUser
with ImpersonateUser():
# map the drive using the current user's login
try:
nr = win32wnet.NETRESOURCE()
nr.dwScope = win32netcon.RESOURCE_GLOBALNET
nr.dwType = win32netcon.RESOURCETYPE_DISK
nr.dwUsage = win32netcon.RESOURCEUSAGE_CONNECTABLE
@chalvorson
chalvorson / personal-signing-certificate.txt
Created November 5, 2022 21:57
Create code-signing certificate to sign Windows executable
Notes to create a personal code-signing certificate. Assumes that Easy-RSA is already set up as Certificate Authority.
Tools used:
OpenSSL
Easy-RSA
signtool.exe (winget install Microsoft.WindowsSDK)
Using OpenSSL:
Generate a key and a certificate signing request