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 / 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() {
@haleyrc
haleyrc / rabinmiller.go
Created June 24, 2015 20:17
Rabin-Miller Primality Test
func BitsN(n int64) []int64 {
var bits []int64
bits = make([]int64, 0)
for {
if n == 0 {
return bits
}
bits = append(bits, n % 2)
n >>= 1
@haleyrc
haleyrc / memoize.py
Created December 3, 2012 22:20
Basic Memoization Class
class Memoize:
def __init__(self, func):
self.prevs = {}
self.func = func
def __call__(self, *args):
if not args in self.prevs:
self.prevs[args] = self.func(*args)
return self.prevs[args]