Skip to content

Instantly share code, notes, and snippets.

@wheresjames
wheresjames / monitor-ip.sh
Created October 16, 2024 09:36
This script pings an IP address at regular intervals and plays a sound indicating the IP address is reachable or unreachable.
#!/bin/bash
# This script pings an IP address at regular intervals and plays a sound
# indicating the IP address is reachable or unreachable.
IP=$1
DELAY=10
TIMEOUT=3
# Check if an IP address was provided as an argument
if [ -z "$IP" ]; then
@wheresjames
wheresjames / settouchscreens.sh
Created August 21, 2024 19:30
Map touch screens to displays
#!/bin/bash
#--------------------------------------------------
# Set touchscreen to monitor mapping
declare -A mapping
mapping["ELAN9008:00 04F3:4063"]="eDP-1"
mapping["ELAN9009:00 04F3:4068"]="DP-1"
#!/bin/bash
echo "Cleaning Xcode..."
# Clear Xcode Caches
CLEANDIRS=("~/Library/Developer/Xcode/DerivedData" \
"~/Library/Caches/org.swift.swiftpm" \
"~/Library/Caches/org.swift.swiftpm.$USER" \
"$(getconf DARWIN_USER_CACHE_DIR)/org.llvm.clang/ModuleCache" \
"$(getconf DARWIN_USER_CACHE_DIR)/org.llvm.clang.$USER/ModuleCache" \
@wheresjames
wheresjames / vscode-settings.json
Last active October 16, 2024 10:59
vscode-settings.json
{
"workbench.startupEditor": "none",
"workbench.sideBar.location": "right",
"editor.renderWhitespace": "boundary",
"editor.suggest.snippetsPreventQuickSuggestions": false,
"emmet.showAbbreviationSuggestions": false,
"editor.wordBasedSuggestions": "off",
"editor.snippetSuggestions": "none",
"editor.inlineSuggest.enabled": true,
"editor.acceptSuggestionOnCommitCharacter": false,
#include <iostream>
#include <string>
#include <vector>
#include <filesystem>
#include <cstdlib>
#include <regex>
/** This program executes a command for each file in a directory that matches a filter.
Usage : test_args <directory> <file-filter> <executable> [extra arguments...]
@wheresjames
wheresjames / cmake-tasks.sh
Last active October 17, 2023 22:51
CMake build script for Visual Studio
#!/bin/bash
# http://github.com/wheresjames
# Run this from the command line like
#
# $ ~/path/to/cmake-tasks.sh clean-config-build release build ./some/cmake/project
#
# OR
#
# $ cd ./some/cmake/project
@wheresjames
wheresjames / certrenew.sh
Created September 9, 2021 01:13
Renew cert with certbot / nginx
echo $DOMAINNAME
# Get cert expire info
EXPDATE=$(echo | openssl s_client -servername $DOMAINNAME -connect $DOMAINNAME:443 2>/dev/null | openssl x509 -noout -enddate)
EXPDATE2=${EXPDATE[@]:9}
FMTDATE=$(date --date="$EXPDATE2" "+%Y-%m-%d %H:%M:%S")
# Cert expire time
EXPTIME=$(date --date="$EXPDATE2" +%s)
function promiseWhile(cond, prom) {
return prom().then(r=> { return cond(r) ? promiseWhile(cond, prom) : r; });
}
function countTo(n) {
let i = 0;
return promiseWhile((r)=> r < n, () => {
return new Promise((resolve, reject)=> {
console.log(i);
setTimeout(()=>{i++; resolve(i);}, 1000);
@wheresjames
wheresjames / linode-deploy.sh
Created January 12, 2021 19:40
Deploy apache server to a Linode instance
#!/bin/bash
#--------------------------------------------------------------------------------------------------
#
# Examples
#
# Setup new instance
# $ ./linode-deploy.sh create-setup <username> newserver.example.com
#
# After you've added the IP address to your DNS, get a lets encrypt cert with
@wheresjames
wheresjames / gdrive.py
Created January 3, 2021 13:32
Python script to sync local folder to google drive
#!/usr/bin/env python3
from __future__ import print_function
import os
import sys
import time
import json
import random
import inspect
import argparse