Skip to content

Commit

Permalink
Added Dockerfile experiement for java and csharp running
Browse files Browse the repository at this point in the history
Fixed bug in make_ver2 with extentionless files
Makefile for api now exports by default
Few notes on upcomming container activity
  • Loading branch information
calaldees committed Apr 21, 2021
1 parent dc522ce commit dbb0065
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 21 deletions.
3 changes: 2 additions & 1 deletion README.md
Expand Up @@ -34,7 +34,8 @@ Other similar projects?
-----------------------

https://github.com/algorithm-archivists/algorithm-archive

* [executable-tutorials](https://github.com/dharmatech/executable-tutorials)
* mechanism for doing what my version system sort of accomplishes

Old README.MD
=============
Expand Down
3 changes: 3 additions & 0 deletions teachprogramming/lib/Makefile
@@ -1,3 +1,6 @@
build:
python3 api.py ../static/projects/ ../static/language_reference/languages/ --export

run_local:
python3 api.py ../static/projects/ ../static/language_reference/languages/
# http://localhost:8000/static/index.html
Expand Down
4 changes: 2 additions & 2 deletions teachprogramming/lib/make_ver2.py
Expand Up @@ -119,7 +119,7 @@ def __init__(self, filenames):

@cached_property
def langauges(self):
return frozenset(self.files.keys()) - frozenset({'ver', 'yaml', 'yml', 'txt', 'md'})
return frozenset(self.files.keys()) - frozenset({'ver', 'yaml', 'yml', 'txt', 'md', ''})

@cached_property
def versions(self):
Expand Down Expand Up @@ -216,7 +216,7 @@ def _amalgamate_files_with_same_extension(acc, f):

@cached_property
def langauges(self):
return frozenset(self.files.keys()) - frozenset({'ver', 'yaml', 'yml', 'md'})
return frozenset(self.files.keys()) - frozenset({'ver', 'yaml', 'yml', 'md', ''})

@cached_property
def versions(self):
Expand Down
2 changes: 1 addition & 1 deletion teachprogramming/static/docs/unit2-projects.md
Expand Up @@ -9,7 +9,7 @@ This is not really unit 2 .. it's just a catch-all for other stuff
* dependency injection, mocks

* multiple container ci project
* black, code coverage + reject, cypress, database, webserver, containers, unittests, integration tests, end-to-end tests, pre-commit hooks, features from git log, conventional commits (check?), tag + auto increment.
* black, code coverage + reject, cypress, database, webserver (REST api + template render, openAPI3) poetry||requirements.txt? log to central log container? load balancer? nginx gzip+static http2? https-cert?, containers, unittests, integration tests, end-to-end tests, pre-commit hooks, features from git log, conventional commits (regex check?), tag + auto increment.

* [ECT Python Program: Theme Park Ride](https://docs.google.com/document/d/1_Hu-ZJz2p4dyYzyYgjZeORWuLX8PVfcFn7i8MZpPFHM/edit)
* > Word problem on estimation: There are 90 people in line at a theme park ride. Every 5 minutes, 40 people get on the ride and 63 join the line. Estimate how long it would take for 600 people to be in line.
Expand Down
@@ -0,0 +1,5 @@
FROM mono
WORKDIR /csharp
COPY *.cs ./
CMD mcs csharp.cs && mono csharp.exe
# docker build --tag csharp . && docker run --rm -it csharp
@@ -0,0 +1,2 @@
run:
docker build --tag csharp . && docker run --rm -it csharp
@@ -0,0 +1,5 @@
FROM openjdk:17-jdk-alpine
WORKDIR /java
COPY *.java ./
CMD javac *.java && java Java
# docker build --tag java . && docker run --rm -it java
105 changes: 88 additions & 17 deletions teachprogramming/static/language_reference/languages/java/Java.java
Expand Up @@ -10,8 +10,13 @@ Java SE (Standard Edition) JDK (Java Development Kit) // V

import java.util.Scanner; //Add at top of file // VER: read_line_from_console

import java.io.BufferedReader; //Add at top of file // VER: read_file
import java.io.FileReader; // VER: read_file
import java.io.BufferedReader; //Add at top of file // VER: file_read
import java.io.FileReader; // VER: file_read

import java.io.BufferedWriter; //Add at top of file // VER: file_write
import java.io.FileWriter; // VER: file_write




public class Java {
Expand Down Expand Up @@ -92,23 +97,85 @@ void for_loop() {
} // VER: for_loop
}

void while_loop() {
Integer count = 0; // VER: while_loop
while (count < 10) { // VER: while_loop
System.out.println("Count is " + count); // VER: while_loop
count = count + 2; // VER: while_loop
} // VER: while_loop
}

void for_each_loop() {
String[] names = {"Bob","Ben","Bill","Borris","Bin"}; // VER: for_each_loop
for (String name: names) { // VER: for_each_loop
System.out.println(name); // VER: for_each_loop
} // VER: for_each_loop
}


// TODO: java8? https://howtodoinjava.com/java8/java-8-write-to-file-example/
void file_write() {
String line_to_write = "Append to end of file"; // VER: file_write
try { // VER: file_write
BufferedWriter file = new BufferedWriter(new FileWriter("out.txt", true)); // VER: file_write
file.write(line_to_write); // VER: file_write
file.close(); // VER: file_write
} // VER: file_write
catch (Exception e){ // VER: file_write
System.err.println("Error: " + e.getMessage()); // VER: file_write
} // VER: file_write
}


void read_file() {
try { // VER: read_file
int line_count = 0; // VER: read_file
String line; // VER: read_file
BufferedReader input = new BufferedReader(new FileReader("in.txt")); // VER: read_file
while (( line = input.readLine()) != null) { // VER: read_file
System.out.println("Line " + line_count + ": " + line); // VER: read_file
line_count += 1; // VER: read_file
} // VER: read_file
input.close(); // VER: read_file
} // VER: read_file
catch (Exception e) { // VER: read_file
System.err.println("Error: " + e.getMessage()); // VER: read_file
} // VER: read_file
void file_read() {
try { // VER: file_read
int line_count = 0; // VER: file_read
String line; // VER: file_read
BufferedReader input = new BufferedReader(new FileReader("in.txt")); // VER: file_read
while (( line = input.readLine()) != null) { // VER: file_read
System.out.println("Line " + line_count + ": " + line); // VER: file_read
line_count += 1; // VER: file_read
} // VER: file_read
input.close(); // VER: file_read
} // VER: file_read
catch (Exception e) { // VER: file_read
System.err.println("Error: " + e.getMessage()); // VER: file_read
} // VER: file_read
}


void function() {
sayHello();
}
void sayHello() { // VER: function
System.out.println("Hello"); // VER: function
System.out.println("Goodbye"); // VER: function
} // VER: function

void function_with_return_value() {
System.out.println(biggest(1,2));
}
Integer biggest(Integer a, Integer b) { // VER: function_with_return_value
if (a > b) { // VER: function_with_return_value
return a; // VER: function_with_return_value
} // VER: function_with_return_value
else { // VER: function_with_return_value
return b; // VER: function_with_return_value
} // VER: function_with_return_value
}


void define_fixed_array() {
String[] names = new String[3]; // VER: define_fixed_array
names[0] = "Bob"; // VER: define_fixed_array
names[1] = "Foo"; // VER: define_fixed_array
names[2] = "Rah"; // VER: define_fixed_array
for (String name : names) { // VER: define_fixed_array
System.out.println(name); // VER: define_fixed_array
} // VER: define_fixed_array
System.out.println("array size is "+names.length); // VER: define_fixed_array
} // VER: define_fixed_array

//----------------------------------------------------------------------------

public static void main(String[] args) {new Java();}
Expand All @@ -120,7 +187,11 @@ public Java() {
arithmetic();
if_statement();
for_loop();
read_file();
while_loop();
for_each_loop();
file_read();
function();
function_with_return_value();
}

}
@@ -0,0 +1,2 @@
run:
docker build --tag java . && docker run --rm -it java

0 comments on commit dbb0065

Please sign in to comment.