Skip to content

Instantly share code, notes, and snippets.

View raymyers's full-sized avatar
🌳
Automating!

Ray Myers raymyers

🌳
Automating!
View GitHub Profile
@raymyers
raymyers / ShellSplitter.java
Last active April 7, 2024 19:11
Simple Java program to tokenize string as a shell would - similar to shlex in Python. Not checked for POSIX compliance yet - feel free to comment with edge cases that could be fixed. This is my original work, free to reuse. Created for Stack Overflow question: https://stackoverflow.com/questions/1082953/shlex-alternative-for-java/20725050:
package com.cadrlife;
import java.util.ArrayList;
import java.util.List;
public class ShellSplitter {
public List<String> shellSplit(CharSequence string) {
List<String> tokens = new ArrayList<String>();
boolean escaping = false;
char quoteChar = ' ';
@raymyers
raymyers / watchdir.py
Created October 25, 2011 00:17
Watch Directory For Changes (python)
import os, time, sys, fnmatch
path_to_watch = "D:/Projects/consumer-purchase-webapp/WebContent/js"
def findCoffeeFiles():
matches = []
for root, dirnames, filenames in os.walk(path_to_watch):
for filename in fnmatch.filter(filenames, '*.coffee'):
matches.append(os.path.join(root, filename))
return matches
import infomap
import littletable
import itertools
import json
from sentence_transformers import SentenceTransformer, util
# def simularity(functions):
@raymyers
raymyers / prompt.txt
Created January 26, 2024 14:17
RefactorGPT lablab Hackathon entry
You are an expert in software engineering including maintainability and refactoring.
You have studied under Marianne Belloti, Martin Fowler, and Llewellyn Falco.
For every block of source code you are given, suggest several opportunities for renames.
Suggestions should help make the code more clear and honest, without being more verbose than needed.
Only show suggestions, never the updated code.
Keep responses brief.
# Behavior
You are made to receive code. Every time you receive code, print only your Hot Keys! When a hot key is pressed, take only that action.

Layoff Logic

This is a tounge-in-cheek illustration of formal logic used refute the claim that high performers are never laid off, using that claim itself (made by an executive) as evidence that judgements are sometimes made without context.

In reality, there is no need to prove such an obvious point because by definition layoffs are not "for cause" terminations, the company has no legal responsibility to justify them as related to the impacted individuals.

Propositional Logic (Zeroth Order)

The proof proceeds by first assuming P1 and showing that it leads to contradiction.

@raymyers
raymyers / trimmedMean.js
Created February 14, 2020 16:15
Trimmed Mean and Median in ES6.
const mean = (values) => {
let sum = values.reduce((previous, current) => current += previous);
return sum / values.length;
};
const median = (arr) => {
const mid = Math.floor(arr.length / 2);
const sorted = [...arr].sort((a, b) => a - b);
return arr.length % 2 == 0 ? (sorted[mid - 1] + sorted[mid]) / 2 : sorted[mid];
};
@raymyers
raymyers / commit-msg
Last active August 28, 2023 18:10
Simple git hook enforcing Arlo Belshee's commit notation with hints, put in a repo as .git/hooks/commit-msg
#!/usr/bin/env python
import sys, os, re
from subprocess import check_output
# Collect the parameters
commit_msg_filepath = sys.argv[1]
allowed_prefixes = (
'f - ', 'F - ', 'F!! ', 'F**',
@raymyers
raymyers / Menderfile
Last active August 25, 2023 01:16
Mend Demo - August 2023
FROM 43a3a253
ENV DEFAULT_FILE=main.c
ENV UNTANGLER_DEFAULT_FILE=main.c
ENV JAVA_HOME=/Library/Java/JavaVirtualMachines/graalvm-jdk-20.0.2+9.1/Contents/Home/
ENV PATH="$PATH:/Users/rmyers/dev/untangler/build/install/untangler/bin"
## Aliases
RECIPE move_includes_to_top \
grep "^#include" $UNTANGLER_DEFAULT_FILE > a.tmp && \
@raymyers
raymyers / CharsetUtils.java
Created August 13, 2023 13:31
Wrap icu4j charset detection
package your.name;
import com.ibm.icu.text.CharsetDetector;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
@raymyers
raymyers / extract-metrics.js
Last active April 22, 2023 01:48
GPT4 generated code to extract metrics from GitHub, NOT debugged
// Warning: This code is LLM output and has NOT been debugged.
const { Octokit } = require("@octokit/rest");
// Initialize the Octokit client
const octokit = new Octokit({ auth: "your_personal_access_token" });
// Variables for your specific repository
const owner = "your_github_username";
const repo = "your_repository_name";