Skip to content

Instantly share code, notes, and snippets.

View donnfelker's full-sized avatar

Donn Felker donnfelker

View GitHub Profile
@donnfelker
donnfelker / disable_uploads_controller.js
Last active December 24, 2025 12:01
Images only and Disable Uploads for Lexxy Editor
import { Controller } from "@hotwired/stimulus"
export default class extends Controller {
connect() {
// Disable Lexxy uploads by preventing all file-accept events
document.addEventListener("lexxy:file-accept", function(event) {
console.log("file uploads not allowed")
event.preventDefault();
});
}
@donnfelker
donnfelker / CircularTransformation.java
Last active October 26, 2025 18:45
Picasso and CircularTransform Example
import android.graphics.*;
import com.squareup.picasso.Transformation;
/**
* Transforms an image into a circle representation. Such as a avatar.
*/
public class CircularTransformation implements Transformation
{
int radius = 10;
@donnfelker
donnfelker / prompt-enginering-course.py
Created May 22, 2025 21:34
ChatGPT Prompt Engineering for Developers
import openai
import os
from openai import OpenAI
client = OpenAI(api_key='<your-open-ai-key>')
def get_completion(prompt, model="gpt-4.1"):
completion = client.chat.completions.create(
@donnfelker
donnfelker / .zshrc
Created February 17, 2025 16:25
run_test - a shell script function that allows you to quickly run rails tests.
# Allows you to run a rails test from the CLI with:
#
# run_test "when x happens then abcd should happen"
#
# Which turns it into:
# rails test --name "/^test_when_x_happens_then_abcd_should_happen$/"
#
run_test() {
# Check if a test description was provided
if [ -z "$1" ]; then
@donnfelker
donnfelker / send_message.rb
Created October 15, 2024 10:45
Ruby Telegram Bot Message Script
# TelegramMessenger Usage
# Replace 'YOUR_BOT_API_TOKEN' and 'CHAT_ID' with your actual bot token and chat ID
bot_token = 'your-bot-token'
chat_id = 'your-chat-id'
# Create an instance of the TelegramMessenger class
telegramer = TelegramMessenger.new(bot_token, chat_id)
# Create a multi-line string for the message
@donnfelker
donnfelker / getDailyQuota.gs
Last active August 29, 2024 15:25
Gmail Contacts from Label to Sheets
function getDailyQuota() {
var quotaRemaining = MailApp.getRemainingDailyQuota()
console.log("Daily Quota Remaining: " + quotaRemaining);
}
@donnfelker
donnfelker / index.html
Created May 12, 2024 21:42
Editor.js Image Example Test - for Images
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Image Tool Example</title>
<script src="https://cdn.jsdelivr.net/npm/@editorjs/editorjs@latest"></script>
<script src="https://cdn.jsdelivr.net/npm/@donnfelker/editor-js-image@latest"></script>
</head>
<body>
@donnfelker
donnfelker / build.gradle
Last active January 12, 2024 17:49
gradle properties in Android Studio
// Other build stuff
task ndkBuild(type:Exec) {
if(androidNdkPath != null) {
def ndkBuild = new File(androidNdkPath, 'ndk-build')
commandLine ndkBuild
} else {
// do something else
}
}
@donnfelker
donnfelker / .gitconfig
Last active December 3, 2023 14:16
Git and Fish
[user]
name = Your Name
email = you@youremail.com
[alias]
A = add -A
a = add
aa = add --all
ae = add --edit
ai = add --interactive
amend = commit --amend -C HEAD
@donnfelker
donnfelker / ReceivedCookiesInterceptor.kt
Created October 28, 2023 16:50
OkHttp Cookie Response Interceptor
package com.example.android.http
import android.webkit.CookieManager
import com.example.android.util.BASE_URL // https://example.com/
import logcat.logcat
import okhttp3.Cookie
import okhttp3.HttpUrl.Companion.toHttpUrl
import okhttp3.Interceptor
import okhttp3.Response
import okio.IOException