Skip to content

Instantly share code, notes, and snippets.

View phagenlocher's full-sized avatar
🏳️‍🌈

Philipp Hagenlocher phagenlocher

🏳️‍🌈
View GitHub Profile
#!/usr/bin/env python3
import code
import ctypes
import inspect
import logging
def hook(
banner_msg: str | None = None,
@phagenlocher
phagenlocher / lazy.py
Last active March 6, 2024 13:59
Lazy Evaluation in Python (https://youtu.be/KniIeHiEzdo)
class Lazy:
def __init__(self, fun, *args, **kwargs):
self.fun = fun
self.args = args
self.kwargs = kwargs
self.executed = False
self.value = None
# Binary Operators
def __binary__(self, binfun, other):
@phagenlocher
phagenlocher / Lazy.java
Last active September 7, 2020 15:00
Lazy Evaluation in Java (https://youtu.be/KniIeHiEzdo)
package main;
public interface Lazy<R> {
public R force();
}
-- Compile with -threaded
import System.IO
import Control.Concurrent
import Control.Concurrent.STM
-- (<Sum>, <Number of finished transactions>)
type Result = TVar (Int, Int)
-- Adds x to result and increments the number of finished transactions
-- Compile with -threaded
import System.IO
import Control.Concurrent
getGreeting :: IO String
getGreeting = do
-- Get id and convert to string
tid <- myThreadId
let greeting = "Hello from " ++ show tid
-- Compile with the -XScopedTypeVariables flag.
-- e.g. ghc -Wall -XScopedTypeVariables Main.hs
import Control.Exception
data MyError = Error deriving Show
instance Exception MyError
failing :: IO ()
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis
import Data.List
import Data.Char
import System.IO
getSearchWords :: IO [String]
getSearchWords = do
putStrLn "Specify the words to search:"
aux
where
aux = do
import Data.List hiding (insert)
import Test.QuickCheck
data Tree a = Leaf | Node (Tree a) a (Tree a)
deriving Show
-- Exercise 1
inv_tup_tree = aux (0,0)
where
aux (l,r) = Node (aux $ (l+1,r)) (l,r) (aux $ (l,r+1))
rev :: [a] -> [a]
rev = foldl (\acc x -> x : acc) []
--rev = foldl (flip (:)) []
prefixes :: [a] -> [[a]]
prefixes = foldr (\x acc -> [x] : (map ((:) x) acc)) []
lagrange :: [(Float, Float)] -> Float -> Float
lagrange xs x = foldl (\acc (xj,y) -> acc + (y * l xj)) 0 xs
where