Skip to content

Instantly share code, notes, and snippets.

@Sam-Serpoosh
Sam-Serpoosh / factorial.py
Last active October 17, 2016 22:37
Full implementation of Factorial in Lambda Calculus using Python.
#!/usr/bin/env python
# As you know there is NO Assignment in Lambda Calculus (LC),
# and all those functions must be inlined using LC's
# substitution rule. But if I do that this code will look extremely
# gross and unreadable. So I keep it this way for comprehensibility
# reasons.
#
# This was SO MUCH fun to implement and quite an interesting puzzle
# to solve. This whole thing was completely inspired by Gary Bernhardt's
@Sam-Serpoosh
Sam-Serpoosh / Pred.hs
Last active October 23, 2016 04:56
PRED/SUB1 function implemented in pure Lambda Calculus using Haskell!
zero = \f -> \x -> x
mySucc = \n -> \f -> \x -> f $ n f x
add = \n -> \m -> n mySucc m
mkPair = \a -> \b -> \s -> s a b
myFst = \a -> \b -> a
mySnd = \a -> \b -> b
step = \p -> mkPair (p mySnd) (mySucc (p mySnd))
nSteps = \n -> \p -> n step p
zz = mkPair zero zero
myPred = \n -> (nSteps n zz) myFst
@Sam-Serpoosh
Sam-Serpoosh / longest_sub_array_sum_k.py
Created December 11, 2016 21:01
Find the longest sub-array in which the sum of elements is equal to a given number.
# Shape a matrix and we only use the half
# in which the col-number >= row-number!
# m[i][j] stores the sum of values in the
# sub-array from i to j (i.e nums[i:(j + 1)])
# and to calculate each new sub-array we can
# leverage the previously calculated sub-array
# which didn't have this new element and add
# this new element on top of that:
#
# m[i][j] = m[i][j - 1] + nums[j]
@Sam-Serpoosh
Sam-Serpoosh / SimpleParser.hs
Created March 13, 2017 06:12
Making a simple parametric Parser which is both a Functor and Applicative in Haskell!
{-# LANGUAGE InstanceSigs #-}
import Data.Char
import Control.Applicative
newtype Parser a = Parser { runParser :: String -> Maybe (a, String) }
instance Functor Parser where
fmap :: (a -> b) -> Parser a -> Parser b
fmap f pa = Parser $ \s -> fmap (first f) (runParser pa s)
@Sam-Serpoosh
Sam-Serpoosh / TumblingEventTimeWindowTest.java
Last active August 12, 2019 04:03
Testing TumblingEventTimeWindow of Flink
package com.uber.gairos.flink.operator.flink_operator;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;
import lombok.ToString;
import org.apache.flink.api.common.ExecutionConfig;
import org.apache.flink.api.common.functions.AggregateFunction;