Skip to content

Instantly share code, notes, and snippets.

@snyderra
snyderra / generate-ca-bundle.py
Last active October 10, 2024 13:43
generate-ca-bundle.py
import ssl
import socket
import urllib.parse
from OpenSSL import SSL, crypto
def get_certificate_chain(hostname, port=443):
context = SSL.Context(SSL.SSLv23_METHOD)
context.set_verify(SSL.VERIFY_NONE, lambda *args: True)
conn = SSL.Connection(context, socket.socket(socket.AF_INET, socket.SOCK_STREAM))
import os
# os.environ['OAUTHLIB_INSECURE_TRANSPORT'] = '1'
from flask import Flask, request, jsonify
from requests_oauthlib import OAuth2Session
import uuid
import time
from cryptography import x509
from cryptography.x509.oid import NameOID
from cryptography.hazmat.primitives import hashes, serialization
from cryptography.hazmat.primitives.asymmetric import rsa
@snyderra
snyderra / smartcurl.sh
Last active October 9, 2024 12:50
Smart Card Curl on Macos
#!/bin/bash
#sudo port install opensc
#sudo port install curl
#sudo port install libp11
export OPENSSL_CONF=$(mktemp)
cat << EOF > $OPENSSL_CONF
openssl_conf = openssl_init
[openssl_init]
from pprint import pprint
import re
import json
def parse_records(records: str):
# see if we have any complete entries
beg = records.index(" # Host name")
end = records.rindex("============================================================================================")
if (beg > 0 and end > 0):
def getVersionCode(){
try {
def (major, minor, patch) = getVersionName().split('-')[0].tokenize('.')
(major, minor, patch) = [major, minor, patch].collect{it.toInteger()}
return (major * 1000000) + (minor * 10000) + (patch * 100)
}
catch (ignored) {
return -1;
}
}
Context context = view.getContext();
ContentResolver cr = context.getContentResolver();
ContentValues values;
try {
// create a file for test
File file = new File(context.getFilesDir(), "1234568");
file.createNewFile();
try (OutputStream os = new FileOutputStream(file)) {
os.write("test".getBytes());
// https://stackoverflow.com/a/60985346
private static String uniqueID = null;
private static final String PREF_UNIQUE_ID = "PREF_UNIQUE_ID";
public synchronized static String id(Context context) {
if (uniqueID == null) {
SharedPreferences sharedPrefs = context.getSharedPreferences(
PREF_UNIQUE_ID, Context.MODE_PRIVATE);
uniqueID = sharedPrefs.getString(PREF_UNIQUE_ID, null);
if (uniqueID == null) {
uniqueID = UUID.randomUUID().toString();
@snyderra
snyderra / debounce.kt
Created June 21, 2023 22:46 — forked from mirmilad/debounce.kt
Simple debounce extension for LiveData by using Coroutines
import androidx.lifecycle.LiveData
import androidx.lifecycle.MediatorLiveData
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
fun <T> LiveData<T>.debounce(duration: Long = 1000L, coroutineScope: CoroutineScope) = MediatorLiveData<T>().also { mld ->
val source = this
@snyderra
snyderra / start_cgi_http_server.sh
Created January 22, 2021 01:32 — forked from ohtomi/start_cgi_http_server.sh
File Upload CGI Script written in Python
#!/bin/bash
mkdir ./cgi-bin/
cp upload.cgi ./cgi-bin/
chmod +x ./cgi-bin/upload.cgi
mkdir ./upload/
python -m CGIHTTPServer 8080
@snyderra
snyderra / Microsoft-Teams-GPU-Fixer.sh
Created January 22, 2020 01:09 — forked from Cosmo/Microsoft-Teams-GPU-Fixer.sh
Disable GPU usage for Microsoft Teams
APP=TeamsFixer
mkdir -vp ${APP}.app/Contents/MacOS ${APP}.app/Contents/Resources
PATH="$PATH:/usr/libexec"
printf '#!/usr/bin/env bash\nexec /Applications/Microsoft\ Teams.app/Contents/MacOS/Teams --disable-gpu' > ${APP}.app/Contents/MacOS/${APP}
chmod +x ${APP}.app/Contents/MacOS/${APP}
cp /Applications/Microsoft\ Teams.app/Contents/Resources/icon.icns ${APP}.app/Contents/Resources/icon.icns
PlistBuddy ${APP}.app/Contents/Info.plist -c "add CFBundleDisplayName string ${APP}"
PlistBuddy ${APP}.app/Contents/Info.plist -c "add CFBundleIconFile string icon.icns"
PlistBuddy ${APP}.app/Contents/version.plist -c "add ProjectName string ${APP}"
find ${APP}.app