Skip to content

Instantly share code, notes, and snippets.

View yasar11732's full-sized avatar

Yaşar Arabacı yasar11732

View GitHub Profile
module ListADT where
import Data.List
data List a = Cons a (List a)
| Nil
-- instance (Show a) => Show (List a) where
-- show xs = "MyList[" ++ (intersperse ',' . map show) (toList xs) ++ "]"
@yasar11732
yasar11732 / hw6.hs
Last active December 12, 2019 15:18
fib :: Integer -> Integer
fib 0 = 0
fib 1 = 1
fib n = fib (n-1) + fib (n - 2)
fibs1 :: [Integer]
fibs1 = map fib [0..]
fibs2 :: [Integer]
@yasar11732
yasar11732 / hw4.hs
Last active December 12, 2019 08:21
import Data.List
fun1 :: [Integer] -> Integer
fun1 = product . map (subtract 2) . filter even
fun2' :: Integer -> Integer
fun2' 1 = 0
fun2' n | even n = n + fun2' (n `div` 2)
| otherwise = fun2' (3 * n + 1)
@yasar11732
yasar11732 / Golf.hs
Last active December 11, 2019 14:43
{-
Exercise 1 Hopscotch
Your first task is to write a function
skips :: [a] -> [[a]]
The output of skips is a list of lists. The first list in the output should
be the same as the input list. The second list in the output should
contain every second element from the input list. . . and the nth list in
{-# OPTIONS_GHC -Wall #-}
module LogAnalysis where
import Log
parseMessage' :: [String] -> LogMessage
parseMessage' ("E":severity:timestamp:rest) = LogMessage (Error (read severity)) (read timestamp) (unwords rest)
parseMessage' ("I":timestamp:rest) = LogMessage Info (read timestamp) (unwords rest)
parseMessage' ("W":timestamp:rest) = LogMessage Warning (read timestamp) (unwords rest)
parseMessage' x = Unknown (unwords x)
toDigits :: Integer -> [Integer]
toDigits n
| n <= 0 = []
| n < 10 = [n]
| otherwise = (toDigits (n `div` 10)) ++ [n `mod` 10]
toDigitsRev :: Integer -> [Integer]
toDigitsRev n = reverse $ toDigits n
@yasar11732
yasar11732 / walk.hs
Last active December 6, 2019 14:18
Haskell Walk Directory Recursively
import System.Directory
import System.FilePath
import Control.Monad
import Control.Exception
import GHC.IO.Encoding
-- Gets a root directory and a callback,
-- calls callback for root directory and every subdirectory recursively
-- callback signature root -> files -> dirs -> IO ()
walkDirectory :: String -> (String -> [String] -> [String] -> IO ()) -> IO ()
walkDirectory rootDir callback = do
@yasar11732
yasar11732 / JSON.cs
Created July 29, 2019 18:50
JSON parser and stringifier implemented in C# (Recursive Descent Parser)
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace MiniWebFramework
{
public enum JSONValueType
@yasar11732
yasar11732 / huffman.c
Last active July 14, 2019 18:03
Canonical Huffman Coding Demo
#include <stddef.h> // NULL
#include <stdint.h>
#include <stdlib.h> // calloc
#include <string.h> // memset
#include <stdio.h>
/*
* Bir kodun en fazla 15 bit olmasına izin vereceğiz.
* Bu nedenle code için 16 bit veri yapısı yeterli.
*/
@yasar11732
yasar11732 / stackprotector.s
Created September 14, 2018 19:46
GCC stack protector
0x08048464 <+0>: push ebp
0x08048465 <+1>: mov ebp,esp
0x08048467 <+3>: sub esp,0x14
0x0804846a <+6>: mov eax,gs:0x14
0x08048470 <+12>: mov DWORD PTR [ebp-0x4],eax
0x08048473 <+15>: xor eax,eax
0x08048475 <+17>: lea eax,[ebp-0x10]
0x08048478 <+20>: mov DWORD PTR [esp],eax
0x0804847b <+23>: call 0x8048360 <gets@plt>
0x08048480 <+28>: lea eax,[ebp-0x10]