Skip to content

Instantly share code, notes, and snippets.

@leksak
leksak / internet-protocol-stack-overview.md
Last active December 6, 2015 19:22
Answer to exam question regarding what roles each layer in the IP-stack has

The different layers that make up the internet protocol stack are

  • Application
  • Transport
  • Network
  • Link
  • Physical

The most common functions in a protocol should handle

  • The dialogue, who gets to send in which order
  • The addressing, how to broadcast one's identity and the identity of one's intended recipient.
  • Frame-format, how information (data) is packaged (framed)
  • Error-handling

Q: What are the differences between a circuit switching network and a packet switching network?

Answer

Bandwidth

A circuit switching network has a guaranteed bandwidth, since the entire established circuit is dedicated to the communication between the two parties. The disadvantage of this is that the resource (the bandwidth) is not guaranteed to be fully utilised

@leksak
leksak / pythagoras.hs
Last active December 21, 2015 22:01
L-system
{-# LANGUAGE MultiWayIf #-}
data Variables = Zero | One | LB | RB deriving (Show, Eq)
-- LB and RB symbolises left and right brackets, i.e. [, ]
pythagoras = concatMap (\c -> if
| c == Zero -> One : [LB, Zero, RB, Zero]
| c == One -> One : [One]
| c == LB -> [LB]
| c == RB -> [RB])
@leksak
leksak / algae1.hs
Last active December 21, 2015 22:02
L-system
{-# LANGUAGE MultiWayIf #-}
data Algae = A | B deriving (Show, Eq)
algae :: [Algae] -> [Algae]
algae = concatMap (\c -> if
| c == A -> A:[B]
| c == B -> [A])
@leksak
leksak / read-file-util-method.java
Last active November 23, 2015 09:39
Read an entire file into memory
/**
* Lossless reading of a file (line-separators are preserved).
* May temporarily require memory several times the size of the
* file. For a short time the raw file contents (a byte array),
* and the decoded characters reside in memory simultaneously.
* It is safest to apply to files that you know to be small
* relative to the available memory.
* @param path the absolute path of the file.
* @param encoding the charset with which the bytes in the file
* should be decoded.