Skip to content

Instantly share code, notes, and snippets.

@pjt33
pjt33 / GolfScriptGolfer.java
Last active Aug 29, 2015
GolfScript golfer
View GolfScriptGolfer.java
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 Aug 29, 2015
Hunt the Wumpus; refactors of Dennis' code
View wumpus-a5.gs
##
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()}"'++~~.
View 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 Aug 9, 2014
Cairo pentagonal grid
View cairo-pentagonal.ps
%!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
View AbstractLattice.java
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 Oct 10, 2014
Count Quoridor wall positions
View QuoridorCounter.java
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++) {
View A263542.cs
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 Dec 19, 2015
PHP stacktrace in a loggable/echoable form.
View gist:5898943
$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 Dec 19, 2015
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
View Build subtitles
$('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 Dec 22, 2015
Enumerator for practical numbers
View PracticalNumbers.java
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()) {
You can’t perform that action at this time.