Notes to myself about how to setup a Java repl to work with automatic JUnit tests.

First, add junit:junit from Packages

Next, redirect the “Run” button:

  1. Create a new .replit file and add run = "bash run.sh"

  2. Create a new shell script run.sh and add the following lines…

    javac -classpath .:/run_dir/junit-4.12.jar:/run_dir/hamcrest-core-1.3.jar:/run_dir/json-simple-1.1.1.jar -d . *.java 
    java -classpath .:/run_dir/junit-4.12.jar:/run_dir/hamcrest-core-1.3.jar:/run_dir/json-simple-1.1.1.jar ShoesTester
    # javac *.java
    # java ShoesTester
    

Here is a sample ShoesTester file:

import org.junit.*;
import org.junit.runner.*;
import static org.junit.Assert.*;

public class ShoesTester {
  public int add3(int n) {
    return n+3;
  }
  
  @Test
  public void test_add3() {
    assertEquals(8,add3(5)); 
  }

  @Test 
  public void trivial_test(){
    assertTrue(5 == 2+3);
    assertFalse(7 != 14/2);
  }

  public static void main(String[] args) {
    System.out.println("Hello tests!");
    org.junit.runner.JUnitCore.main("ShoesTester");
  }
}


Here is the TEDIOUS process to follow to convert an old Quiz Question Bank to a new Quiz Item Bank in Canvas:

  1. Create a Quiz and name it TempQuiz
  2. Select Classic Quiz
  3. Click the Questions tab
  4. Click the Find Questions button
  5. Select the Question Bank
  6. Click Select All
  7. Click Add Questions
  8. Click Save
  9. Go back to the Quizzes page
  10. Click the Kabob icon next to TempQuiz
  11. Click Migrate
  12. Click TempQuiz
  13. Click Item Banks
  14. Click +Bank
  15. Name the Item Bank
  16. Repeat for EVERY QUESTION. If you have 20 questions in the bank, repeat these next steps 20 times!
    1. Click the first question
    2. Click Item Banking
    3. Click Add to Bank
    4. Select the destination bank
    5. Click Add
    6. Click the Trash icon to remove question


This post consists of notes to myself, so that I can remember the commands to create a Node.js Twitterbot hosted on Heroku.

  1. Create a Github repo and clone it locally

  2. Create a .gitignore with .env and node_modules/
    .env
    .DS_Store
    node_modules/
    
  3. Use npm to generate the initial project.
    npm init
    

    npm asks questions and builds a package.json file.

  4. Install some packages
    npm install dotenv
    npm install twit
    npm install express
    
  5. Create .env_sample with this
    CONSUMER_KEY = ...
    CONSUMER_SECRET = ...
    ACCESS_KEY = ...
    ACCESS_SECRET = ...
    
  6. Create index.js with this starter code
    const express = require('express');
    const app = express();
    require('dotenv').config();
    const Twit = require('twit');
    // const T = new Twit({
    //   consumer_key:         process.env.CONSUMER_KEY,
    //   consumer_secret:      process.env.CONSUMER_SECRET,
    //   access_token:         process.env.ACCESS_KEY,
    //   access_token_secret:  process.env.ACCESS_SECRET,
    //   timeout_ms:           60*1000,  // optional HTTP request timeout to apply to all requests.
    //   strictSSL:            true,     // optional - requires SSL certificates to be valid.
    // });
        
    // yr code here
        
    app.listen(
      process.env.PORT || 3000,
      ()=>console.log("bot running")
    );
    
  7. Write your code in index.js

  8. Use app.listen to log local, console-based tests. Run the tests with the command
    node index.js
    
  9. Create .env and add the API keys, then run live tests that post to Twitter.
    CONSUMER_KEY = ...
    CONSUMER_SECRET = ...
    ACCESS_KEY = ...
    ACCESS_SECRET = ...
    
  10. Commit and push to Github. Create a public branch for Github and publish it
    git checkout -b Github_Public
    git push -u origin Github_Public
    
  11. Go to the website for the Github repo, click Settings > Branches, and change Github_Public to be the default branch

  12. Commit/push the Github_Public branch. Switch to the master/main branch.

  13. Add a file named Procfile that contains the following
    worker: node index.js
    
  14. Check that .gitignore is empty. Go to Heroku’s website. New > Create New App.
    heroku login
    heroku git:remote -a goodnitebot
    git add .
    git commit -am "make it better"
    git push heroku master
    
  15. Back to Heroku’s website. Click on your app, then Resources. Edit > disable Web > Confirm. Edit > enable Worker > Confirm. Check Twitter.




RECENT POSTS