Skip to content

Instantly share code, notes, and snippets.

View JoshData's full-sized avatar

Joshua Tauberer JoshData

View GitHub Profile
@JoshData
JoshData / WinFormsTreeViewDragDropWithDottedBoxAroundTarget.cs
Last active June 17, 2022 14:30
System.Windows.Forms TreeView Drag-Drop with Dotted Box Around Drop Target
using System;
using System.Drawing;
using System.Windows.Forms;
namespace WinFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
@JoshData
JoshData / gist:08cdd028f332c550fce2d3ba40d94396
Created April 9, 2021 18:45
is_point_on_line_segment in C++
// See if pt is between pt0 and pt1.
// via stackoverflow https://stackoverflow.com/a/328122
auto is_between = [](VertexType pt, VertexType p0, VertexType p1) {
auto z = (pt.y - p0.y) * (p1.x - p0.x)
- (pt.x - p0.x) * (p1.y - p0.y);
if (abs(z) > .0001) return false;
auto d = (pt.x - p0.x) * (p1.x - p0.x)
+ (pt.y - p0.y) * (p1.y - p0.y);
if (d < 0) return false;
auto n2 = (p1.x - p0.x) * (p1.x - p0.x)
@JoshData
JoshData / epapercmd.cpp
Last active November 10, 2024 13:21
Waveshare e-paper driver tool
/*
* A Waveshare E-Paper controller via a simple web API
*
* This C++ program creates a simple HTTP server to control a Waveshare
* e-Paper display, like the 10.3inch e-Paper e-Ink Display HAT For
* Raspberry Pi at https://www.waveshare.com/10.3inch-e-Paper-HAT.htm
* which I am using. This program is meant to be run on the Pi that is
* connected to the e-Paper display.
*
* When run, this program creates a simple web server that serves a
@JoshData
JoshData / zipcode_database.py
Last active February 14, 2021 05:57
Severless ZIP code database
# Pull ZIP code latitude/longitude coordinates from Geonames.org
# and write them out to a sharded flat-file database that makes
# it easy to efficiently query the database from the browser without
# any backend server. The Geonames database has a CC-BY license so
# credit must be given in the application.
#
# There are about 41,000 ZIP codes in the database, and with their
# lat/lng coordinate it's about 1MB of data, which a browser could
# load but it's kind of a lot of data for a browser to download and
# process. With state and place names, which might make for a nicer
@JoshData
JoshData / dropcasechanges.sh
Last active September 2, 2019 17:12
Discard changes in git working directory that are only changes in case
# This bash script can be used to drop changes in your git working directory that are only changes
# in upper/lowercase. This is useful if you are working on a case-insensitive document, such
# as a Visual Basic 6 source code file (ugh), and your tools accidentally change the case of
# words, but you want to revert that before making a commit. After this script finishes, your
# working directory has your changes except for those that were only changes in case.
#
# This script takes the following actions:
#
# 1) Use "git difftool" with "diff -i" to run a case-insensitive diff on the
# working directory and save that to a temporary patch file case_insensitive_changes.patch.
@JoshData
JoshData / self_signed_tls_cert_oneliner.sh
Created February 24, 2019 17:51
self-signed TLS/SSL certificate one-liner bash script
mkdir -p /etc/ssl/local \
&& (umask 077; openssl genrsa -out /etc/ssl/local/ssl_certificate.key 2048) \
&& openssl req -new -key /etc/ssl/local/ssl_certificate.key -out temp.csr -sha256 -subj "/CN=$HOSTNAME" \
&& openssl x509 -req -days 365 -in temp.csr -signkey /etc/ssl/local/ssl_certificate.key -out /etc/ssl/local/ssl_certificate.crt \
&& rm -f temp.csr
@JoshData
JoshData / demo_site.yaml
Created July 25, 2018 14:47
Example GovReady-Q "assemble" command YAML file
# GovReady-Q Command Line YAML file describing
# "Demo Website," a generic website, to produce
# a System Security Plan.
organization:
name: Demo Agency
app: ../govready-apps-dev/apps/generic-web-site
questions:
@JoshData
JoshData / comparison.md
Last active April 26, 2017 12:22
Immigration EO Comparison

This page shows a comparison of the executive orders on immigration posted on January 27, 2017 and March 6, 2017. Strikeout indicates portions deleted in the March 6 order. Underlining indicates portions added by the March 6 order. This comparison was made by GovTrack.us.


 January 27,March 06, 2017

Executive Order Protecting The Nation From Foreign Terrorist Entry Into The United States

By the authority vested in me as President by the Constitution and the laws of the United States of America, including the Immigration and Nationality Act (INA), 8 U.S.C. 1101 et seq., and section 301 of title 3, United States Code, and to protect the Ameri

@JoshData
JoshData / commonmark-tests.md
Last active February 9, 2017 15:59
Is your CommonMark renderer safe?

Potential CommonMark Exploits

This CommonMark file demonstrates some potential exploits if untrusted input is rendered with a compliant renderer. The point of this file isn't to say that CommonMark is unsafe --- the features below are very useful in many situations and are worth having in the CommonMark spec --- but that it is not safe to give untrusted input to CommonMark renderers without taking precautions.

Github doesn't render gists using CommonMark, so they won't appear as exploits below. Look at the source of this gist for the actual CommonMark.

Exploits

This link will execute a script.

@JoshData
JoshData / usps-state-abbrevs.txt
Created September 28, 2016 19:07
USPS state abbreviations for all addressable mail
# All state abbreviations for U.S. mail, from the USPS
# Postal Addressing Standards "Publication 28," May 2015,
# page 55.
#
# This list includes the 50 States, the District of Columbia,
# Puerto Rico, island territories, and overseas military addresses.
#
# source:
#
# http://pe.usps.gov/text/pub28/28apb.htm