Skip to content

Instantly share code, notes, and snippets.

@yuce
yuce / Makefile
Created October 4, 2013 18:11 — forked from ericbmerritt/Makefile
# Copyright 2012 Erlware, LLC. All Rights Reserved.
#
# This file is provided to you under the Apache License,
# Version 2.0 (the "License"); you may not use this file
# except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
@yuce
yuce / sample.py
Last active August 29, 2015 14:00
PySWIP Sample
from pyswip import Prolog
p = Prolog()
# something is fun if it is a car and it is red.
p.assertz('(fun(X) :- red(X), car(X))')
# facts...
p.assertz('car(vw_beatle)')
p.assertz('car(ferrari)')
p.assertz('car(hyundai)')
@yuce
yuce / sendmore.pl
Created May 3, 2014 19:52
Send more money in prolog
:- use_module(library('clp/bounds')).
sendmore(Digits) :-
Digits = [S,E,N,D,M,O,R,Y],
Digits in 0..9,
S #\= 0,
M #\= 0,
all_different(Digits),
1000*S + 100*E + 10*N + D
+ 1000*M + 100*O + 10*R + E
@yuce
yuce / 99-bottles-marvin.mar
Created May 3, 2014 20:03
99 Bottles on the wall in Marvin
99 ^beers
{
%beers 0 >
iftrue
" bottle(s) of beer" & dup " on the wall," & println
"." & println
"Take one down, pass it around," println
%beers -- ^beers
repeat
}
@yuce
yuce / 99-bottles-marvin3.m3
Created May 3, 2014 20:07
99 Bottles on the wall in Marvin3
:bottles dup dup 1 > [" bottles"] [" bottle"] ifte cat ;
:sing
bottles dup " of beer on the wall," cat println
" of beer. " cat println
"Take one down, pass it around." println ;
:theend "No more beer left." println ;
:beers [dup 0 >] [sing decr] while theend eat ;
@yuce
yuce / amarok-song-info-dcop.py
Created May 3, 2014 20:16
Amarok song info via DCOP
import pydcop
playerService = pydcop.DCOPObject('amarok', 'player')
d = dict(
title=playerService.title(),
artist=playerService.artist(),
album=playerService.album()
)
print '%(artist)s - %(title)s (%(album)s)' % d
@yuce
yuce / generate-all-strings.py
Created May 3, 2014 20:34
Generate all strings of a given alphabet
def allstrings(alphabet, length):
"""Find the list of all strings of 'alphabet' of length 'length'"""
if length == 0: return []
c = [[a] for a in alphabet[:]]
if length == 1: return c
c = [[x,y] for x in alphabet for y in alphabet]
if length == 2: return c
@yuce
yuce / link-checker.go
Created May 3, 2014 20:38
Go link checker
@yuce
yuce / infix.mar
Created May 3, 2014 20:41
Convert an infix expression to postfix (Marvin)
# infix.mar | Converts an infix expression into postfix
# This implementation uses the global variable space as a hash-table
# for operator precedence.
"listop forth dequeop" use
@|> globs & pushfrom ;
@string dfront NONE =
@yuce
yuce / infixoop.mar
Created May 3, 2014 20:44
OOP infix to postfix (Marvin)
# infixoop.mar | Converts an infix expression into postfix
# This implementation uses the object data as a hash-table
# for operator precedence.
"listop forth dequeop" use
@@Infix
@new # define the hash-table for operator precedence
FALSE ^++ ^+- ^-+ ^-- ^*+ ^*- ^** ^*/ ^/+ ^/- ^/* ://