Skip to content

Instantly share code, notes, and snippets.

View rtoal's full-sized avatar
💭
Copying and pasting

Ray Toal rtoal

💭
Copying and pasting
View GitHub Profile
@rtoal
rtoal / JSFirst.md
Last active April 15, 2024 10:23
JSFirst

JS First

About This Manifesto

Have you ever argued for or against teaching language X as the first language in a university computer science curriculum? If so, I hope that your arguments:

  • were first and foremost about students, considering the question “What do we want students to gain from their experience with a first language?”, not “Is language X better than language Y?” because the latter question requires too much context and isn’t really answerable;
  • kept in mind that ultimately we want to train polyglots, so the first language is never the only language; and
  • took into account previous work from computing educators, and education theorists and practitioners in general.
@rtoal
rtoal / MontyPython.java
Created January 8, 2014 02:10
Uses reflection to count like King Arthur with the Holy Hand Grenade
import java.lang.reflect.Field;
public class MontyPython {
public static void main(String[] args) throws Exception {
Field v = Integer.class.getDeclaredField("value");
v.setAccessible(true);
v.set(3,5);
System.out.printf("Ready the holy hand grenade!\n");
Thread.sleep(1000);
System.out.printf("%d\n", 1);
Thread.sleep(1000);
@rtoal
rtoal / UFOCodeAlong.md
Last active September 27, 2023 00:48
Instructions for a UFO 3-D Codealong using the p5js editor

Code Along

Brief notes on a 45 minute code-along I like to do to introduce P5.js, 3-D graphics, variables, objects, conditionals, and animation.

  • (Optional) make an account for the p5js editor
  • Go to https://editor.p5js.org/
  • File -> New if not already at a new file
  • Name it if you like
  • In function setup, replace line with createCanvas(500, 500, WEBGL);
  • Run (hit the "Play" button)
@rtoal
rtoal / enum.py
Last active May 13, 2023 10:06
A lightweight, very convenient function to dynamically create good enums in Python
# Makes an enum class with instances (class attributes) having uppercase
# names while the string representations can be in any case. For example,
# Color = enum_class('Color', 'red', 'amber', 'green') returns class Color
# with members Color.RED, Color.AMBER, and Color.GREEN. The __str__ instance
# methods produce 'red', 'green', and 'blue', respectively. To get the
# instance from the string, use, for example, Color.from_string('blue'),
# which will return Color.BLUE.
def enum_class(classname, *values):
cls = type(classname, (), {})
@rtoal
rtoal / rsa-math-example.txt
Created April 17, 2022 22:15
Python shell session to check RSA-style math
>>> p = 36469
>>> q = 50929
>>> n = p * q
>>> n
1857329701
>>> e = 65537
>>> d = pow(e, -1, (p-1)*(q-1))
>>> d
395695169
>>> m = bytes("¿Dónde está ud.?", "utf-8")
<head>
<link href="https://fonts.googleapis.com/css?family=Courgette|Catamaran|Tangerine|Assistant|Lora|Source+Sans+Pro|Open+Sans|Pacifico|Nothing+You+Could+Do|Lato|Titillium+Web" rel="stylesheet">
<style>
td {width: 150px; height: 150px; text-align: center; font-family:Helvetica}
.js {font-family: Assistant; font-size:450%; font-weight:800; text-align:right; padding-right:10px}
.rust {font-family: 'Source Sans Pro'; font-size: 300%; font-weight: 500}
.python {font-family: 'Titillium Web'; font-size: 250%; font-weight: normal; color:#bbb}
.haskell {font-family: Helvetica; font-size: 225%; font-weight: 500; letter-spacing: -2px}
.java {font-family: 'Open Sans'; font-size: 300%; font-weight:400; color:#eef}
.elm {font-family: 'Open Sans'; font-size: 325%; font-weight: 300; letter-spacing: 5px}
@rtoal
rtoal / ExercisesTest.java
Created October 14, 2020 00:54
Test suite for CMSI 386 Java Homework
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;
import java.util.Set;
import java.util.Map;
import java.util.Optional;
public class ExercisesTest extends TestSuite {
public static void main(String[] args) {
TestSuite.run(new ExercisesTest());
@rtoal
rtoal / TestSuite.java
Created October 1, 2020 04:37
A not-half-bad test framework for Java
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.util.Objects;
import java.util.function.Consumer;
public abstract class TestSuite {
int successes = 0;
int failures = 0;
int errors = 0;
@rtoal
rtoal / practice-midterm.md
Last active October 9, 2019 14:31
CMSI 386 Practice Exam

CMSI 386 Practice Exam

Name: (ENTER YOUR NAME HERE)

Problem 1: Forcing Keyword Arguments

Suppose the boss demanded a function to compute the area of a rectangle. The boss says the function MUST have four parameters, x1, y1, x2, and y2 where (x1, y1) is one of the corner points and (x2, y2) is the other corner point. But since our users can never remember what order the four parameters go in (Is it x1-x2-y1-y2 or x1-y1-x2-y2?), we will make our function REQUIRE that the four arguments in the call be “named.” Note that I said required. The function is not supposed to work if the arguments are not named. In fact, it should be an error to make a call without “naming” the arguments.

a) Write the function in JavaScript:

@rtoal
rtoal / main.rs
Created September 14, 2019 16:06
The guessing game from the Rust book
use std::io;
use std::cmp::Ordering;
use rand::Rng;
fn main() {
println!("Guess the number!");
let secret_number = rand::thread_rng().gen_range(1, 101);
loop {