Skip to content

Instantly share code, notes, and snippets.

View meikj's full-sized avatar

John Meikle meikj

  • Glasgow, Scotland
View GitHub Profile
@meikj
meikj / list.c
Last active August 29, 2022 21:12
Implementation of a doubly-linked list in C.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
/***************************************************************************
* Helper Types
***************************************************************************/
/* Basic example person data structure. */
-- Insertion sort
inssort :: Ord a => [a] -> [a]
inssort [] = []
inssort (x:xs) = insert x (inssort xs)
where
insert :: Ord a => a -> [a] -> [a]
insert n [] = [n]
insert n (x:xs)
| n <= x = n : x : xs
| otherwise = x : insert n xs
@meikj
meikj / CW5.hs
Last active January 3, 2016 01:19
-- Question 1: Define the functions add and allEqual
add :: (Int -> Int) -> Int -> Int
add f 1 = f 1
add f n = if n > 0 then add f (n-1) + f n else error "input must be n > 0"
allEqual :: (Int -> Int) -> Int -> Bool
allEqual f 1 = True
allEqual f n = if n > 0 then (allEqual f (n-1)) && (f (n-1) == f n) else error "input must be n > 0"
import Data.List
type NI = Int
type Age = Int
type Balance = Int
type Person = (NI, Age, Balance)
type Bank = [Person]
type Market = [Bank]
type Pop = [NI]
type Name = String
type Customer = (Name, Int, Int, Int)
type VStore = [Customer]
-- BEGIN TEST DATA --
cust1 :: Customer
cust1 = ("Neil", 311, 271, 345)
cust2 :: Customer
/**
* The Central Processing unit (CPU).
* Consists of an ALU and a set of registers, designed to fetch and
* execute instructions written in the Hack machine language.
* In particular, functions as follows:
* Executes the inputted instruction according to the Hack machine
* language specification. The D and A in the language specification
* refer to CPU-resident registers, while M refers to the external
* memory location addressed by A, i.e. to Memory[A]. The inM input
* holds the value of this location. If the current instruction needs
#include <stdio.h>
#include <stdlib.h>
#define DEFAULT_TAB_STOP 4
#define DEFAULT_REPLACE ' ' // used as tab replacement
int main(int argc, char *argv[]) {
char *arg_end;
int c, tab_stop, curr_col, spaces;
#include <stdio.h>
#define MAXLINE 1000
#define NEWLINE_ON 1
#define NEWLINE_OFF 0
int strend(char string[], int len);
int getline(char line[], int maxline);
int main(void) {
#include <stdio.h>
#define BUF_SIZE 256
void reverse(char dst[], char src[], int len);
int strend(char string[], int len);
int getline(char line[], int maxline);
int main(void) {
int len;
@meikj
meikj / folder.py
Last active December 20, 2015 00:29
#!/usr/bin/env python
from os import listdir, mkdir
from os.path import isfile, join
from shutil import move
PATH = "D:/Videos/Movies/"
def main():
files = [ f for f in listdir(PATH) if isfile(join(PATH, f)) ]