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 / 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 / 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.
@Pet3ris
Pet3ris / pinducer.hs
Created December 6, 2012 19:37
Basic program induction
{-# LANGUAGE GADTs #-}
import Control.Monad
-- Basic program inducer
--
-- usage:
-- take 5 $ solve [(1, 2::Int), (2, 3)]
-- => [(+ 1 X),(+ X 1),(+ 0 (+ 1 X)),(+ 0 (+ X 1)),(+ 1 (+ 0 X))]
-- Expressions of the target language
; Temporal logic programming with explicit time using core.logic
; we assume relations s, <o and constants zero, one, four are defined as in
; https://github.com/frenchy64/Logic-Starter/blob/master/src/logic_introduction/numbers.clj
; we start by using 'next' to define a Fibonacci relation
; that is equal to F(n) at time n
; We use the small trick that if a number
; has a predecessor and then another, then it is at least 2
(defn fib [v t]
@Pet3ris
Pet3ris / idea.scala
Created December 25, 2012 09:46
Typed type tensors in scala
sealed trait Tensor[V] {
val n, m: Int
def apply(vs: List[V], vds: List[V => Double]): Double
}
case class TUnit[V](v: V) extends Tensor[V] {
val n = 1
val m = 0
def apply(vs: List[V], vds: List[V => Double]): Double = vds head(v)
}