Nothing Special   »   [go: up one dir, main page]

Skip to content

Instantly share code, notes, and snippets.

View prmichaelsen's full-sized avatar
🌚

Patrick Michaelsen prmichaelsen

🌚
  • Phoenix
  • 00:22 (UTC -07:00)
View GitHub Profile
@Log4j2
public class ImageUtility {
public MultipartFile removeExifAndApplyOrientation(MultipartFile file, String mimeType) throws Exception {
final BufferedImage image = ImageIO.read(file.getInputStream());
final Path tempDir = Paths.get(System.getProperty("java.io.tmpdir"));
final Path originalFile = Files.createTempFile(tempDir, "original-image-", "");
final String originalPath = originalFile.toAbsolutePath().toString();
final ByteArrayOutputStream originalBytes = new ByteArrayOutputStream();
// jpg is lossy, and in this case when we try to write the file out,
@prmichaelsen
prmichaelsen / canReachCorner.spec.ts
Created October 19, 2024 20:44
canReachCorner.ts
import { calcDist, canReachCorner, getRectIntersections, intersectsCircle, intersectsRect, isPointWithinBounds, solutionsForY, solutionsForX, getCircleIntersections } from "./leet";
describe('leet', () => {
describe('calcDist', () => {
it('calcs dist', () => {
expect(calcDist([0, 0], [0, 1])).toEqual(1);
});
function compareSemver(a: string, b: string) {
const aSemver = a.split('-')[1].split('.');
const bSember = b.split('-')[1].split('.');
for (let i = 0; i < 3; i++) {
const aPart = parseInt(aSemver[i], 10);
const bPart = parseInt(bSember[i], 10);
if (aPart > bPart) {
@prmichaelsen
prmichaelsen / jestDiff.ts
Last active August 20, 2024 13:05
This script generates test output files for each jest test so you can view the diffs in an external diff viewer
#!/usr/bin/env ts-node
import { spawn } from 'node:child_process';
import * as fs from "node:fs";
// This script generates test output
// files for each jest test so
// you can view the diffs in an external
// diff viewer
function sortByKey(obj: any): any {
// ==UserScript==
// @name Alt Click Copy
// @namespace http://tampermonkey.net/
// @version 0.1.0
// @description Alt click an HTML element on the page to copy it to your clipboard.
// @author mchpatr
// @match *://*/*
// @icon https://github.com/prmichaelsen/alt-click-copy/releases/download/alt-click-copy/save.icon.png
// @run-at document-start
// ==/UserScript==
@prmichaelsen
prmichaelsen / session.ts
Created June 5, 2024 18:23
example single command terminal exec using streams
import { Readable, Writable } from "node:stream";
import { spawn } from "node:child_process";
export const execCommand = async (cmd: string) => {
const ps = spawn("sh", { env: process.env });
const data: string[] = [];
const outputStream = new Writable({
write(chunk, encoding, callback) {
@prmichaelsen
prmichaelsen / rmrf.sh
Created May 21, 2024 21:28
Send your files to .trash instead of the void
rmrf () {
trash="$HOME/.trash"
mkdir -p $trash
if [ -z "$1" ]; then
echo "Usage: rmrf <dir>";
return 1
else
while [ -n "$1" ]
do
dir="$PWD/$1"
@prmichaelsen
prmichaelsen / gitf.sh
Created April 16, 2024 17:48
Git force push
gitf ()
{
prefix="dev/$USER/"
branch=$(git rev-parse --abbrev-ref HEAD)
if [[ "$branch" = $prefix* ]]; then
echo "[INFO]: Force pushing to branch '$branch'..."
git push origin ":$branch" ; git push origin -u "$branch"
else
echo "[INFO]: Cannot push to branch '$branch' because it does not match prefix '$prefix'."
}
@prmichaelsen
prmichaelsen / entity-readme.md
Created February 26, 2024 09:26
Entity definition

Let's examine the type for Entity.

export interface Model {};
export type Entity<
  TModels extends Model[],
> = {
  id?: string,
  creatorId?: string,
 createTimeMs?: number,
import { NonObject } from "./core-types";
export type DeepComplete<T> = T extends NonObject
? Exclude<T, undefined>
: T extends Array<infer U>
? DeepCompleteArray<U>
: T extends Map<infer K, infer V>
? DeepCompleteMap<K, V>
: DeepCompleteObject<T>;