Skip to content

Instantly share code, notes, and snippets.

View skiadas's full-sized avatar

Haris Skiadas skiadas

  • Hanover College
  • Hanover, IN, USA
View GitHub Profile
@skiadas
skiadas / segfault_example.cpp
Created February 15, 2020 16:12
segfault example
// segfault_example
// author: Haris Skiadas
// date: 2-14-20
// Compile with something like:
// g++ segfault_example.cpp -ldw -g -pthread -lgtest -o segfault_example
// ./segfault_example
#include "gtest/gtest.h"

Classes in C++

  • objects contain:
    • data in the form of member variables (also called instance variables).
    • as well as the functions we can use to interact with that data, in the form of member functions.
  • objects allow us to provide information hiding.
    • We cannot see and interact with the private members of an object.
    • We can only use the public member functions.
  • A class is a blueprint for objects (technically a bit more).
  • Name and type of the member variables.
@skiadas
skiadas / Lab6Instructions.md
Last active April 8, 2019 19:04
Lab 6 Instructions

Lab 6 instructions

Setup

  • Download the zip file from Moodle. Unzip the file in your downloads directory. You should now be seeing a project directory named "AVLTreeAssignment". The other directory, _MACOSX, can be ignored.
  • Copy the AVLTreeAssignment directory and paste it into your IDEA projects directory, or simply move the AVLTreeAssignment directory into your IDEA projects directory.
  • Start IntelliJ IDEA and Close your current project if you have one open. You should be seeing the IDEA welcome screen.
  • Choose "Create New Project". Make sure Java is selected, and click on Next twice to get to the screen that prompts for a project name. Use the file popup to the right of the "project location" line to select the AVLTreeAssignment directory from inside your IDEA projects directory. Then click Finish to complete the Project creation process.
  • Go to the File->Project Structure menu, and select the Modules tab on the sidebar. You should be seeing the src and test folders in the middle area of
@skiadas
skiadas / topologicalSort.md
Created February 12, 2019 20:14
Topological Sort Notes

Topological Sorting

  1. What is a directed acyclic graph?
  2. Example: CS major course prerequisites.
  3. What is a topological sorting for such a graph?

DFS solution to topological sorting

  1. How does DFS work in a directed graph? When will we encounter back-edges in this case?
  2. Perform DFS, noting the order in which vertices become dead-ends.
@skiadas
skiadas / proglang_interpreter_practice.md
Created November 9, 2016 13:55
Extra practice problems to supplement part B of Dan Grossman's Coursera/UniWash Programming Languages Course

As always, these problems go far and beyond what is required/expected from the class, and should only be pursued after you have finished all other requirements for the week. That being said, you might find the problems in the first section a good practice in understanding how MUPL works, and as good tests of your MUPL interpreter.

More MUPL macros/functions

We will write here more MUPL macros and functions. A "MUPL function" is basically a Racket definition of a (fun ...) MUPL expression. A "MUPL macro" is a Racket function that takes in MUPL expressions and produces a MUPL expression.

  1. We will start with "boolean" expressions. A boolean expression is going to be a MUPL expression that always evaluates to either int 1 (mupl-true) or int 0 (mupl-false). You might find it convenient to create those synonyms first.
  2. Write a MUPL macro mupl-if that takes a boolean expression e1 and two more MUPL expressions e2, e3. It would evaluate e1, and if it is equal to mupl-true then it evalua

The desugarer

Most of this will make sense once you hit the "conditionals" part of the project.

It is important to understand how the desugarer differs from the interpreter. Think of the desugarer as a "program transformation". You give it a program in one form, and it turns it into another form. It does NO evaluation of the program, only a syntactic transformation.

For example if you recall in the early days we talked about the expression: e1 or e2 and how we can instead get the same thing going with if statements:

if e1

The thing that students have the hardest time on when learning functional programming is how to process a recursive structure while maintaining some sort of "state", the result if you will. I'll attempt here to demystify the process.

Functional programming languages almost always use a lot of recursively defined structures. Depending on the language those can be implemented in various ways, but in any case the end result is the same. A structure of this type is either an "atom", i.e. an irreducible thing, or a "compound" consisting of substructures of the same form.

For example a "list" is either an Empty/Nil list (the "atom") or it is formed as a Cons of a value and another list (compound form). That other "sublist" can itself be empty or another cons and so on and so forth. A tree is similar. It is either empty, or it consists of a triple of a value and two sub-trees, left and right.

Almost every problem we encounter is a question about doing something with all entries in a structure. To solve these prob

@skiadas
skiadas / primes.sml
Created October 31, 2013 01:38
A simple algorithm for constructing the sequence of prime numbers, in SML.
fun divisible x xs =
case xs of
[] => false
| y::xs' => x mod y = 0 orelse divisible x xs'
fun primes lst =
let fun acc(x, rest) =
if divisible x rest then rest else x::rest
in rev (foldl acc [] lst)
end
@skiadas
skiadas / routing-wire.markdown
Last active December 19, 2015 21:58
Brainstorming for a wire.js API/DSL for routing. See https://github.com/cujojs/wire/issues/124

Ok here's some thoughts:

Routing/History protocol

Basic routing format

Basic routing mechanism: A "routes" facet you can add to any object. E.g:

routes = {
@skiadas
skiadas / BootstrapNotes.md
Last active December 18, 2015 20:48
Some notes on Bootstrap features

Bootstrap Notes

Overview

Responsive Design CSS. Offers CSS hooks to adjust behavior of page as you change the size, along with other goodies.

Uses a 12-column grid format, in other words you can divide any section into 12 pieces (or any divisor of 12). We'll see details later.