Skip to content

Instantly share code, notes, and snippets.

View Pet3ris's full-sized avatar
🎯
Focusing

Peteris Erins Pet3ris

🎯
Focusing
View GitHub Profile
@Pet3ris
Pet3ris / README.md
Created August 18, 2011 18:01
arrowmania

arrowmania

A copy and improvement (with appropriate Unicode characters inserted) of a deleted Project Fortress (programming language) wiki entry describing conventions for converting unicode arrows to valid ASCII operators.

The document was originally created by members of the Project Fortress community, I am only copying it here as it might be of interest for other programmers.

@Pet3ris
Pet3ris / post.clj
Created September 11, 2011 11:44
Problems with clj-http POST
(ns app.main
(:require [clj-http.client :as client]))
(:body (client/post "http://api.pgconsulting.se/Lgf/HcpList.aspx"
{:query-string
"__EVENTTARGET=pagerTop%24ctl01%24ctl01&__VIEWSTATE=%2FwEPDwUJMjUxNzIwMTU4ZBgDBQtwYWdlckJvdHRvbQ8UKwAEZGQCZALLBGQFCWx2UGxheWVycw8UKwAOZGRkZAUIUGxheWVySWRkZDwrAGQAAssEZGRkZgJkZAUIcGFnZXJUb3APFCsABGRkAmQCywRkqC8J3cgNWv4zyxO8CIdJjnTs5bnf8y3HEJ584oWXkuM%3D&__EVENTVALIDATION=%2FwEWHQKl4aiPCAK1rL%2FwCQKlw5WeBQK6w5WeBQK7w5WeBQK8td%2BsDwKqrNeNDAKqrJPMCwLHzJCiBALHzNSQCgLHzOjrAgLHzKzaCALHzMC1AQLHzJDKCwLHzKSlBALwzIqDBQLvzIqDBQLuzIqDBQLyzIqDBQL1zIqDBQL0zIqDBQLzzIqDBQLZ%2FrmpAQKIw%2BDpAgKjrP7%2BDAKqupPpDwLFo7H%2BCQLZlpyUBwL0%2F7mpAVQBXtWtanOjitkIqvhLDBWDDcdkqHZ6BIpx%2F%2BNSj96e"
}))
@Pet3ris
Pet3ris / parse.py
Created September 14, 2011 10:55
Quick & dirty meetup list parsing
import re
content = open('./Desktop/meetup list.htm', 'r').read()
members = re.findall('<tr id="mem.*?</tr>', content, re.DOTALL)
people = []
count = 0
for member in members:
@Pet3ris
Pet3ris / sokuza-kanren.scm
Created December 22, 2011 19:29
Mini-kanren like logic programming in Scheme
; Quick miniKanren-like code
;
; written at the meeting of a Functional Programming Group
; (Toukyou/Shibuya, Apr 29, 2006), as a quick illustration of logic
; programming. The code is really quite trivial and unsophisticated:
; it was written without any preparation whatsoever. The present file
; adds comments and makes minor adjustments.
;
; $Id: sokuza-kanren.scm,v 1.1 2006/05/10 23:12:41 oleg Exp oleg $
@Pet3ris
Pet3ris / fsm.clj
Created January 25, 2012 13:27
Finite State Machine in Clojure core.logic
(ns fsm
(:refer-clojure :exclude [==])
(:use [clojure.core.logic]))
;; Encoding a Finite State Machine and recognizing strings in its language in Clojure core.logic
;; We will encode the following FSM:
;;
;; (ok) --+---b---> (fail)
;; ^ |
@Pet3ris
Pet3ris / fsmparse.clj
Created January 27, 2012 12:45
Finite State Machines: jumps, flexible transitions and parsing
(ns fsmparse
(:refer-clojure :exclude [==])
(:use [clojure.core.logic]))
;; We will encode a state machine that accepts lists containing '(w h y) as a sublist
;; Moreover, instead of a recognizer, we will implement a parser, that returns a list
;; of visited states in order
;;
;; +----#-----+----#-----+ +--?--+
;; v | | v |
@Pet3ris
Pet3ris / fst.clj
Created February 25, 2012 13:02
Finite State Transducers: English pluralization
(ns fst
(:refer-clojure :exclude [==])
(:use [clojure.core.logic]))
;; A finite state transducer is essentially a translator between
;; two tapes of symbols. It is normally a translator from an input
;; tape to an output tape, but since we are using core.logic,
;; we hope to relax this restriction :).
;; The main idea is that every transition accepts two symbols
@Pet3ris
Pet3ris / chain.hs
Created August 11, 2012 17:24
Comparison chaining for a blog post
import Data.Monoid
chain :: (Ord a) => [a] -> [a] -> Ordering
chain xs = mconcat . (zipWith compare xs)
chain [1, 2, 3] [1, 2, -1]
-- GT
chain [1, 2, 3] [1, 2, 3]
-- EQ
@Pet3ris
Pet3ris / scalatoprolog.md
Created September 15, 2012 16:33 — forked from jonifreeman/scalatoprolog.md
Scala type system -> Prolog
@Pet3ris
Pet3ris / cond.pl
Created October 5, 2012 22:42
rejection sampling conditioner in prolog
% Two dices are thrown and the results added up.
% We sample when the sum is conditioned on the first dice landing on 2.
output(S) :-
randvar(a, dice(X), X),
dice(Y),
S is X + Y.
dice(X) :-
X is random(6) + 1.