Skip to content

Instantly share code, notes, and snippets.

@pjt33
pjt33 / GolfScriptGolfer.java
Last active August 29, 2015 13:56
GolfScript golfer
import java.io.*;
import java.util.*;
public class GolfScriptGolfer {
public static void main(String[] args) throws Exception {
if (args.length == 1) {
String src = readFully(args[0]);
String golfed = golf(src);
String outputFile = (args[0].endsWith(".gs") ? args[0].substring(0, args[0].length() - 3) : args[0]) + ".min.gs";
@pjt33
pjt33 / wumpus-a5.gs
Last active August 29, 2015 14:00
Hunt the Wumpus; refactors of Dennis' code
##
0:DBGID;
{['"#{$stderr.puts Garray.new($stack).ginspect.to_s.slice(1..-2)#'DBGID):DBGID'
}"']''*~;}:DEBUG;
##
#[5:C,]{{.{[~@]}:>~.{-1%}:<~}%.&}8*({[.<><.<><]}:&~-{99rand}$~5,{.<[.>.>]{&~}%.3{$?~!!}:Q~"You smell a wumpus.\n"{*print}:,~.4Q"You feel a breeze.\n",'"#{'C):C';STDIN.gets()}"'++~~.10/3%@3%=\5%{&2Q"You killed the wumpus."{\<{>}3rand*\1"Your arrow didn't hit anything.\n",0}if}{\;.&3Q"You fell into the pit."*}if 1$&3Q{;"You were killed by the wumpus."}*:n!}do];
#[5:C,]{{.{[~@]}:>~.{-1%}:<~}%.&}8*({[.<><.<><]}:&~-{99rand}$~5,{.<[.>.>].{&3{$?~!!}:Q~'You smell a wumpus.\n'{*print}:,~}/.{&4Q'You feel a breeze.\n',}/'"#{'C):C';STDIN.gets()}"'++~~.10/3%@=\5%{&2Q'You killed the wumpus.'{\<{>}3rand*\1"Your arrow didn't hit anything.\n",0}if}{\;.&3Q'You fell into the pit.'*}if 1$&3Q{;'You were killed by the wumpus.'}*:n!}do];
#[5:C,]{{.{[~@]}:>~.{-1%}:<~}%.&}8*({[.<><.<><]}:&~-{99rand}$~5,{.<[.>.>].{3{$\&\?~!!}:Q~'You smell a wumpus.\n'{*print}:,~}/.{4Q'You feel a breeze.\n',}/'"#{'C):C';STDIN.gets()}"'++~~.
@pjt33
pjt33 / URLUtils.js
Last active August 29, 2015 14:02 — forked from Yaffle/URLUtils.js
/*jslint regexp: true, maxerr: 50, indent: 2 */
(function (global) {
"use strict";
function URLUtils(url, baseURL) {
var m = String(url).replace(/^\s+|\s+$/g, "").match(/^([^:\/?#]+:)?(?:\/\/(?:([^:@]*)(?::([^:@]*))?@)?(([^:\/?#]*)(?::(\d*))?))?([^?#]*)(\?[^#]*)?(#[\s\S]*)?/);
if (!m) {
throw new RangeError();
}
@pjt33
pjt33 / cairo-pentagonal.ps
Created August 9, 2014 08:53
Cairo pentagonal grid
%!PS-Adobe-2.0
%%Creator: Peter Taylor
% Force A4 portrait.
<</PageSize [595 842]>> setpagedevice
/hex {
currentpoint
8 14 rlineto
6 0 rlineto
8 -14 rlineto
@pjt33
pjt33 / AbstractLattice.java
Last active August 29, 2015 14:05
GenericLife
import java.awt.Point;
import java.util.*;
public abstract class AbstractLattice implements Tiling<AbstractLattice.LatticeCell> {
// Use the idea of expansion and vertex mapping from my earlier aperiod tiling implementation.
private Map<Point, Set<LatticeCell>> vertexNeighbourhood = new HashMap<Point, Set<LatticeCell>>();
private int scale = -1;
// Geometry
private final int dx0, dy0, dx1, dy1;
@pjt33
pjt33 / QuoridorCounter.java
Created October 10, 2014 14:36
Count Quoridor wall positions
import java.math.BigInteger;
import java.util.*;
public class QuoridorCounter {
public static void main(String[] args) {
List<String> rows = new ArrayList<String>();
char[] chs = new char[8];
for (int i = 0; i < 6561 /* 3^8 */; i++) {
int r = i;
for (int j = 0; j < 8; j++) {
using System;
using System.Collections.Generic;
using System.Linq;
namespace Sandbox {
// NB This is not really "production-quality" code
class Program {
static void Main(string[] args) {
for (int m = 2; m < 7; m++) {
for (int n = 2; n <= m; n++) {
@pjt33
pjt33 / gist:5898943
Last active December 19, 2015 04:39
PHP stacktrace in a loggable/echoable form.
$st = debug_backtrace();
$lineNo = '';
$stackTrace = '';
foreach ($st as $line)
{
if (isset($line['class'])) $stackTrace .= $line['class'].$line['type'].$line['function'].' at line '.$lineNo . "\n";
else $stackTrace .= $line['function'].' in '.$line['file'].' line '.$lineNo . "\n";
$lineNo = $line['line'];
}
@pjt33
pjt33 / Build subtitles
Last active December 19, 2015 21:39
Coursera video list: things to run in the console 1. Generate wiki markup for the subtitles page. 2. Generate a bash script to download the resources
$('a.lecture-link').each(function(){
var $lectureLink = $(this);
var lectureId = $lectureLink.data('lecture-id');
var title = $lectureLink.text().trim().replace(/ *\([0-9]+:[0-9]+\)/, '');
console.log('* ' + title + ' [[Scigast:Subtitles:Lecture' + lectureId + ':en|English]] | [[Scigast:Subtitles:Lecture' + lectureId + ':es|Español]]');
}),null;
@pjt33
pjt33 / PracticalNumbers.java
Last active December 22, 2015 23:29
Enumerator for practical numbers
package com.akshor.pjt33.math;
import java.util.*;
public class PracticalNumbers
{
public static void main(String[] args) {
Generator gen = new Generator();
// Print all practical numbers up to 30000
for (int pr = gen.next(); pr <= 30000; pr = gen.next()) {