Skip to content

Instantly share code, notes, and snippets.

@msfayed
msfayed / docker-compose.yml
Created March 14, 2025 18:57
automatically restart any unhealthy containers
services:
# source: https://stackoverflow.com/a/78212726
unhealthy_container_restarter:
image: docker:cli
network_mode: none
cap_drop:
- ALL
volumes:
- /var/run/docker.sock:/var/run/docker.sock
command: |
@msfayed
msfayed / dig.bat
Created October 5, 2023 12:34
calling Linux apps - WSL, just rename the file to the desired command
@echo off
SETLOCAL EnableExtensions
SETLOCAL DisableDelayedExpansion
set v_params=%*
set v_params=%v_params:\=/%
set v_params=%v_params:c:=/mnt/c%
REM v_params=%v_params:"=\"%
REM echo calling %~n0 %v_params%
set DISTRO=Ubuntu
C:\Windows\system32\wsl.exe -d %DISTRO% %~n0 %v_params%
@msfayed
msfayed / oauth2-oidc-client.cs
Created August 27, 2023 18:20
LIQPad oauth2-oidc-client to test https://github.com/msfayed/oauth2-oidc-mock or any OICD server
class Program
{
static async Task Main(string[] args)
{
var _usePKCE = false;
// ======================================
var clientId = "clientId";
var clientSecret = "clientSecret";
//_usePKCE = true; // for SPA/Mobile (without backend)
$hostName = $env:COMPUTERNAME # or the server name that you will use to connect
$hostIP=(Get-NetAdapter| Get-NetIPAddress).IPv4Address|Out-String
$srvCert = New-SelfSignedCertificate -DnsName $hostName,$hostIP -CertStoreLocation Cert:\LocalMachine\My
$srvCert
Export-Certificate -Cert $srvCert -FilePath 'C:\SSL_PS_Remoting.cer'
# import this certificate on the client machine
# Import-Certificate -FilePath c:\SSL_PS_Remoting.cer -CertStoreLocation Cert:\LocalMachine\root\
Get-ChildItem wsman:\localhost\Listener
SELECT CONNECTIONPROPERTY('net_transport') AS net_transport
,CONNECTIONPROPERTY('physical_net_transport') AS physical_net_transport
,SERVERPROPERTY ('ServerName') as ServerName
,SERVERPROPERTY ('Edition') as Edition
,SERVERPROPERTY ('ProductVersion') as ProductVersion
,CONNECTIONPROPERTY('local_net_address') AS local_net_address
,CONVERT(BIGINT,CONNECTIONPROPERTY('local_tcp_port')) + 65536 AS actual_tcp_port
,CONNECTIONPROPERTY('client_net_address') AS client_net_address
,CONNECTIONPROPERTY('auth_scheme') AS auth_scheme
,CONNECTIONPROPERTY('protocol_type') AS protocol_type
@msfayed
msfayed / Microsoft.PowerShellISE_profile.ps1
Created August 23, 2022 13:37
PowerShell ISE Toggle-Comment add-on
function Toggle-Comment
{
$file = $psise.CurrentFile
$textLines = $file.Editor.SelectedText.Split("`n",[System.StringSplitOptions]::None)
$result = ""
foreach ($line in $textLines)
{
if([String]::IsNullOrWhiteSpace($line) -ne $true)
{
@msfayed
msfayed / LogFile.udl.xml
Created March 15, 2022 14:48 — forked from mmdemirbas/LogFile.udl.xml
Custom log file syntax highlighting for Notepad++
<NotepadPlus>
<UserLang name="LogFile" ext="log">
<Settings>
<Global caseIgnored="yes" />
<TreatAsSymbol comment="no" commentLine="no" />
<Prefix words1="no" words2="no" words3="no" words4="no" />
</Settings>
<KeywordLists>
<Keywords name="Delimiters">[(0])0</Keywords>
<Keywords name="Folder+"></Keywords>
@msfayed
msfayed / cross-origin-local-storage.js
Created March 2, 2022 14:27 — forked from buren/cross-origin-local-storage.js
Cross origin local storage sharing example (using an iframe and postMessage)
const CrossOriginLocalStorage = function(currentWindow, iframe, allowedOrigins, onMessage) {
this.allowedOrigins = allowedOrigins;
let childWindow;
// some browser (don't remember which one) throw exception when you try to access
// contentWindow for the first time, it works when you do that second time
try {
childWindow = iframe.contentWindow;
} catch(e) {
childWindow = iframe.contentWindow;
@msfayed
msfayed / cloudflare-ddns-update.sh
Created February 9, 2022 19:47 — forked from Tras2/cloudflare-ddns-update.sh
A bash script to update a Cloudflare DNS A record with the external IP of the source machine
#!/bin/bash
# A bash script to update a Cloudflare DNS A record with the external IP of the source machine
# Used to provide DDNS service for my home
# Needs the DNS record pre-creating on Cloudflare
# Proxy - uncomment and provide details if using a proxy
#export https_proxy=http://<proxyuser>:<proxypassword>@<proxyip>:<proxyport>
# Cloudflare zone is the zone which holds the record
FROM alpine:3.11
ARG SERVICE_USER
ARG SERVICE_HOME
# Default Settings
ENV SERVICE_USER ${SERVICE_USER:-firefox}
ENV SERVICE_HOME ${SERVICE_HOME:-/home/${SERVICE_USER}}
RUN \
adduser -h ${SERVICE_HOME} -s /sbin/nologin -u 1000 -D ${SERVICE_USER} \