Skip to content

Instantly share code, notes, and snippets.

@ShinNoNoir
ShinNoNoir / Get-Monitor.ps1
Created March 5, 2023 12:42
Get Monitor Information
<#
.SYNOPSIS
This Powershell function gets information about the monitors attached to any computer. It uses EDID information provided by WMI. If this value is not specified it pulls the monitors of the computer that the script is being run on.
.DESCRIPTION
The function begins by looping through each computer specified. For each computer it gets a litst of monitors.
It then gets all of the necessary data from each monitor object and converts and cleans the data and places it in a custom PSObject. It then adds
the data to an array. At the end the array is displayed.
@ShinNoNoir
ShinNoNoir / restart-docker-desktop.ps1
Last active July 7, 2020 04:04
Quick 'n Dirty script to fix Docker desktop startup issues
# Based on the steps listed here: https://github.com/docker/for-win/issues/6822#issuecomment-643563276
gsv com.docker.service | spsv
wsl --shutdown
$ubuntu = (Get-AppPackage *Ubuntu20.04*)
$fam = $ubuntu.PackageFamilyName
explorer "shell:AppsFolder\$fam!ubuntu2004"
@ShinNoNoir
ShinNoNoir / ProjectEuler14.js
Created April 28, 2020 05:34
Project Euler 14
// Project Euler 14, but in JS (longest Collatz chain for starting n < 1e6)
// Take a cup of ☕, this is going to take a while... (because it's slow)
function* collatzSeq(n) {
yield n;
if (n<=1) return;
yield* collatzSeq(n%2==0 ? n/2 : 3*n+1);
}
function seqLength(s) {
@ShinNoNoir
ShinNoNoir / SplitWhenPrev.hs
Created May 2, 2018 19:03
splitWhenPrev: A function somewhat similar to groupBy, but instead of using the first element of a group to determine when to start a new group, it compares adjacent values
{-# LANGUAGE LambdaCase #-}
import Data.List (unfoldr)
both :: (a -> b) -> (a,a) -> (b,b)
both f (x,y) = (f x, f y)
withPrevious :: [a] -> [(a, Maybe a)]
withPrevious xs = zip xs (Nothing : map Just xs)
@ShinNoNoir
ShinNoNoir / env.bat
Created October 5, 2017 07:30
vcpkg utility: set environment vars
@ECHO OFF
set VCPKGROOT=%~dp0
echo VCPKGROOT=%VCPKGROOT%
set TOOLCHAIN=%VCPKGROOT%scripts\buildsystems\vcpkg.cmake
echo TOOLCHAIN=%TOOLCHAIN%
FOR /D %%F IN (%VCPKGROOT%\downloads\cmake-*) DO (
set CMAKEDIR=%%F\bin
goto break
)
@ShinNoNoir
ShinNoNoir / netstat.ps1
Created September 12, 2017 06:34
Netstat wrapper in PowerShell
# from: https://blogs.technet.microsoft.com/heyscriptingguy/2015/08/19/parsing-netstat-information-with-powershell-5/
function ns {
return (netstat -ano).trim() | select -Skip 4 | ConvertFrom-String -PropertyNames Protocol,LocalAddress,RemoteAddress,State,Process
}
@ShinNoNoir
ShinNoNoir / opencv.autopkg
Created July 19, 2017 09:54
CoApp autopkg example for OpenCV
// https://github.com/coapp/coapp.powershell/issues/112
configurations {
Toolset {
key : "PlatformToolset";
choices: { v141 };
v141.condition = "( $(PlatformToolset.ToLower().IndexOf('v141')) > -1 Or '$(PlatformToolset.ToLower())' == 'windowskernelmodedriver8.0' Or '$(PlatformToolset.ToLower())' == 'windowsapplicationfordrivers8.0' Or '$(PlatformToolset.ToLower())' == 'windowsusermodedriver8.0' )";
};
}
@ShinNoNoir
ShinNoNoir / necklace.py
Created May 23, 2017 13:11
Number of necklaces (combinatorics)
# https://en.wikipedia.org/wiki/Necklace_%28combinatorics%29#Number_of_necklaces
from eulerlib import Divisors
def N(k, n):
divs = Divisors()
return sum( divs.phi(d) * k**(float(n)/d) for d in divs.divisors(n) ) / float(n)
@ShinNoNoir
ShinNoNoir / ThrottleManager.cs
Created September 7, 2016 10:17
Simple throttle utility
using System;
using System.Collections.Generic;
namespace Utilities
{
public class ThrottleManager
{
static Dictionary<object, DateTime> disabledUntil = new Dictionary<object, DateTime>();
public static bool Throttle(object key, int delay)
; AutoHotkey script for adding shortcuts for volume and next/prev controls
; using the Win (#), shift (+) and PgUp/PgDn keys:
#PgUp::Send {Volume_Up 3}
#PgDn::Send {Volume_Down 3}
#+PgDn::Send {Media_Next}
#+PgUp::Send {Media_Prev}