Skip to content

Instantly share code, notes, and snippets.

@kevidently
kevidently / PastedImageHandler.js
Last active March 7, 2022 01:17
JS handler for pasted image data. Part of larger image processing lib. Allows pasting a copied image into a form input then displaying the image on the page.
export const handlePastedImage = (pasteEvent, stateUpdater) => {
// No support for clipboard API in MS Edge
// https://stackoverflow.com/questions/32113086/microsoft-edge-browser-how-to-read-clipboard-data
if (pasteEvent) {
pasteEvent.preventDefault();
pasteEvent.stopPropagation();
}
@kevidently
kevidently / FileMatcher.java
Last active January 17, 2022 17:08
File matching utility. Given two lists of files, matches files (using recursion/relative paths) and groups the files together.
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class Utils {
@kevidently
kevidently / LoginForm.cs
Last active January 17, 2022 17:06
Login form for Windows Forms application. User enters their windows domain name and password.
using System;
using System.Windows.Forms;
namespace Company.Project.DesktopApp.Dialogs {
public partial class UserLoginForm : Form {
private const string COMPANYDOMAIN = "company.com";
private MainForm mf;
@kevidently
kevidently / ConstrainImage.js
Last active March 7, 2022 01:05
JS Image Constrainer. Part of a larger image processing lib. The image is constrained to dimensions of a given container.
/**
* Returns an object with values to use for width and height that are constrained within the given dimensions.
* This works with a "landscape" type of container (width > height).
* Provides a maximum-sized image for the given container and preserves the aspect ratio.
*
* @param {number} originalImgWidth starting width of image to constrain
* @param {number} originalImgHeight starting height of image to constrain
* @param {number} constraintWidth width of container to fit image within
* @param {number} constraintHeight height of container to fit image within
* @return {object} object containing width and height values of constrained image