This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is the implementation of SUB1 in Lambda Calculus (LC) | |
# using the "Wisdom Tooth" trick! Apparently for some time, | |
# even Alonzo Church didn't believe SUB1 is a feasible operation | |
# in LC until one day his student Kleene came up with this idea. | |
# It's called "Wisdom Tooth" because he came up with it while he | |
# was at dentist :) | |
# | |
# It simply starts counting up from ZERO and at each step, remebers | |
# the previous value and when reaches the target, returns the previous | |
# value as the SUB1 result: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import random | |
# O(n * lg(k)) | |
def k_largest_elements(arr, k): | |
k_elems = arr[0:k] | |
k_elems_heaped = min_heapify(k_elems) | |
for idx in range(k + 1, len(arr)): | |
if arr[idx] > k_elems_heaped[0]: | |
k_elems_heaped[0] = arr[idx] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE InstanceSigs #-} | |
newtype Compose f g a = Compose { getCompose :: f (g a) } | |
instance (Functor f, Functor g) => Functor (Compose f g) where | |
fmap :: (a -> b) -> Compose f g a -> Compose f g b | |
fmap f (Compose fga) = Compose $ fmap (fmap f) fga | |
instance (Applicative f, Applicative g) => Applicative (Compose f g) where | |
pure :: a -> Compose f g a |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
twice :: Int -> Int | |
twice = (*2) | |
twicePossibleNums :: Maybe [Int] -> Maybe [Int] | |
twicePossibleNums = (fmap . fmap) twice | |
main :: IO () | |
main = putStrLn $ show $ twicePossibleNums (Just [1, 2, 3]) -- => Just [2, 4, 6] | |
-- How it Works? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Convert a One-Track-Input Function to Two-Track-Input Function for better | |
// Composability of Function in the presence of Option types | |
def bindOption[A, B](f: A => Option[B]): Option[A] => Option[B] = { | |
(input) => input match { | |
case Some(a) => f(a) | |
case None => None | |
} | |
} |
NewerOlder