Skip to content

Instantly share code, notes, and snippets.

View espoelstra's full-sized avatar

Ethan Spoelstra espoelstra

View GitHub Profile
@espoelstra
espoelstra / !powershell-hijinks.md
Created September 24, 2018 02:08
PowerShell hijinks

If wanting to run a .ps1 with a double click it IS possible to edit the registry to allow this, the issue is that scripts that aren't elevated may fail, and it bypasses some of the ExecutionPolicy restrictions or hardcodes the same policy for all of them.

This Q&A has a number of options for making it work, but the best practice scenario I'm going with is creating a .bat file to call a .ps1 file, and then putting a shortcut to the .bat file on the Public Desktop so that the shortcut can be set to run as Administrator and prompt for the password if UAC is configured that way.

https://stackoverflow.com/questions/10137146/is-there-any-way-to-make-powershell-script-work-by-double-clicking-ps1-file

For reference the "Run with PowerShell" in the right click menu uses this as the "Command" registry key, "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" "-Command" "if((Get-ExecutionPolicy ) -ne 'AllSigned') { Set-ExecutionPolicy -Scope Process Bypass }; & '%1'"

If a user has changed the association

@espoelstra
espoelstra / .freedos-pxe-boot.md
Created September 26, 2018 21:52
Creating a FreeDOS image for PXE boot

FreeDOS easy to update USB or PXE boot (Legacy or EFI)

I've been wanting to do this for quite a while, ever since I had to make up dozens of USB drives with a system image for deployment to migrate from Windows XP to Windows 7 for a large enterprise. Any tweaks to the image required re-writing all the drives, and the quickest way to burn up a cheap drive is repeated reads and writes. Then I learned partway through the rollout from the support staff performing the hands-on reimaging that on some systems the boot took forever, and while investigating I discovered that there was a BIOS update that remedied the issue and the system boot dropped from 10-15 minutes to a minute or two. After that I added updating the BIOS to our reimage procedure checklist, but again I was making multiple copies of the USB so that each tech could have one to do the fairly quick BIOS update before switching over to the other USB for imaging the system. Luckily at the time I had opted for the USB "full" image of FreeDOS which had sp

@espoelstra
espoelstra / .bats-mock-SO.md
Last active September 30, 2018 02:19
Bats-mock which to use?
@espoelstra
espoelstra / .bats-advice.md
Created September 30, 2018 02:20
Bats testing advice, pitfalls, and behaviors to watch out for

You can test almost anything with Bats, assuming it accepts input and produces output or an exit code. Bats is commonly used to test scripts, but it can also be used to wrap characterization or integration tests or API "contract" tests around an executable (eg run my-thing.bin -h ; assert_exit_code == 0 or to run a series of commands and test the results across various parts of the system (eg docker ps | grep bats ; assert_line 'bats/bats:latest').

When testing a shell script with bats there are multiple ways to perform the tests. You can do a "blackbox" style run my-script.sh --some option --other-flag and assert certain outputs and status codes and check for the presence or absence of temporary files in /tmp (if it was supposed to create or clean them up), or the absence of oh-poop.log files if the script triggers logging when it hits an error. Or you can do individual function testing and examine the environment variables after executing individual functions to check for any state that you are t

@espoelstra
espoelstra / .moving-domain-joined-drives.md
Last active October 1, 2018 16:52
Moving hard drive between computers when joined to an AD/SSSD domain

When imaging a computer to speed up the process and avoid prompts but also prevent duplicate names on the network, you will typically configure your image to pull out some unique identifier from the hardware and use that as part of the hostname. This could be the system serial number or the MAC address of the on board network controller (highly unlikely to change without a new motherboard) or something else like that.

The trouble with moving a hard drive that has been imaged this way is that it doesn't magically adopt the unique attributes from the new system, and if you reimage the old system with another drive, there is now an "evil" twin on the network, which causes no end of fun and frivolity when suddenly one becomes untrusted and you can't log into any AD accounts from it.

The solution is that immediately after moving the drive to a new computer, you should login, then unjoin the domain (requires domain admin permissions) so you can rename and rejoin once you know what unique identifier you will use i

@espoelstra
espoelstra / !notes.md
Last active February 8, 2019 17:45
Jetbrains IntelliJ IDEA RubyMine WebStorm PhpStorm PyCharm HiDPI on ChromeOS experiments

Finding optimal settings for rapidly scalable ChromeOS UI

Official documentation

https://www.reddit.com/r/Crostini/wiki/howto/adjust-display-scaling

"Best" method in Chrome v73+

The BEST way to do this in ChromeOS is to right click the application icon and choose "Use low density", then either allow ChromeOS to restart the app or say "Not now" and do it yourself. Upon starting the application again you should have a readable UI without monkeying with the Java VM options or the properties of whichever app your are using.

@espoelstra
espoelstra / fix-desktop-launcher.sh
Created February 6, 2019 21:25 — forked from stuaxo/fix-desktop-launcher.sh
Launch desktop files instead of opening them in gedit.
$ sudo apt-get install dex
$ /usr/bin/dex -c /usr/bin/dex -t ~/.local/share/applications/
@espoelstra
espoelstra / README.md
Last active April 2, 2019 16:00 — forked from fkorotkov/nanka.xml
Use the xml to enabled nested virtualization with the Anka command line installation instructions like `sudo installer -applyChoiceChangesXML nanka.xml -pkg AnkaBuild-1.4.3.104.pkg -target /`

README

Save this XML somewhere like $HOME/Downloads alongside the Anka .pkg file. Install/reinstall using this xml to enabled nested virtualization with the Anka command line installation instructions:

  • sudo installer -applyChoiceChangesXML nanka.xml -pkg AnkaBuild-1.4.3.104.pkg -target / If your hardware supports things properly, you should be able to install Docker for Mac inside the VM and use it.
@espoelstra
espoelstra / azure-pipelines.yml
Last active April 2, 2019 18:29
Azure DevOps Docker for Mac installation
pool:
vmImage: 'macOS-10.13'
steps:
- bash: |
brew cask install docker # grabs Docker for Mac
set -x
echo "Running xattr" # I think brew is supposed to do this but I was still prompted to "trust" it if I didn't
xattr -d -r com.apple.quarantine /Applications/Docker.app
echo "Running Docker as root to install helpers"
@espoelstra
espoelstra / !new-machine-setup.sh
Last active April 27, 2020 01:23
New macOS setup for flexibility and productivity
# Check the dock settings
# Future plan is automatic removal of unwanted items and addition of only necessary items using dockutil/Ansible
# plutil -p Library/Preferences/com.apple.dock.plist
# Enable SSH server for remote management/configuration
sudo systemsetup -setremotelogin on
# Install Homebrew (if it isn't already available)
hash brew || /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"