Skip to content

Instantly share code, notes, and snippets.

@stenno
stenno / Ruby Proxy
Created March 31, 2011 13:39
Proxy in Ruby, very dirty
#Proxy in Ruby, very dirty, supports chunking (kinda), don't expect it to work
#OOP version will be available soon
#See it as an example ... ;)
require 'net/http'
require 'uri'
TCPServer.open("127.0.0.1", 55555) do |server|
s = server.accept
req = s.recvfrom(4096)
@stenno
stenno / test_xlogfile
Created May 17, 2011 11:50
xlogfile test
version=3.4.3:points=2354147:deathdnum=7:deathlev=-5:maxlvl=51:hp=215:maxhp=227:deaths=0:deathdate=20100614:birthdate=20100613:uid=5:role=Pri:race=Hum:gender=Mal:align=Law:name=demirobin:death=ascended:conduct=2048:turns=36831:achieve=2047:nconducts=1:nachieves=11:realtime=55203:starttime=1276447456:endtime=1276521554:gender0=Mal:align0=Neu:flags=0
version=3.4.3:points=2046073:deathdnum=7:deathlev=-5:maxlvl=50:hp=180:maxhp=192:deaths=0:deathdate=20100615:birthdate=20100614:uid=5:role=Arc:race=Dwa:gender=Mal:align=Law:name=demirobin:death=ascended:conduct=1280:turns=24658:achieve=4095:nconducts=2:nachieves=12:realtime=41863:starttime=1276521658:endtime=1276566751:gender0=Mal:align0=Law:flags=0
version=3.4.3:points=535:deathdnum=0:deathlev=4:maxlvl=4:hp=0:maxhp=15:deaths=1:deathdate=20100615:birthdate=20100615:uid=5:role=Cav:race=Gno:gender=Mal:align=Neu:name=demirobin:death=killed by a gecko, while fainted from lack of food:conduct=3968:turns=1457:achieve=0:nconducts=5:nachieves=0:realtime=1203:starttime=12765
@stenno
stenno / gist:1240714
Created September 25, 2011 15:20
Connecting to nethack.eu via ruby and socket
require 'socket'
$TELNET_BUFFER = 4096
class Connection
attr_reader :neusock
def self.init
@neusock = TCPSocket.new("nethack.eu", 23)
handshake = [0xff, 0xfb, 0x18, 0xff, 0xfa, 0x18, 0x00, 'x', 't', 'e', 'r', 'm', 0xff, 0xf0, 0xff, 0xfc, 0x20, 0xff, 0xfc, 0x23, 0xff, 0xfc, 0x27, 0xff, 0xfe, 0x03, 0xff, 0xfb, 0x01, 0xff, 0xfd, 0x05, 0xff, 0xfb, 0x21, 0xff, 0xfb, 0x1f, 0xff, 0xfa, 0x1f, 0x00, 0x50, 0x00, 0x18, 0xff, 0xf0]
#from https://github.com/canidae/saiph/blob/master/src/Telnet.cpp
handshake = handshake.map{|c| c.class == Fixnum ? c.chr : c}.join

#nitrohack.js

nitrohack.js provides a javascript client for nitrohack_server.

This basically allows to play NetHack using javascript. All communication is wrapped in javascript functions, and hooks for message and event callbacks are provided. nitrohack.js also stores and keeps track of the current game state, for example the map and attributes.

@stenno
stenno / gist:8d3a72356dd52de58081b038523467c9
Last active December 16, 2018 14:04
eq eq german translation
{
"JavaScript Equality Table Game": "JavaScript Gleichheitstabellenspiel",
"Language": "Sprache",
"About": "Über",
"Help": "Hilfe",
"Restart": "Neu starten",
"How well do you know": "Wie gut kennst Du",
"in JavaScript?": "in JavaScript?",
"Test your mettle against what's considered a textbook example of a confusing language design flaw – JavaScript's loose equality operator.": "Teste Dein Wissen über ein Paradebeispiel eines verwirrenden Sprachdesigns: Javascripts `loose equal`-Operator",
"Flag all cells where the values are loosely equal according to": "Markiere alle Zellen, in denen die Werte `loose equal` sind: ",
@stenno
stenno / server.js
Created February 4, 2019 20:12
low level API for nethack in node.js
// https://nethackwiki.com/wiki/Vt_tiledata
const pty = require("node-pty");
const AnsiTerminal = require("node-ansiterminal").AnsiTerminal;
const AnsiParser = require("node-ansiparser");
const WAITING_DELAY = 100; // a short delay to capture all neccessary data
// we monkeypatch AnsiTerminal for vt_tiledata support
@stenno
stenno / ttywindows.js
Last active February 6, 2019 00:52
NetHack tty windows
const coreTTYWindows = [{
name: "message",
internalName: "NHW_MESSAGE",
id: windowIds.NHW_MESSAGE,
description: "Message window, 1 line long, very wide, top of screen",
resize: (baseDimensions) => {
return { rows: msgHistory, cols: 0, maxRows: 0, maxCols: 0 }
}
}, {
name: "status",
@stenno
stenno / playground.js
Last active February 10, 2019 16:17
Nethack API Frontend WIP
const NethackAPI = require("./nethackapi");
const nethackAPI = new NethackAPI();
// lazy top-level await
(async () => {
// connect to HDF
await nethackAPI.loginSSH("stenno", "not my password", "nethack@eu.hardfought.org");
@stenno
stenno / asyncExample.js
Created February 11, 2019 23:09
async generator example
async doANSIInput(data) {
this.session.prepareForInput();
const terminal = await this.session.rawInput(data, WAITING_DELAY);
const ANSIWindow = terminal.getANSICells();
return ANSIWindow;
}
async* batchANSIInput(commands) {
@stenno
stenno / tiledata.js
Created February 16, 2019 14:08
vt_tiledata returned from HDF-3.6.2
tiledata got [ 1, 2, 3 ] z { col: 73, row: 4 }
tiledata got [ 1, 2, 1 ] z { col: 73, row: 4 }
tiledata got [ 1, 2, 3 ] z { col: 0, row: 0 }
tiledata got [ 1, 2, 1 ] z { col: 73, row: 4 }
tiledata got [ 1, 2, 0 ] z { col: 0, row: 0 }
tiledata got [ 1, 3 ] z { col: 39, row: 0 }