Skip to content

Instantly share code, notes, and snippets.

View phagenlocher's full-sized avatar

Philipp Hagenlocher phagenlocher

View GitHub Profile
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
elem :: (Eq a) => a -> [a] -> Bool
elem _ [] = False
elem e (x:xs) = (e == x) || (elem e xs)
nub :: (Eq a) => [a] -> [a]
nub [] = []
nub (x:xs)
| x `elem` xs = nub xs
| otherwise = x : nub xs
@phagenlocher
phagenlocher / getip.py
Created January 31, 2019 11:28
Get IP and Location from ifconfic.co
#!/usr/bin/python3
from json import loads
from requests import get
g = get("https://ifconfig.co/json")
if not g.ok:
print("Failure connecting to ifconfig.co")
exit(-1)
@phagenlocher
phagenlocher / forall.py
Created April 19, 2018 07:48
Run any command recursively
#!/usr/bin/python3
import os
import re
import argparse
import subprocess
from functools import reduce
def run_cmd(path, cmd, verbose):
for i, el in enumerate(cmd):
@phagenlocher
phagenlocher / xmas.ml
Last active April 12, 2018 10:04
Xmas Tree in OCaml
(* ocamlc unix.cma xmas.ml *)
type color = RST | RED | GRN | YEL | BLU | MAG | CYN | WHT
let rec mult_list n l = if n <= 0 then [] else l @ (mult_list (n-1) l)
let tree_elems = (mult_list 5 [GRN, ">"; GRN, "<"]) @
[RED, "@"; BLU, "O"; MAG, "o"; YEL, "*"]
let snow_elems = (mult_list 15 [" "]) @ [".";",";"'";"*"]
@phagenlocher
phagenlocher / bright.py
Created November 4, 2016 21:40
Script to change screenbrightness on a Thinkpad T410
#!/usr/bin/python3
import sys
def readFile(path):
with open(path, 'r', encoding='utf-8') as file:
return int(file.read())
def writeFile(path, value):
with open(path, 'w', encoding='utf-8') as file:
@phagenlocher
phagenlocher / crawl.go
Created August 18, 2016 13:00
A simple webcrawler written in Golang
package main
import (
"os"
"strconv"
"fmt"
"github.com/mxk/go-sqlite/sqlite3"
"golang.org/x/net/html"
"net/http"
"strings"
@phagenlocher
phagenlocher / main.go
Created August 15, 2016 21:28
Generating prime numbers with go routines
package main
import (
"fmt"
"math"
"math/rand"
"time"
)
func generate_prime(min int, max int, result chan int) {