Skip to content

Instantly share code, notes, and snippets.

@haleyrc
haleyrc / quadrants.js
Created April 11, 2024 15:48
A four-pane layout for Amethyst
function layout() {
return {
name: "Quadrants",
getFrameAssignments: (windows, screenFrame) => {
const columnWidth = screenFrame.width / 2;
const rowHeight = screenFrame.height / 2;
const frames = windows.map((window, index) => {
const frame = {
x: screenFrame.x + (columnWidth * (index % 2)),
y: screenFrame.y + (index < 2 ? 0 : rowHeight),
@haleyrc
haleyrc / dragondrop.html
Created January 30, 2024 16:46
A basic demo of drag and drop with pure JS
<!doctype html>
<html>
<head>
<title>Dragon Drop</title>
<style>
:root {
--background-color: #181824;
--text-color: #fff;
--scrollbar-thumb-color: #fff;
@haleyrc
haleyrc / deleteme2
Created October 12, 2023 19:23
A dummy file for testing
Hello from deleteme2
@haleyrc
haleyrc / delaywriter.go
Created January 14, 2021 23:15
A simple wrapper around io.Writer that supresses output until a check function returns true. Could be useful when running a noisy command with exec.Cmd to keep it quiet until some pre-determined bit of output (think using Go to run a React application).
package main
import (
"fmt"
"io"
"os"
"strings"
)
func main() {
package demo_test
import (
"testing"
"github.com/frazercomputing/f4/demo"
)
func TestToUpper(t *testing.T) {
t.Parallel()
@haleyrc
haleyrc / gettitle.go
Created December 26, 2019 17:43
A quick and dirty way to get a webpage title in Go.
package main
import (
"fmt"
"io/ioutil"
"net/http"
"regexp"
)
func main() {
@haleyrc
haleyrc / throttledebounce.go
Last active March 27, 2024 05:31
Throttle and debounce implemented in Go
// This gist is a reminder to myself about the differences between throttling and debouncing, inspired by
// https://redd.one/blog/debounce-vs-throttle
//
// A runnable example is available here: https://play.golang.org/p/sADDu829fRa
package main
import (
"fmt"
"time"
)
@haleyrc
haleyrc / goodbye.py
Created April 16, 2019 21:01
Demonstration of merging text onto existing pdf
from PyPDF2 import PdfFileWriter, PdfFileReader
import StringIO
from reportlab.pdfgen import canvas
from reportlab.lib.pagesizes import letter
# Create a new PDF with the text to overlay
packet = StringIO.StringIO()
can = canvas.Canvas(packet)
can.drawString(200, 100, "Goodbye World")
can.save()
@haleyrc
haleyrc / mapkeys.go
Created March 22, 2019 14:27
A reminder that complex map keys do exist
// This gist is a reminder to don't be like me and forget that you can
// use complex keys for maps.
//
// https://play.golang.org/p/KCJ58WH2jU-
package main
import "fmt"
func main() {
// Before continuing to the details, confirm for yourself that
@haleyrc
haleyrc / logger.go
Last active March 13, 2019 13:46
An experiment in safer logging.
// This gist is an experiment toward safer logs that don't leak PII or secrets. We present three different logging
// implementations and outline the pros and cons of both. Ultimately, however, the "safeish" version provides the
// best mix of developer-friendliness and safety.
//
// Note that none of the safety mechanisms here apply in cases where fields of a data type are logged directly, but
// if log.Printf(data.Password) passes code review, there are other problems.
//
// A runnable version of this is available at:
// https://play.golang.org/p/_jePSMkWM1O
package main