Skip to content

Instantly share code, notes, and snippets.

View jeremysinger's full-sized avatar

Jeremy Singer jeremysinger

View GitHub Profile
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
unsigned int i;
unsigned int x = 0xdeadbeef;
if (argc==2)
x = atoi(argv[1]);
printf("seed value: %x\n", x);
@jeremysinger
jeremysinger / lab-wk3.hs
Created October 5, 2023 17:47
Week 3 lab for Functional Programming COMPSCI4021
-- lab-wk3
-- Jeremy.Singer@glasgow.ac.uk
-- v1, Thu 5 Oct 23
import Data.Char
import Test.QuickCheck
{--
1. Write a function `twice` that calls a function f
{- Example code for Functional Programming
to demonstrate ad-hoc polymorphism with typeclasses
(c) Jeremy Singer 2022
-}
data Mammal = Human | Dog | Cat | Pig deriving (Show,Eq)
data Reptile = Crocodile deriving (Show,Eq)
class Noisy a where
mkNoise :: a -> String
import Test.QuickCheck
import Control.Monad
-- simple binary tree, with data stored at leaves
data Tree a = Leaf a | Node (Tree a) (Tree a) deriving (Show,Eq)
-- only instances of Arbitrary typeclass can be
-- generated by QuickCheck random input generator
instance Arbitrary a => Arbitrary (Tree a) where
arbitrary = sized arbTree
import Text.Parsec
-- simple datatype for expressions
data BinOp = Add | Sub | Mul | Div deriving (Show,Eq)
data ArithExpr =
Compound ArithExpr BinOp ArithExpr
| Value Int
deriving Show
import io
import matplotlib.pyplot as plt
import pandas as pd
components = [ 'Sensor Interface',
'Sensor Node',
'Manage Nodes',
'Web Interface',
'Database Interface',
'Communication'
from machine import Pin, I2C
import time
_DEVICE_ADDR = 0x23 # default I2C address for BH1750 light sensor
class LightSensor():
#Light Modes
OP_SINGLE_HRES1 = 0x20
OP_SINGLE_HRES2 = 0x21
@jeremysinger
jeremysinger / loyaltycard.tex
Created September 23, 2019 12:32
loyaltycard.tex
\documentclass{article}
\usepackage{amsmath}
\usepackage{fdsymbol}
\usepackage[left=1.8cm,top=1.7cm,right=1.8cm,bottom=1.72cm,nohead]{geometry}
\begin{document}
\thispagestyle{empty}
@jeremysinger
jeremysinger / output.txt
Created November 12, 2018 10:40
Ideal output from FP Receipts exercise
<start>
* Items Purchased
+ 1 Apple 0.50
+ 2 Apple 0.50
+ 3 Apple 0.50
+ 4 Apple 0.50
+ 5 Apple 0.50
+ 6 Watermelon 3.00
+ 7 Sumatran Coffee Beans 6.00
-- | The 'wordPhrase' function spells out an individual word
-- For example, "a is for apple"
wordPhrase :: String -> String
wordPhrase x = (head x) : " is for " ++ x
-- | The 'speller' function generates text for a spelling book
-- from a list of words
speller :: [String] -> String
speller [] = []