Skip to content

Instantly share code, notes, and snippets.

View NicMcPhee's full-sized avatar

Nic McPhee NicMcPhee

View GitHub Profile
@NicMcPhee
NicMcPhee / Mergesort.java
Created September 28, 2021 01:58
Java implementation of Mergesort and Quicksort. It's the allocation of the array destination on line 29 in Mergesort.java that creates the memory management complications. In Java we don't have to worry about freeing up that memory because the garbage collector takes care of it for us, but in C we'll have to look after that ourselves.
package umm.systems;
public class Mergesort implements Sorter {
@Override
public void sort(int[] values) {
mergesortRange(values, 0, values.length);
}
private void mergesortRange(int[] values, int startIndex, int endIndex) {
@NicMcPhee
NicMcPhee / docker-compose.yml
Created February 7, 2021 21:23
The `docker-compose.yml` file for the Cloud Computing class Docker lab
services:
server:
container_name: server
build: ./server # Location of the Dockerfile for the client
restart: always
environment:
MONGO_ADDR: mongo # hostname of the mongo container
MONGO_DB: prod
WAIT_HOSTS: mongo:27017 # wait for mongo to start up before starting the server
depends_on:
@NicMcPhee
NicMcPhee / Main.java
Created February 5, 2021 18:54
Java Hello World!
public class Main {
public static void main(String[] args) {
System.out.println("Hello from inside a Java container!");
}
}
@NicMcPhee
NicMcPhee / ThreadDemo.java
Created October 13, 2020 14:42
A simple example of threading in Java
import java.util.concurrent.atomic.AtomicInteger;
public class ThreadDemo {
private int count = 0;
private AtomicInteger atomicCount = new AtomicInteger(0);
public static void main(String[] args) throws InterruptedException {
ThreadDemo demo = new ThreadDemo();
demo.go();
}
@NicMcPhee
NicMcPhee / _README_replacing_temporary_files_with_pipes.md
Last active September 4, 2020 17:22
Using pipes to eliminate temporary files

Using pipes to eliminate temporary files

This illustrates using pipes to eliminate temporary files. We start with a bash script that takes some demographic data (see MOCK_DATA.csv) specified as a file name as a command line argument. The script then outputs a count of how many people come from different states. The output on the included data file is:

 49 MN
@NicMcPhee
NicMcPhee / GECCO_tutorial_graph_database_demo.cypher
Created July 15, 2018 23:26
GECCO tutorial graph database demo code
// Clear the DB for a clean start
MATCH (n) DETACH DELETE n;
CREATE CONSTRAINT ON (i:Individual) ASSERT i.uuid IS UNIQUE;
CREATE CONSTRAINT ON (e:Errors) ASSERT e.Errors_vector IS UNIQUE;
CREATE INDEX ON :Individual(generation);
CREATE INDEX ON :Errors(total_error);
USING PERIODIC COMMIT
@NicMcPhee
NicMcPhee / Todos-F17-CSci3403.md
Last active September 5, 2017 03:27
To-dos for F17 CSci 3403

Questions

  • Should @dolan-peter use Github classroom instead of the UMN Github? What does @kklamberty think?
    • Answer seems to be that Github classroom was easier to work with and did a better job of separating groups, so Peter's going to go with that.
  • Do we want to at least start replacing the semi-deprecated use of backticks in shell scripts with the $(…) syntax? Eventually yes, but it doesn't need to start happening now.
  • The "course resources" page is currently in the UMN Github, which isn't a good place for it and it should probably move to Github.com. Where, though? Should it be a page in a repo? A gist? A page or pages in a wiki somehwere?

Check the repos

I need to make sure that each repo has whatever changes were made last fall merged into the "master" repos.

@NicMcPhee
NicMcPhee / DateClient.java
Last active October 15, 2018 04:05
Simple Date client/server example. Start the server, and then running the client gets the date from the server and prints it.
import java.net.*;
import java.io.*;
public class DateClient {
public static final int portNumber = 6013;
public static void main(String[] args) throws IOException {
String server;
// Use "127.0.0.1", i.e., localhost, if no server is specified.
if (args.length == 0) {
// Clear the DB for a clean start
MATCH (n) DETACH DELETE n;
CREATE CONSTRAINT ON (i:Individual) ASSERT i.uuid IS UNIQUE;
CREATE CONSTRAINT ON (e:Errors) ASSERT e.Errors_vector IS UNIQUE;
CREATE INDEX ON :Individual(generation);
CREATE INDEX ON :Errors(total_error);
USING PERIODIC COMMIT
@NicMcPhee
NicMcPhee / CoinTossDistributed.ex
Created November 3, 2015 23:22
Distributed cryptographically fair coin toss in Elixir with multiple nodes.
# Person A flips and Person B chooses "heads" or "tails".
# Person B wins if their choice matches the flip, otherwise
# person A wins.
defmodule CoinToss do
def run_simulation(first_host, second_host, num_people) do
counterPid = spawn(__MODULE__, :counter_loop, [0, 0])
:global.register_name(:counter, counterPid)
people = create_people(first_host, second_host, num_people)