Skip to content

Instantly share code, notes, and snippets.

View alysbrooks's full-sized avatar

A Brooks alysbrooks

View GitHub Profile
@alysbrooks
alysbrooks / hiccup.fnl
Created October 27, 2021 22:35
Very simple hiccup implementation
(fn gen-attributes [attributes]
(clj.reduce (fn [x y] (.. x y))
(icollect [attr val (pairs attributes)]
(string.format " %s=\"%s\"" attr val))))
;
(fn render [form]
(if (clj.string? form) (EscapeHtml form)
(clj.vector? form) (let [tag (. form 1)
attributes (when (clj.map? (. form 2) ) (. form 2))
(defn get-thread-states []
(->> (Thread/getAllStackTraces)
(.keySet)
(into [] )
(mapv #(.getState %))
frequencies))
(defn futures-quit [n ms]
@alysbrooks
alysbrooks / README.md
Last active October 18, 2021 19:26
Hallway animation in Quil

This is copied from a larger project that lets you flip through multiple animations, so there's no defsketch here. If you want to get it up and running, you can insert the code into the fun-mode example.

The basic way this works is that we have a vector that basically determines the size of each square. Each frame, we make each one a bit bigger. Since larger objects appear closer and should look like they're moving faster, we want to make them a percentage bigger rather than a constant amount.

When using Quil and live reloading, the state tends to get out of whack, so I use a few tricks to help reset it if necessary:

  • initialized? and initialize-state functions that check if the state seems to be invalid, and reset it, respectively.
  • Binding the R key to a function that clears the state. This causes initialized? to be false and initialize-state to add the animation-specific starting state.
  • Namespaced keywords (notice the double
@alysbrooks
alysbrooks / gist:10218553
Last active August 29, 2015 13:58
Implementation of trees in Python
class Node:
def __init__(self, left, right):
self.left = left
self.right = right
def n(left=None, right=None):
"""Shortcut method for making a tree."""
return Node(left, right)
test = Node(n(), n())
#!/bin/sh
# aws_provision_dev.sh
# Setup and configure a server
EMBED=0
NAME=""
while getopts ie o
do case $o in
@alysbrooks
alysbrooks / numberWord.java
Created August 29, 2012 01:43
Print integers as words. (e.g. from '34' to 'thirty-four.')
class numberWord {
//Limited to numbers under 20,000.
//TODO punctuate properly
public static String spellOut(int n) {
if(n == 0) return "zero";
String output = "";
//This method relies on the fact Java drops the remainder of integer division
int thousands = n / 1000;
n -= thousands * 1000;
@alysbrooks
alysbrooks / Factorial_Recursive.java
Created March 24, 2012 05:32
Arbitrary precision factorial calculator using recursion
import java.util.Scanner;
import java.math.BigInteger; //For arbitrary precision arithmatic
public class Factorial {
public static BigInteger factorial(String input) {
//BigInteger means the program fails b/c of a stack overflow rather
//than an integer or long overflow. (Happens between 9000! and 10000!)
BigInteger result = new BigInteger(input);