Skip to content

Instantly share code, notes, and snippets.

@kbhaines
kbhaines / witch.prolog
Last active August 29, 2015 14:08
Prolog Constraints Programming
?- use_module(library(clpfd)).
/*
Load: ['witch.prolog'].
Run: witch(5,Result).
*/
witch(Top, Vars) :-
Vars = [L1,L2,L3,L4,L5,L6,L7,L8,L9,L10,L11,L12,L13,L14,
L15,L16,L17,L18,L19,L20,L21,L22,L23,L24,L25],
@kbhaines
kbhaines / PrologExperiments
Created September 16, 2014 10:55
Experiments with Prolog for Constraints Programming
?- use_module(library(clpfd)).
/* type go(200, Answer) to run the program. 200 is the highest side */
/* length it will look for. */
go(Top, [L1,L2,L3,L4,L5,L6,L7,L8,L9,L10,L11,L12,L13,L14,
L15,L16,L17,L18,L19,L20,L21,L22,L23,L24,L25]) :-
/* Start the timer */
@kbhaines
kbhaines / BasicAuthFetch
Created August 15, 2014 14:29
Doing URL fetch with Basic authorization from AppEngine
@GET
@Path("/urlfetch/{url}")
public Response urlFetch(@PathParam("url") String userUrl) {
String result = "";
try {
URL url = new URL("https://" + userUrl);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
// Header is "Basic <base64 encoded username:password>"
// e.g. echo "kevin:password" | openssl env -base64 will give you this
@kbhaines
kbhaines / Watch
Last active August 29, 2015 14:01
File watch
#!/bin/sh
PREFIX=$1
while [ 1 ];do
for f in $PREFIX*;do
if ! lsof $f >/dev/null;then
echo $f is ready
# do something with it, then rm/mv it out of the way...
...
fi
@kbhaines
kbhaines / KeyRemap MacBook swap symbols & numbers
Last active January 9, 2018 20:30
Karabiner Configuration
<?xml version="1.0"?>
<root>
<item>
<name>Remap CapsLock to Hyper</name>
<appendix>OS X doesn't have a Hyper. This maps Left Control to Control + Shift + Option + Command.</appendix>
<identifier>space_cadet.left_control_to_hyper</identifier>
<autogen>
--KeyToKey-- KeyCode::F19, KeyCode::COMMAND_L, ModifierFlag::OPTION_L | ModifierFlag::SHIFT_L | ModifierFlag::CONTROL_L
# This is Kev's slate file
config defaultToCurrentScreen true
config nudgePercentOf screenSize
config resizePercentOf screenSize
config windowHintsIgnoreHiddenWindows false
config windowHintsShowIcons true
config windowHintsDuration 10
config focusPreferSameApp false