This summer I was working on translating a project with a dozen Python classes into Javascript ES6 classes. The following are “notes to myself” about the substitutions that can be made automatically in order to speed up the translation process.

replace all (this –> with that)
def __init__ --> constructor
def -->
(self): --> (){
(self, --> (
): --> ){
self. --> this.
# --> //#
else: --> }else{
print( --> console.log(
int( --> Math.floor(
str( --> (""+
True --> true
False --> false
None --> null
and not --> && !
if not --> if (!
while true: --> while (true){

The following substitutions need to be made manually (one at a time).

find and replace manually
and --> &&
result = --> let result =
temp = --> let temp =
.append --> .push
len(foo)
for i in range(
for each in --> for (let each of
while
.insert(0,"foo") --> .splice(0,0,"foo")
a in b --> b.includes(a)
@staticmethod \n def --> static
@classmethod \n def --> static
.sort(key=lambda x: x.getGrade(), reverse=False) --> .sort(function(a, b){return a.getGrade() - b.getGrade()})
.sort(key=lambda x: x.getGrade(), reverse=True) --> .sort(function(a, b){return b.getGrade() - a.getGrade()})


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




RECENT POSTS