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 / CMSI284S2018HW1.md
Last active January 17, 2018 00:04
CMSI 284 Spring 2018 Homework 1

Do all these problems without the aid of a computer. The purpose of these exercises is for you to develop skills. If you spend the time to practice with pencil and paper (or a whiteboard) you will learn the material much better.

To submit your answers, copy the text below into a secret gist on GitHub and fill in the answers at the end of the same line. Email or DM me the url of the secret gist.

Make sure your Gist filename is CMSI284S2018HW1.md.

Your submission will be autograded so it is imperative that your answers are formmatted as expected; for example, if a 32-bit hex value is required, you are to use 8 hex digits, without ever doing silly things like removing leading zeros or putting spaces or commas between digits. Same with binary values (never omit leading zeros) and with decimals (no spaces, no commas). MAKE SURE YOUR GIST HAS EXACTLY 64 LINES, NO MORE, NO LESS. Answers that are "correct" but not in the proper format will receive zero points, since answers that follow ins

@rtoal
rtoal / tv.swift
Last active December 20, 2017 19:19
Smart TV Virtual Keyboard Trace
struct Coordinate {
var row: Int = 0
var col: Int = 0
}
var coordinateMapping: [Character: Coordinate] = {
var mapping: [Character: Coordinate] = [:]
for (index, letter) in "ABCDEFGHIJKLMNOPQRSTUVWXYZ".enumerated() {
mapping[letter] = Coordinate(row: index / 5, col: index % 5)
}
@rtoal
rtoal / Test.md
Created October 14, 2017 00:01
Try this JavaScript/Python Test

CMSI 386 Fall 2017 Exam 1

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 / sizes.cpp
Created October 2, 2017 03:24
A C++ program with a crazy macro to print ranges of numeric types
#include <cstdint>
#include <climits>
#include <cassert>
#include <iostream>
using namespace std;
#define show_type_range(t, min, max)\
cout << #t << " (" << sizeof(t) << " bytes): " << min << ".." << max << '\n';
@rtoal
rtoal / [-8] < 0.md
Created June 18, 2017 04:39
Is [-8] < 0?

Clojure

user=> (< [-8] 0)

ClassCastException clojure.lang.PersistentVector cannot be cast to java.lang.Number

Python 2 (BOOOOOOOOOOO)

&gt;&gt;&gt; [-8] &lt; 0
@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 / offside.js
Created March 12, 2017 01:34
An illustration of preprocessing lines of text for later use of the offside rule
const program = `
def f(x):
y = 0
while x < y:
if p:
x = 3
else:
for x in range(10):
@rtoal
rtoal / translation-telephone.md
Last active January 11, 2017 08:10
A translation telephone example

English

She's feeling under the weather so will work from home today, with a laptop and cup of tea

Afrikaans

Sy gevoel onder die weer so sal werk van die huis af vandag, met 'n skootrekenaar en koppie tee

Hindi

वह मौसम के अंतर्गत महसूस किया तो एक लैपटॉप और एक कप चाय के साथ आज घर से काम करेंगे

Bulgarian

@rtoal
rtoal / htmlCollectionIteratorPolyfill.js
Created December 14, 2016 16:52
Polyfill allowing iteration of Safari's HTMLCollection objects
// Polyfill because Safari's HTMLCollections are not iterable
if (typeof HTMLCollection.prototype[Symbol.iterator] !== 'function') {
HTMLCollection.prototype[Symbol.iterator] = function () {
let i = 0;
return {
next: () => ({done: i >= this.length, value: this.item(i++)})
}
};
}
@rtoal
rtoal / Arithmetic.json
Created December 8, 2016 22:07 — forked from mroeder/Arithmetic.json
Arithmetic Grammar for Ohm
[
{
"text": "2 * (42 - 1) / 9",
"startRule": "Exp",
"shouldMatch": true
},
{
"text": "1+2*3",
"startRule": "Exp",
"shouldMatch": true