Skip to content

Instantly share code, notes, and snippets.

View lizettepreiss's full-sized avatar

lizettepreiss

View GitHub Profile
@lizettepreiss
lizettepreiss / FDFParser.py
Last active January 20, 2023 03:59
How to parse a .fdf file in Python. The intention was to export comments I'd made in a .pdf (using Adobe Reader DC's commenting capability) and make them available elsewhere to use as a basis for further notes.
from pdfminer.pdfparser import PDFParser
from pdfminer.pdfdocument import PDFDocument
from pdfminer.pdftypes import resolve1
# I exported the comments I had made in an Adobe Reader DC document to f:temp/stn.fdf.
# Now I wanted to access those comments outside of the Adobe Reader. Here is how I extracted the comments.
fdf_file = open("F:/temp/stn.fdf", 'rb')
@lizettepreiss
lizettepreiss / SNMPTrapGenerator.java
Created May 5, 2016 12:44
SNMP Trap Generator. JAR Required: snmp4j.jar at http://www.snmp4j.org/html/download.html
package preiss;
import org.snmp4j.CommandResponder;
import org.snmp4j.CommandResponderEvent;
import org.snmp4j.CommunityTarget;
import org.snmp4j.PDU;
import org.snmp4j.PDUv1;
import org.snmp4j.ScopedPDU;
import org.snmp4j.Snmp;
import org.snmp4j.TransportMapping;
@lizettepreiss
lizettepreiss / python_list_tuple_dictionary.py
Last active April 15, 2020 12:38
Python List, Tuple, Dictionary syntax - simple examples.
# LIST
list = ["apple","orange","pear"]
for s in list:
print(s)
print(list[1])
# TUPLE
@lizettepreiss
lizettepreiss / GenericExample.java
Last active April 14, 2020 11:31
Java Generics Example
package java_examples;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
public class GenericExample {
/**
*
@lizettepreiss
lizettepreiss / LoggingTemplate_.idea_LoggingTemplate.iml
Created April 7, 2020 12:45
Python logger configuration that either logs to File; or alternatively logs both to File and Console
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="jdk" jdkName="Python 3.7 (LoggingTemplate)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="TestRunnerService">
<option name="PROJECT_TEST_RUNNER" value="Unittests" />
</component>
@lizettepreiss
lizettepreiss / SNMPTrapReceiver.java
Created May 5, 2016 12:39
SNMPTrapReceiver. JAR Required: snmp4j.jar at http://www.snmp4j.org/html/download.html
package preiss;
import java.io.IOException;
import java.net.UnknownHostException;
import java.util.Iterator;
import java.util.Vector;
import org.snmp4j.CommandResponder;
import org.snmp4j.CommandResponderEvent;
import org.snmp4j.MessageDispatcherImpl;
@lizettepreiss
lizettepreiss / DateToLocalDate.java
Created December 6, 2018 10:41
Java 8 – Convert java.util.Date to java.time.LocalDate
java.util.Date d = new java.util.Date();
java.time.LocalDate localDate = d.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
@lizettepreiss
lizettepreiss / MultilineStringSplitUsingRegex.java
Last active December 5, 2018 10:35
Using a Pattern to compile a regex for use instead of String.split()
import java.util.regex.Pattern;
public class MultilineStringSplitUsingRegex {
private static final Pattern pattern = Pattern.compile("\\r?\\n");
public static void main(String[] args) {
MultilineStringSplitUsingRegex m = new MultilineStringSplitUsingRegex();
String[] s1 = m.splitWithPattern();
String[] s2 = m.splitWithStringSplit();
}
@lizettepreiss
lizettepreiss / JSONParser.java
Last active October 30, 2018 15:00
Java JSON Parser: Recursively parse any JSON and print the output.
package preiss;
import java.util.Iterator;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
public class JSONParser {
public static void main(String[] args) {
@lizettepreiss
lizettepreiss / HTTPServer.java
Created October 30, 2018 14:34
HTTP Server
package preiss;
import com.sun.net.httpserver.Headers;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;