Skip to content

Instantly share code, notes, and snippets.

@jiamo
jiamo / build_mediainfo.sh
Last active May 25, 2018 17:39
Build mediainfo ELF for aws lambda
cd ~/
apt-get install git automake autoconf libtool pkg-config make g++ zlib1g-dev libcurl4-gnutls-dev
git clone https://github.com/MediaArea/ZenLib.git
git checkout v0.4.37
cd ZenLib/Project/GNU/Library
./autogen.sh
./configure --enable-static
make -j4
@jiamo
jiamo / cartesian_product1.hs
Last active May 25, 2018 17:35
high order function transform example 1
module Cartesian_product1 where
import Prelude hiding(product)
product1 [] = [[]]
product1 (xs:xss) =
h xs (product1 xss) where
h [] xss = []
h (x : xs) xss =
map (x:) xss ++ h xs xss
@jiamo
jiamo / Cartesian_product2.hs
Last active May 27, 2018 17:31
high order function transform simple 2
module Cartesian_product2 where
import Prelude hiding(product)
-- introduce mapa
map' :: (b->a) -> [b] -> [a]
map' g l = foldr' f [] l where
f x y = (g x) : y
foldr' :: (a -> b -> b) -> b -> [a] -> b
foldr' f z [] = z
@jiamo
jiamo / Cartesian_product3.hs
Last active May 29, 2018 01:58
Cartesian_product3.hs
{-# LANGUAGE RebindableSyntax #-}
module Cartesian_product3 where
import Prelude hiding((>>=), return, Monad, fail)
-- begin help -----
class Applicative m => Monad m where
return :: a -> m a
@jiamo
jiamo / Ycombinator1.rkt
Last active September 20, 2018 10:43
Ycombinator1
#lang racket
(define (factorial n)
(if (= n 0)
1
(* n (factorial (- n 1)))))
(define factorial_lambda
(lambda (n)
@jiamo
jiamo / Ycombinator2.rkt
Created September 20, 2018 10:54
Ycombinator2
#lang racket
;(Y f) = fixpoint-of-f
;(f fixpoint-of-f) = fixpoint-of-f
;(Y f) = fixpoint-of-f = (f fixpoint-of-f)
;(Y f) = (f (Y f))
(define (Y f) (f (Y f)))
(define Y-lambda
@jiamo
jiamo / Ycombinator3.rkt
Created September 20, 2018 12:28
Ycombinator3
#lang racket
(define identity (lambda (x) x))
(define (part-factorial0 self n)
(if (= n 0)
1
(* n (self self (- n 1))))) ;; note the extra "self" here the same as below
(part-factorial0 part-factorial0 5)
@jiamo
jiamo / Ycombinator4.rkt
Created January 8, 2019 14:18
Ycombinator4.rkt
#lang racket
;;(define Y
;; (lambda (f)
;; ((lambda (x) (f (x x))) (lambda (x) (f (x x)))) ))
;;(define almost-Y
;; (lambda (f)
;; ((lambda (x) (f (x x))) (lambda (x) (f (x x)))) ))
@jiamo
jiamo / can.agda
Last active September 12, 2019 10:17
plfa exercise in relation.
module Can where
import Relation.Binary.PropositionalEquality as Eq
import Data.Nat.Properties as Pro
open Pro using (+-assoc; +-identityʳ; +-suc; +-comm)
open Eq using (_≡_; refl; cong; sym)
open Eq.≡-Reasoning using (begin_; _≡⟨⟩_; _≡⟨_⟩_; _∎)
open import Data.Nat using (ℕ; zero; suc; _+_; _*_; _∸_; _^_)
@jiamo
jiamo / lazy-ycombinator.rkt
Created October 21, 2019 10:24
ycombinator from fix point of function
#lang lazy
(define g
(lambda (f)
(lambda (n)
(if (= n 0)
1
(* n (f (- n 1)))))))
(define f