Skip to content

Instantly share code, notes, and snippets.

@nrclark
nrclark / make_task.ps1
Last active December 27, 2023 21:32
Powershell script to make WSL start at boot
$ErrorActionPreference = "Stop"
$principal = aNew-ScheduledTaskPrincipal `
-UserId "$env:USERDOMAIN\$env:USERNAME" `
-LogonType S4U `
-RunLevel Limited `
-ThrottleLimit 1
$settings = New-ScheduledTaskSettingsSet `
-MultipleInstances IgnoreNew `
@nrclark
nrclark / SerialBridge.ps1
Created December 27, 2023 17:46
Powershell script that bridges a COM port to a TCP socket.
#!/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe -file
<#
.SYNOPSIS
PowerShell TCP/IP Client for Serial Port Communication.
.DESCRIPTION
This script establishes a TCP connection to a specified server and port and
relays data to and from a specified serial port (COM port).
.PARAMETER server
@nrclark
nrclark / Makefile
Last active December 6, 2023 22:37
Makefile that shows how to run Windows apps from a Docker container on WSL2
# Shell script example of how to run Windows tools from inside
# of a Docker container on WSL2. Note that
# env_vars returns a list of all input words that are defined
# in the environment.
env_vars = $(strip $(foreach x,$1,$(if $(filter environment,$(origin $x)),$x,)))
WSL_VARS := $(sort $(call env_vars,$(filter WSL%,$(.VARIABLES))))
comma := ,
@nrclark
nrclark / mergelog.txt
Last active October 31, 2018 23:41
Git Diffgen
#!/bin/sh
#------------------------------------------------------------------------------#
MERGE="no"
CHECK_ONLY="no"
PROGNAME=`echo "$0" | sed 's@.*/@@g'`
#------------------------------------------------------------------------------#
@nrclark
nrclark / serial_9258.py
Created November 15, 2017 23:24
Serial-port controller for the IP Power 9258
#!/usr/bin/env python3
""" Command-line utility for interfacing with an IP Power 9258 using the
serial debug interface. """
import time
import sys
import re
import argparse
import ast
import serial
@nrclark
nrclark / parallel.sh
Last active July 2, 2017 01:44
Shell script for running commands in parallel
#!/bin/sh
#
# Quick-and-dirty parallelizer, by Nicholas Clark
#
# Uses shell job-control to launch each argument as a subprocess.
# Waits until all subprocesses have finished. If all subprocesses
# returned 0, the result of the script is 0. Otherwise, the result
# will be the error-code of the first failed command in the argument
# list.
#
@nrclark
nrclark / SConstruct
Last active August 23, 2016 07:08
Sample SConstruct file
# vi: set ft=python:
import os
# Run scons three times:
# Run 1. Create new 'dummy_file' and 'file.tcl'
# Run 2. Build 'file.xpr'
# Run 3. Rebuild 'file.tcl' from 'file.xpr' (doesn't trigger currently)
generate_new_tcl = Builder(action='echo "dummy file" > $TARGET')
@nrclark
nrclark / package.yml
Created May 5, 2016 20:57
Ansible playbook for provisioning a build server and building a package
---
- hosts: all
become: true
become_method: sudo
tasks:
- name: Update APT cache
apt: cache_valid_time=3600 update_cache=yes
- name: Upgrade installed packages
apt: upgrade=dist