Skip to content

Instantly share code, notes, and snippets.

View markomanninen's full-sized avatar

Marko Manninen markomanninen

View GitHub Profile
@markomanninen
markomanninen / anthropic-claude-function-calling.ipynb
Created March 10, 2024 15:59
Anthropic Claude Function Calling.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@markomanninen
markomanninen / betacode.py
Last active January 31, 2018 14:54
Import Greek corpora to local file system by cltk library, parse Homer Iliad to cards and lines by using betacode decoder
# copyright (c) https://raw.githubusercontent.com/epilanthanomai/hexameter/master/betacode.py
import unicodedata
map_b2u = {
'A': '\u03b1', # alpha
'B': '\u03b2', # beta
'C': '\u03be', # xi
'D': '\u03b4', # delta
'E': '\u03b5', # epsilon
'F': '\u03c6', # phi
@markomanninen
markomanninen / ilmestyskirja.txt
Created January 20, 2018 17:58
Ilmestyskirja 33/38
1 luku
Alkulause 1 – 3. Johannes lausuu tervehdyksen seitsemälle Vähä Aasian seurakunnalle 4 – 8 sekä kertoo Jeesuksen ilmestyneen hänelle Patmos – saarella ja käskeneen hänen kirjoittaa, mitä hän näyssään oli saanut nähdä 9 – 20.
1 Jeesuksen Kristuksen ilmestys, jonka Jumala antoi hänelle, näyttääkseen palvelijoillensa, mitä pian tapahtuman pitää; ja sen hän lähettämänsä enkelin kautta antoi tiedoksi palvelijalleen Johannekselle,
2 joka tässä todistaa Jumalan sanan ja Jeesuksen Kristuksen todistuksen, kaiken sen, minkä hän on nähnyt.
3 Autuas se, joka lukee, ja autuaat ne, jotka kuulevat tämän profetian sanat ja ottavat vaarin siitä, mitä siihen kirjoitettu on; sillä aika on lähellä!
4 Johannes seitsemälle Aasian seurakunnalle: Armo teille ja rauha häneltä, joka on ja joka oli ja joka tuleva on, ja niiltä seitsemältä hengeltä, jotka ovat hänen valtaistuimensa edessä,
5 ja Jeesukselta Kristukselta, uskolliselta todistajalta, häneltä, joka on kuolleitten esikoinen ja maan kuningasten hallitsija! Hänelle, jok
def is_zero(n):
return not n[1:] and not n[0]
def carry_over(first_num, second_num):
stack = []
for i, j in enumerate(second_num):
if j:
# basicly same as map(sum, zip(stack, a)) but with zero appends
stack = [(stack.pop(0) + n) if stack else n \
for n in ([0] * i + first_num)]
#from summa import summa
#from predecessor import predecessor
def bn(n):
return list(reversed(list(map(lambda x: 1 if x == "1" else 0, "{0:b}".format(n)))))
def is_zero(n):
return not n[1:] and not n[0]
@markomanninen
markomanninen / lcalc.min.hy
Last active October 27, 2017 18:04
Lambda Calculus Interpreter
(eval-and-compile(defmacro D[&rest e]`(defn ~@e))(D €[a b](.extend a b)a)(D §[a](.reverse a)a)(D ¤[a](first a))(D ?[e](instance? F e))(D £[e](if(coll? e)(if(?(¤ e))(£(apply(¤ e)(rest e)))(if(? e)e(do(def x(list(map £ e)))(if(?(¤ x))(£ x)x))))e))(D $[a b c](if(coll? c)(if(? c)(if(=(¤ c)a)c(F[(¤ c)($ a b(second c))]))((type c)(genexpr($ a b d)[d c])))(if(= a c)b c)))(defclass V[HySymbol](D --call--[self &rest v](€[self]v)))(defclass F[HyExpression](D --call--[self a &rest b](def e(£($(¤ self)a(second self))))(if b(def e(apply e b)))e)))(defmacro L[&rest e](reduce(fn[y x]`((fn[](def ~x(V(gensym'~x)))(F[~x ~y]))))(§(list e))))
(eval-and-compile
; pretty print utility
(defn lprint [expr]
(if (coll? expr)
(+ "(" (.join " " (list-comp (lprint x) [x expr])) ")")
(str expr)))
; church number body generator: (N 3 m n) ; -> (m (m (m n)))
(defn N [n x y]
(if (zero? n) y
(+ (% "(%s " x) (N (dec n) x y) ")"))))
; index-find function needs to be available at compile time for the lambda expression macro
(eval-and-compile
; set comma constant for separator
; at the moment Hy doesn't support dot on macro expressions because dot is mixed with internal HyCons functionality
; causing this error: https://github.com/hylang/hy/blob/e8ffd412028232cc2cc4fe4bfb10f21ce8ab2565/hy/compiler.py#L2478
(setv comma '·)
; find index of the element from the list. if the element is not found, return -1
(defn index-find [elm lst]
(try (.index lst elm) (except [ValueError] -1))))
; lambda expression macro
@markomanninen
markomanninen / macro2cmacro.hy
Created July 26, 2017 17:12
Macro to call other macro and recursively passing parameters one by one
; singular variable setter
(defmacro defproposition [symbol]
; this is simplified here for demonstration
`(setv ~symbol None))
; multiple variable setter
(defmacro defpropositions [&rest args]
(if (len args)
`(do
(defproposition ~(get args 0))
@markomanninen
markomanninen / isNaturalNumber.py
Created July 26, 2017 08:08
function to check if given input is a natural number. with an additional parameter (function) limit of the number can be set
def isN(x, func=None):
try:
val = int(x)
return (len(str(val)) is len(str(x))) and \
(func(val) if callable(func) else True)
except ValueError:
return False
print(