Skip to content

Instantly share code, notes, and snippets.

View primaryobjects's full-sized avatar

Kory Becker primaryobjects

View GitHub Profile
@primaryobjects
primaryobjects / bf_to_c
Last active August 29, 2015 14:13
BF to C Converter (source at https://github.com/matslina/bfoptimization). Change line 74 to convert your own BF code: ir_to_c(bf_to_ir("+++.")). Example output from this program https://ideone.com/z16KPJ.
from collections import namedtuple
# These map directly to the 8 regular brainfuck instructions. The
# exception is the offset parameter, which would be 0 in regular
# brainfuck, but can here indicate an offset from the current cell at
# which the operation should be applied.
Add = namedtuple('Add', ['x', 'offset'])
Sub = namedtuple('Sub', ['x', 'offset'])
Right = namedtuple('Right', ['x'])
Left = namedtuple('Left', ['x'])
@primaryobjects
primaryobjects / domain-grammar.txt
Last active August 23, 2022 14:45
Attempt at a basic STRIPS PDDL grammar parser for pegjs.org. To use, visit http://pegjs.org/online and paste the below grammar into the left-side window. In the right-side window, paste a PDDL domain file, such as https://spark-public.s3.amazonaws.com/aiplan/resources/random-domain.txt. The output will display in the Output panel.
/*STRIPS PDDL parser for http://pegjs.org/online
For example of parsing this grammar, see https://gist.github.com/primaryobjects/1d2f7ee668b62ca99095
Example PDDL domain to parse:
(define (domain random-domain)
(:requirements :strips)
(:action op1
:parameters (?x1 ?x2 ?x3)
:precondition (and (S ?x1 ?x2) (R ?x3 ?x1))
:effect (and (S ?x2 ?x1) (S ?x1 ?x3) (not (R ?x3 ?x1))))
@primaryobjects
primaryobjects / parser.js
Last active August 29, 2015 14:14
Javascript parser for STRIPS PDDL grammar parser from pegjs.org. This code parses the result of the pegjs grammar produced from the file grammar.txt https://gist.github.com/primaryobjects/22363e71112d716ea183 and returns a JSON object with the action operators, conditions, and effects.
/*
grammar.txt: saved from https://gist.github.com/primaryobjects/22363e71112d716ea183
domain.txt:
(define (domain random-domain)
(:requirements :strips :typing)
(:action op1
:parameters (?x1 ?x2 ?x3)
:precondition (and (S ?x1 ?x2) (R ?x3 ?x1))
:effect (and (S ?x2 ?x1) (S ?x1 ?x3) (not (R ?x3 ?x1))))
(:action op2
@primaryobjects
primaryobjects / pddl.json
Last active August 28, 2022 08:43
Output from parsing PDDL STRIPS grammar, using pegjs parser. The PDDL grammar (https://gist.github.com/primaryobjects/22363e71112d716ea183) has been parsed and run against a pddl domain (https://spark-public.s3.amazonaws.com/aiplan/resources/random-domain.txt) and the output has been converted to json. See https://gist.github.com/primaryobjects/…
{
"domain":"random-domain",
"requirements":[
"strips",
"typing"
],
"actions":[
{
"action":"op1",
"parameters":[
@primaryobjects
primaryobjects / problem-grammar.txt
Created January 27, 2015 04:59
PEGjs grammar for parsing a PDDL STRIPS domain problem.
/*
pegjs grammar for parsing a PDDL STRIPS domain problem. Example problem:
(define (problem random-pbl1)
(:domain random-domain)
(:init
(S B B) (S C B) (S A C)
(R B B) (R C B))
(:goal (and (S A A))))
*/
@primaryobjects
primaryobjects / app.js
Created February 24, 2015 03:15
Planning graph using the strips node.js library.
var strips = require('strips');
var util = require('util');
// Load the domain and problem.
strips.load('./domain-cake.pddl', './problem-cake.pddl', function(domain, problem) {
var S = [];
// S0 - 1 node per literal in initial state.
for (var i in problem.states[0].actions) {
var literal = problem.states[0].actions[i];
@primaryobjects
primaryobjects / run.bat
Created February 24, 2015 14:41
DOS batch file to launch a NodeWebKit app. NodeWebKit has a habit of occasionally immediately quitting when trying to launch it. This script times the launch and quit times, so if the app exits in less than 5 seconds, we re-launch the app, until we finally get a proper launch.
@echo off
:loop
:: Start timer.
@set /A _tic=%time:~0,2%*3600^
+%time:~3,1%*10*60^
+%time:~4,1%*60^
+%time:~6,1%*10^
+%time:~7,1% >nul
@primaryobjects
primaryobjects / deploy_node_site.txt
Last active August 29, 2015 14:16
4 easy steps to deploy a node.js web site to a Windows server.
1. Download and install node.js at http://nodejs.org/download/
2. Copy your node.js project files to C:\Users\YOUR_USERNAME\Documents\SITENAME
3. Open Windows Firewall port 80.
4. Open Windows Powershell and type:
$env:PORT = 80
cd C:\Users\YOUR_USERNAME\Documents\SITENAME
@primaryobjects
primaryobjects / minify.js
Last active August 29, 2015 14:16
3 Tools for Minifying Your Web Project
/*
html-minifier
https://www.npmjs.com/package/html-minifier
UglifyCSS
https://github.com/fmarcia/UglifyCSS
UglifyJS2
https://github.com/mishoo/UglifyJS2
@primaryobjects
primaryobjects / info.txt
Last active August 29, 2015 14:16
Razor Syntax for node.js views using Vash view engine.
Razor Syntax for node.js views
https://github.com/kirbysayshi/vash#syntax-example
Example Controller:
exports.page = function(req, res) {
res.render('page.vash', { name: 'John Doe', colors: [ 'red', 'green', 'blue' ] });
};
Example Views: