Skip to content

Instantly share code, notes, and snippets.

View markscottwright's full-sized avatar

Mark Wright markscottwright

  • Washington, DC
View GitHub Profile
@markscottwright
markscottwright / .inputrc
Created November 14, 2021 04:14
VI mode inputrc
set editing-mode vi
set bell-style none
$if mode=vi
set keymap vi-command
"gg": beginning-of-history
"G": end-of-history
set keymap vi-insert
"kj": vi-movement-mode
"\C-w": backward-kill-word
"\C-p": history-search-backward
@markscottwright
markscottwright / QrCodeExtractor.java
Created September 23, 2021 19:57
How to extract the totp secret from a QR code
package scratch;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import javax.imageio.ImageIO;
import com.google.zxing.BinaryBitmap;
@markscottwright
markscottwright / Totp.java
Created September 23, 2021 16:27
How to do a totp in Java
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.time.Instant;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import org.apache.commons.codec.binary.Base32;
@markscottwright
markscottwright / gist:6b55d9b01d5769e9a7924dfaca40b4b5
Last active August 10, 2021 15:12
How to get an Azure Managed Identity token using curl
token=`curl -s 'http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&resource=https%3A%2F%2Fstorage.azure.com' -H Metadata:true | grep -o 'access.token[": ]\+[^"]\+' | sed s/access_token...//`
@markscottwright
markscottwright / movemouse.cpp
Last active September 29, 2020 20:53
How to move a mouse cursor to a particular monitor
#include <windows.h>
#include <stdio.h>
#include <string.h>
RECT monitors[100];
int numMonitors = 0;
BOOL SaveMonitorInfo(
HMONITOR Arg1,
HDC Arg2,
@markscottwright
markscottwright / DisableHttpSecurity.java
Created March 1, 2019 20:17
How to disable TLS certificate verification in java
package scratch;
import java.io.IOException;
import java.net.URL;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import javax.net.ssl.HttpsURLConnection;
@markscottwright
markscottwright / PKCS7.java
Last active June 16, 2024 15:27
How to create a PKCS7/CMS signature using BouncyCastle
package scratch;
import java.io.FileInputStream;
import java.io.IOException;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.Provider;
import java.security.Security;
@markscottwright
markscottwright / CertFetcher.java
Created December 12, 2018 17:41
How to fetch certificates from a TLS connection
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.UnknownHostException;
import java.security.KeyManagementException;
import java.security.KeyStore;
import java.security.KeyStoreException;
@markscottwright
markscottwright / SignedOfficeDocumentCerts.java
Created December 12, 2018 14:48
How to retrieve the signing certs and any attached chain of trust from a signed Office document.
package scratch;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
@markscottwright
markscottwright / DropTarget.java
Last active September 24, 2021 18:43
How to accept dropped files in Java Swing
package scratch;
import java.awt.BorderLayout;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;