Skip to content

Instantly share code, notes, and snippets.

View ericchansen's full-sized avatar

Eric Hansen ericchansen

  • United States
View GitHub Profile
@ericchansen
ericchansen / apps-script.gs
Last active October 23, 2023 16:44
Import events from one calendar into another
function sync() {
var id = "ericchansen@gmail.com";
var today = new Date();
var endDate = new Date();
endDate.setDate(today.getDate() + 7);
var secondaryCal = CalendarApp.getCalendarById(id);
var secondaryEvents = secondaryCal.getEvents(today, endDate);
var primaryCal = CalendarApp.getDefaultCalendar();
var primaryEvents = primaryCal.getEvents(today, endDate);
var primaryEventTitle = "Personal Appointment";
@ericchansen
ericchansen / fix_id_rsa_permissions.ps1
Created May 24, 2023 19:36
Fix permission issues in Windows for id_rsa.
New-Variable -Name Key -Value "$env:UserProfile\.ssh\id_rsa"
Icacls $Key /c /t /Inheritance:d # Disable inheritance of permissions from parent objects.
Icacls $Key /c /t /Grant ${env:UserName}:F # Grants full control (F) permission to current user.
TakeOwn /F $Key # Take ownership.
Icacls $Key /c /t /Grant:r ${env:UserName}:F # Grants full control (F), but replace any existing permissions rather than add them.
Icacls $Key /c /t /Remove:g Administrator "Authenticated Users" BUILTIN\Administrators BUILTIN Everyone System Users # Remove these groups from the access control list.
Icacls $Key # Display updated permissions.
Remove-Variable -Name Key
@ericchansen
ericchansen / monitor_usb.ps1
Created May 24, 2023 18:19
PowerShell script to monitor device connects and disconnects on Windows.
$CurrentState = $null
$NewState = $null
Write-Host "Monitoring device changes..." -ForegroundColor Green
while ($true) {
if (-not($CurrentState)) {
$CurrentState = Get-PnpDevice -Status OK
}
else {
$NewState = Get-PnpDevice -Status OK
$Changes = $null
# You have to do this to allow yourself to run scripts.
# Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted
oh-my-posh font install "Meslo"
# Not sure how to automate.
# CTRL + SHIFT + , to open settings.json.
# Add this.
# {
# "profiles":
@ericchansen
ericchansen / .emacs_on_windows
Created November 5, 2021 15:14
.emacs_on_windows
;; Place this file in C:\Users\<username>\AppData\Roaming and point to the appropriate files
(setq user-init-file "C:/path/to/.emacs")
(setq user-emacs-directory "C:/path/to/.emacs.d/")
(setq default-directory "C:/whatever/you/want/to/start/in")
(setenv "HOME" "D:/my/home/directory")
(load user-init-file)
@ericchansen
ericchansen / .emacs
Last active November 5, 2021 15:12
My .emacs configuration
;; Highlights dumb stuff.
(require 'whitespace)
(setq whitespace-style '(face empty tabs lines-tail trailing))
(global-whitespace-mode t)
;; 80 column marker.
(
add-hook 'rust-mode-hook (
lambda ()
(setq-local whitespace-line-column 80)
@ericchansen
ericchansen / install-with-fresh-windows-03.ps1
Last active May 9, 2023 17:26
Install useful stuff on Windows
# Make powershell awesome.
Install-Module -Scope CurrentUser -SkipPublisherCheck -Name posh-git -Force
Install-Module -Scope CurrentUser -SkipPublisherCheck -Name PSReadLine -Force
# Create your profile if it doesn't exist.
if (!(Test-Path -Path $PROFILE)) {
New-Item -ItemType File -Path $PROFILE -Force
}
Set-Content -Path $Profile -Value "oh-my-posh init pwsh --config 'https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/jandedobbeleer.omp.json' | Invoke-Expression"
@ericchansen
ericchansen / install-with-fresh-windows-01.bat
Last active November 29, 2023 21:39
Install useful tools on Windows. You'll have to enable winget before you can use this.
@ECHO OFF
GOTO CHECK_PERMISSIONS
:CHECK_PERMISSIONS
ECHO Administrative permissions required. Detecting permissions...
NET SESSION >NUL 2>&1
if %errorLevel% == 0 (
ECHO Success: Administrative permissions confirmed. Press any key to continue.
) else (
ECHO Failure: Current permissions inadequate. Press any key to continue.
@ericchansen
ericchansen / install-terminal-parrot.sh
Last active October 26, 2018 15:21
Install the most crucial component of any Ubuntu system
sudo apt-get -y install golang
# Adds to ~/go/bin.
go get -u github.com/jmhobbs/terminal-parrot
echo "export PATH=\"$PATH:/home/eric/go/bin\"" >> ~/.profile
@ericchansen
ericchansen / install-with-fresh-ubuntu.sh
Last active May 8, 2023 18:31
Fresh Ubuntu install script
sudo apt-get update && sudo apt-get upgrade
sudo apt-get -y install build-essential curl
git config --global credential.helper "/mnt/c/Program\ Files/Git/mingw64/libexec/git-core/git-credential-wincred.exe"
# Setup Docker. These directions work on WSL2.
sudo addgroup --system docker
sudo adduser $USER docker
newgrp docker
sudo chown root:docker /var/run/docker.sock