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
function! OpenTestOrProduction() | |
let current_file_without_extension = expand("%:r") | |
let filename_parts = split(current_file_without_extension, "_") | |
let target_file = "" | |
if IsInTestFile() | |
let main_name_parts = filename_parts[0:-2] | |
let target_file = CreateTargeFilename(main_name_parts) | |
else | |
let target_file = CreateTargeTestFilename(current_file_without_extension) | |
end |
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
def self.to_csv(options: { col_sep: "," } , column_names: self.column_names, messages: limit(1000)) | |
CSV.generate(options) do |csv| | |
csv << column_names.push(*["Annotation Reason", "Annotation Notes"]) | |
messages.each do |message| | |
attributes = message.attributes.values_at(*column_names) | |
attributes.push(*get_annotation_data_for_message(message)) | |
csv << attributes | |
end | |
end | |
end |
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
data Optional a = Invalid | Valid a | |
deriving (Show) | |
optionalToString :: (Show a) => Optional a -> String | |
optionalToString Invalid = "Not Valid" | |
optionalToString (Valid value) = show value | |
safeRoot :: Double -> Optional Double | |
safeRoot x | |
| x >= 0 = Valid (sqrt x) |
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 OverloadedStrings #-} | |
module PraseJsonSample where | |
import Data.Aeson ((.:), (.:?), decode, FromJSON(..), Value(..)) | |
import Control.Applicative ((<$>), (<*>)) | |
import Data.Time.Format (parseTime) | |
import Data.Time.Clock (UTCTime) | |
import System.Locale (defaultTimeLocale) | |
import Control.Monad (liftM) | |
import qualified Data.HashMap.Strict as HM |
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 GeneralizedNewtypeDeriving, FlexibleInstances #-} | |
module Sized where | |
import Data.Monoid | |
newtype Size = Size { getSize :: Int } | |
deriving (Eq, Ord, Show, Num) | |
class Sized a where | |
size :: a -> Size |
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 | |
} | |
} |
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
{-# 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
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
# 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: |