Skip to content

Instantly share code, notes, and snippets.

View mndrix's full-sized avatar

Michael Hendricks mndrix

View GitHub Profile
@mndrix
mndrix / pyfx.pas
Last active March 26, 2018 05:06
Toy language parser in Pascal taken from "The simple and powerful yfx operator precedence parser" by E. L. Favero. His code is intended to show how one can convert a Prolog DCG into an imperative language. The translation is straightforward and can be used to write a Prolog parser, with dynamic operator precedence, in an imperative language. I a…
program pyfx;
type int = integer;
bool = boolean;
str = string;
const fy = 1;
fx = 2;
yf = 3;
xf = 4;
xfy= 5;
@mndrix
mndrix / read-race.go
Created March 3, 2017 14:07
Can multiple goroutines read from a single map?
package main
// "go run -race read-race.go"
import (
"fmt"
"sync"
)
func main() {
@mndrix
mndrix / sample.txt
Created January 6, 2017 21:20
SWI-Prolog V7.3.34 pack_install sample
Sampling process 43655 for 3 seconds with 1 millisecond of run time between samples
Sampling completed, processing symbols...
Analysis of sampling swipl (pid 43655) every 1 millisecond
Process: swipl [43655]
Path: /Users/michael/lib/swipl-7.3.34/bin/x86_64-darwin15.6.0/swipl
Load Address: 0x101c2e000
Identifier: swipl
Version: 0
Code Type: X86-64
Parent Process: bash [41679]
@mndrix
mndrix / tmux.conf
Created December 20, 2016 17:52
tmux config for my workspace
# main: window where I spend most of my time
tmux rename-window main
# shells: window where spare shells live (see C-n and C-p)
new-window -d
rename-window -t 2 shells
split-window -d -t shells
split-window -d -t shells
@mndrix
mndrix / collatz.eve
Created December 9, 2016 12:56
Collatz Conjecture in Eve
# Collatz Conjecture
## Description
The Collatz Conjecture deals with an integer #`n` and the #`steps` it takes to reach 1.
```
commit
[#n]
[#step]
```
@mndrix
mndrix / append.go
Last active November 2, 2016 21:49
Compiling Prolog to Go
package prolog
/*
%% append(list,list,list)
%% append(+,+,+) is semidet.
%% append(+,+,-) is det.
%% append(+,-,+) is semidet.
%% append(+,-,-) is det.
%% append(-,+,+) is multi.
%% append(-,+,-) is multi.
@mndrix
mndrix / hello.ama
Last active October 31, 2016 18:25
Hello Amalog
use("amalog.org/std/io", Io); # See Note_use
main(W) {
Io.printf(W, "Hello, world!\n");
}
### Note_use:
`use/2` is a macro that expands into
@mndrix
mndrix / README.md
Last active October 28, 2016 18:59
Abandoned attempt at a nice Go package for PayPal's NVP API. That API is too much of an abomination to proceed
@mndrix
mndrix / scrape.prolog
Last active October 23, 2016 02:20
speculative sketch of a web scraper in Prolog with XPath, regular expressions and constraints
% The numerous inline comments are explanatory. Normal code wouldn't have them.
% I'm using double quotes to delineate raw text content. Real code would use
% a quasiquotation mechanism.
amazon_condition_overview(ASIN, Condition, BestPrice, Inventory, Section) :-
% HTTP GET the URL and parse it into a DOM structure
get(url("amazon.com/gp/offer-listing/$ASIN/?ie=UTF8"), DOM),
% build an atom representing the tab's node ID
TabId = qq("olpTab$Condition"),
@mndrix
mndrix / currency.pl
Created October 7, 2016 14:54
PriceCharting's Prolog library for currency amounts
:- module(currency, [ atom_currency/2
, codes_currency/2
, currency//1
]).
:- use_module(library(clpfd)).
:- use_module(library(dcg/basics), [integer//1]).
:- use_module(library(delay)).
:- use_module(library(error)).