Skip to content

Instantly share code, notes, and snippets.

View wchargin's full-sized avatar

Willow Chargin wchargin

View GitHub Profile
/etc/mdm/Xsession: Beginning session setup...
/etc/mdm/Xsession: 26: /home/wchargin/.profile: [[: not found
localuser:wchargin being added to access control list
Script for none started at run_im.
Script for auto started at run_im.
Script for default started at run_im.
Script for none started at run_im.
Script for auto started at run_im.
Script for default started at run_im.
GNOME_KEYRING_CONTROL=/run/user/1000/keyring-bapv8r
@wchargin
wchargin / LAFOptimizer.java
Created February 24, 2016 14:52
look-and-feel optimizer for swing
public class LAFOptimizer
{
/**
* Optimizes the look and feel to integrate with the operating system as
* much as possible.
* <p>
* To do this, this method at the installed look and feels and finds the
* system look and feel. If this is the same as the Metal look and feel, the
* method disables bold fonts to limit eyesores. If the element is the
// ...
final ActionListener listener = event -> {
if (working) {
return;
}
working = true;
solveButton.setEnabled(false);
solutionArea.setText("Computing solutions\u2026");
progress.setIndeterminate(true);
new SwingWorker<List<Map<Character, Integer>>, Void>() {
// ...
final ActionListener listener = event -> {
if (working) {
return;
}
working = true;
solveButton.setEnabled(false);
solutionArea.setText("Computing solutions\u2026");
progress.setIndeterminate(true);
new SwingWorker<List<Map<Character, Integer>>, Void>() {
@wchargin
wchargin / HistoryADT.java
Created March 5, 2016 16:09
an attempt at emulating algebraic data types in Java
import java.util.List;
class HistoryEvent {
private final HistoryEventItem item;
private static class HistoryEventItem {
}
private static final class WordPlayedItem extends HistoryEventItem {
private final int player;
private final List<String> wordsFormed;
public WordPlayedItem(int player, List<String> wordsFormed) {
@wchargin
wchargin / HistoryADT.hs
Created March 5, 2016 16:14
an example algebraic data type for a history event
data HistoryEvent = Play
{ tilesPlaced :: [Positioned LetterTile]
, wordsFormed :: [[Letter]]
, rawPoints :: Int
, pointsAfterSpecialTile :: Int
}
| Challenge { invalidWords :: [[Letter]] }
| Exchange { old :: [LetterTile], new :: [LetterTile] }
| Pass
@wchargin
wchargin / TextFixture.java
Created March 8, 2016 20:04
how do you *actually* find the ascent of a letter? not getAscent, that's for sure
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.font.GlyphVector;
import java.awt.geom.Rectangle2D;
import java.util.Arrays;
@wchargin
wchargin / shuffle.py
Created March 24, 2016 03:41
shuffling routines and automatic evaluation
"""Shuffling algorithms and tools for evaluating them."""
import collections
import math
import random
def fisher_yates(xs):
"""Generate a uniformly random permutation of the input list."""
n = len(xs)
for i in xrange(n):
idx = random.randint(i, n - 1)
@wchargin
wchargin / magic.sml
Created March 24, 2016 12:28
convenience functors for easily defining equality instances
functor MagicEq (eqtype t) : EQUAL where type t = t =
struct
type t = t
val equal : t * t -> bool = op =
end
functor MagicPairOfEq (structure E1 : EQUAL
structure E2 : EQUAL) : PAIR_OF_EQUAL =
struct
structure E1 = E1
@wchargin
wchargin / Queens.hs
Last active March 25, 2016 15:47
parallel and sequential n-queens in 40 lines
import System.Environment (getArgs)
import Control.Parallel.Strategies (parMap, rpar)
import Control.Monad (mplus, guard)
type Square = (Int, Int)
-- |threat p q|: is |p| queen-threatened by |q|?
threat :: Square -> Square -> Bool
threat (x, y) (x', y') =
x == x' || y == y' || x + y == x' + y' || x - y == x' - y'