Skip to content

Instantly share code, notes, and snippets.

View yasar11732's full-sized avatar

Yaşar Arabacı yasar11732

View GitHub Profile
@yasar11732
yasar11732 / package.json
Created December 23, 2019 13:01
TypeScript Environment
{
"name": "tstuts",
"version": "1.0.0",
"description": "TypeScript environment to follow tutorials",
"main": "dist/app.js",
"scripts": {
"start": "tsc && node dist/app.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
module Main (main) where
import RecursiveContents
import System.FilePath (takeExtension)
import System.IO (hPutStrLn,stderr)
import GHC.IO.Encoding (setLocaleEncoding, utf8)
import System.Environment (getArgs)
hasExtension :: String -> -- extension
String -> -- filepath
module Main where
import RecursiveContents
main :: IO ()
main = do
contents <- getRecursiveContents "."
mapM_ putStrLn contents
module RecursiveContents (getRecursiveContents)
where
import Control.Monad (forM)
import Control.Applicative (liftA2)
import System.Directory (doesDirectoryExist, listDirectory)
import System.FilePath ((</>))
myFilterM :: (Applicative m) => (a -> m Bool) -> [a] -> m ([a],[a])
cabal: Could not resolve dependencies:
[__0] trying: base-4.12.0.0/installed-4.1... (user goal)
[__1] trying: bytestring-0.10.10.0 (user goal)
[__2] next goal: directory (user goal)
[__2] rejecting: directory-1.3.4.0, directory-1.3.3.2, directory-1.3.3.1
(constraint from user target requires ==1.3.3.0)
[__2] trying: directory-1.3.3.0/installed-1.3...
[__3] next goal: Win32 (dependency of directory)
[__3] rejecting: Win32-2.6.1.0/installed-2.6... (conflict:
bytestring==0.10.10.0, Win32 => bytestring==0.10.8.2/installed-0.1...)
module HighestClose where
import qualified Data.ByteString.Lazy.Char8 as L
closing = readPrice . (!!7) . L.split ';'
readPrice :: L.ByteString -> Maybe Int
readPrice str = do
(tl,rest) <- L.readInt str
case rest of
L.empty -> Nothing
module ExeMagic where
import qualified Data.ByteString.Lazy as L
hasExeMagic :: L.ByteString -> Bool
hasExeMagic content = L.take 2 content == exeMagic
where exeMagic = L.pack [0x4D, 0x5A]
isExeFile :: FilePath -> IO Bool
@yasar11732
yasar11732 / ch04part2.hs
Created December 15, 2019 23:47
Real World Haskell CH04 exercises (2)
myGroup :: (Eq a) => [a] -> [[a]]
myGroup = foldr myMatchMaker []
where myMatchMaker x' ((x:xs):xss) = if x' == x then (x':x:xs):xss else [x']:(x:xs):xss
myMatchMaker x' [] = [[x']]
import System.Environment (getArgs)
import Data.Char (isAsciiLower, isAsciiUpper, isDigit)
import Data.List (intercalate)
splitWith :: (a -> Bool) -> [a] -> [[a]]
splitWith pred = foldr f [[]]
where f elem acc@(x:xs) | pred elem = (elem:x):xs
| otherwise = []:acc
module Hull where
data Direction = L | R | S
instance Show Direction where
show L = "Left"
show R = "Right"
show S = "Straight"