Skip to content

Instantly share code, notes, and snippets.

View dgunning's full-sized avatar

Dwight Gunning dgunning

View GitHub Profile
@dgunning
dgunning / SQLTempate.java
Last active December 18, 2017 02:32
A template for creating a new insert statement from an existing one in Java
package com.dgunning.testtools.sql;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.stream.IntStream;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toMap;
/**
* Gets an HTTP resource
* @param url the url
* @return an InputStream from the resource
*/
public static InputStream get(String url){
HttpClient client = HttpClientBuilder.create().build();
try {
return client.execute( new HttpGet(url)).getEntity().getContent();
} catch (IOException e) {
@dgunning
dgunning / DataFrameHolder
Created October 22, 2019 20:19
A delegate class for pandas dataframes .. an alternative to subclassing pandas dataframes
import pandas as pd
class DataFrameHolder:
def __init__(self, data: pd.DataFrame, title=''):
self.data = data
self.title = title
def __len__(self):
return len(self.data)
@dgunning
dgunning / BertFinetuning
Last active October 27, 2019 20:47
An example of finetuning a language model using the Huggingface Transformer library
mkdir -p output
# Install Transformers
pip install transformers
# Download the wikitext raw data files
if [ ! -d "wikitext-2-raw" ];
then
wget https://s3.amazonaws.com/research.metamind.io/wikitext/wikitext-2-raw-v1.zip
unzip wikitext-2-raw-v1.zip
fi
@dgunning
dgunning / get_filings_using_edgartools
Created October 10, 2023 11:02
Get SEC filings using edgartools
from edgar import *
# Tell SEC Edgar who you are
set_identity("First Last First.last@domain.com")
# Get filings - by default it gets the current quarter
filings = get_filings()
# Get filings for 2022
filings = get_filings(year=2020)
@dgunning
dgunning / get_current_sec_filings
Created October 21, 2023 12:24
Get the most recent filings including filings made after the 5:30 pm deadline
from edgar import *
# Get the current filings
filings = get_current_filings()
# Page through the filings
filings = filings.next()
# Select the filing you want
filing = filings[0]
@dgunning
dgunning / check_cert
Last active April 19, 2024 13:57
Check if a certificate exists
import sys
import certifi
from cryptography import x509
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.serialization import Encoding
def load_certificates_from_file(file_path):
"""Load all certificates from a file, automatically handling PEM and DER formats."""