Skip to content

Instantly share code, notes, and snippets.

View jimbo8098's full-sized avatar

Jim Speir jimbo8098

View GitHub Profile
@jimbo8098
jimbo8098 / nginx.conf
Created February 5, 2020 17:54 — forked from Stanback/nginx.conf
Example Nginx configuration for adding cross-origin resource sharing (CORS) support to reverse proxied APIs
#
# CORS header support
#
# One way to use this is by placing it into a file called "cors_support"
# under your Nginx configuration directory and placing the following
# statement inside your **location** block(s):
#
# include cors_support;
#
# As of Nginx 1.7.5, add_header supports an "always" parameter which
@jimbo8098
jimbo8098 / main.c
Last active April 29, 2020 18:13
Blink LED1 and 2 on EXP430FR4133 such that LED1 is off when LED2 is on. The general premise here should be the same for MSP430FR4133 chips too.
#include <msp430.h>
volatile unsigned int i = 0;
/**
* main.c
*/
int main(void)
{
// Stop watchdog timer. This line of code is needed at the beginning of most MSP430 projects.
@jimbo8098
jimbo8098 / output-spotify-playlist-songs.js
Last active April 29, 2020 19:42
Outputs all songs currently in view on a Spotify playlist page and outputs a JSON array of those songs
// Go to https://open.spotify.com/playlist/7dhpGlWyXiRadoIgKKvubA?si=tF8elMqMSPazYUUzKivLgg&fbclid=IwAR0bNVYx-XV0ddKp9djpk5RxfpgERLqJOHk9Vjb7-amThYQwl-gl3j1gthM or something similar then run this in console
var songs = [];
var rows = document.getElementsByClassName("tracklist-row");
for(var i = 0; i < rows.length; i++)
{
var rowComps = rows[i].innerText.split("\n");
if(rowComps[1] != "E")
{
var song = {
"name": rowComps[0],
@jimbo8098
jimbo8098 / main.go
Last active August 30, 2020 17:59
Go HTTP Server
// Using this Gist, you can kick off a web server and start receiving and sending data when you visit localhost:5000/foo or /bar
package main
import (
"net/http"
)
type fooHandler struct {
Message string
@jimbo8098
jimbo8098 / Hyper-V Test Network.md
Created September 2, 2020 10:17
Creating a Hyper-V Test Network
  1. Enable Hyper-V in Windows Features
  2. Grab the server ISO, e.g. https://ubuntu.com/download/server
  3. Set up a new switch in Hyper-V with Internal type
  4. Set up the host OS' network for the new virtual switch (which should appear as a network card on the OS. Set the IP to 10.0.1.1 and the subnet as 255.0.0.0. Leave the gatway blank.
  5. Set up the gues OSes: 5a. Log into the OS then set the network up. If you are using netplan edit /etc/netplan/ file as follows:
    eth1:
      dhcp4: no
    

addresses: [10.0.1.5/24]

In the current Windows 2019 meta (build 1809), it is not possible to use && to run commands sequentially in the one process. The same syntax is true in build 2004 of Windows 10 Pro. You need to use this format at the moment:

RUN echo "command 1"; if ($?) {\
    echo "command 2"; if ($?) {\
    echo "command 3"; }}

The backslashes are to escape the newline character for Docker.

There is a PR open for comment at PowerShell/PowerShell#9849 which refers to changing this so that && works but in this particular LTSC build of Windows, you can't use it. At this time it looks to be merged so presumably we will see it soon enough.

@jimbo8098
jimbo8098 / windows-azure-pipeline.md
Last active September 17, 2020 14:17
Windows Docker Build with Library Variables in Azure

When running a container build in a pipeline on Azure, it is important to remember buildAndPush does not currently support the addition of argument (see https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/build/docker?view=azure-devops#build-and-push ) but it is possible to build your container with arguments using the simple build command instead. For example:

    - task: Docker@2
      displayName: Build
      inputs:
        command: build
        containerRegistry: $(dockerRegistryServiceConnection)
        repository: $(imageRepository)
        dockerfile: $(dockerfilePath)
@jimbo8098
jimbo8098 / docker-classic-asp-gmsa.md
Created September 30, 2020 14:45
Classic ASP Docker Container gMSA

Classic ASP may be almost dead but unfortunately not quite. Thankfully we can at least make it a bit more modern. The steps below go through the steps required to setup gMSA authentication on a Classic ASP docker container. I will use an example of a similar issue I was trying to solve which required Integrated Authentication to be used (in place of plaintext credentials)

  1. Set up your gMSA per https://docs.microsoft.com/en-us/virtualization/windowscontainers/manage-containers/manage-serviceaccounts
New-ADGroup -Name "Service Provider Group" -SamAccountName "ServiceHosts" -GroupScope DomainLocal
Add-ADGroupMember -Identity "ServiceHosts" -Members "SERVER01$"
New-ADServiceAccount -Name "app" -DnsHostName "app.domain.local" -ServicePrincipalNames "host/ServiceHosts" - PrincipalsAllowedToRetrieveManagedPassword "ServiceHosts"
@jimbo8098
jimbo8098 / chirp-install.md
Created October 31, 2020 18:35
Chirp Install Ubuntu 20.04
@jimbo8098
jimbo8098 / runner.md
Created December 1, 2020 00:18
Start a Windows Docker Github Runner through Powershell (Server Core 2019)

When starting a new github runner in a virtualized environment I had some issues due to the environment using Server Core 2019 and therefore not shipping with the usual GUI tools. To use the runner with the Docker service by default I had to register the Github agent runner as the LocalSystem account instead.

  1. Download and install Docker and Git per their docs
  2. In your Github repo, go to the settings > actions section and click add runner. Select Windows (if it's not default) then download the agent and expand it per the instructions.
  3. Ensure you use --windowslogonaccount LocalSystem
./config.cmd --url repourl --token token --runasservice --name hostname --windowslogonaccount LocalSystem

The reason this works is that by default the LocalSystem user has access to Docker although it also has access to slews of other resources. It is probably better practice to make a user specifically for your runners with just the access they need but this is difficult on Server Core so I just close things out