Skip to content

Instantly share code, notes, and snippets.

View acbart's full-sized avatar

Austin Cory Bart acbart

View GitHub Profile
@acbart
acbart / canvas_edit_external_tool.js
Last active July 27, 2018 22:17
Snippet to modify an external tool on Canvas via JS.
// Query to GET a list of external tools, filter it for your tool, and then PUT it's changes
// Need to change the <course_id>, add your filtering criteria, and
// customize your data attributes for the tool.
$.get('https://canvas.instructure.com/api/v1/courses/<course_id>/external_tools/', {}, function(result) {
$.each(data, function(i, item) {
if (item /* matches some criteria, maybe the name? */) {
$.ajax({ url: 'https://canvas.instructure.com/api/v1/courses/<course_id>/external_tools/'+item.id,
type: 'put',
data: {'course_navigation[enabled]': 'true',
(require 2htdp/image)
(require 2htdp/universe)
(define PMAX 10)
(define CELL-SIZE 30)
(define-struct cell (value polluted? x y))
;; make-cell: number boolean number number -> cell
;; A cell has a value indicating permeability,
;; a flag indicating whether it has been polluted yet
with open('data', 'r') as inputFile:
with open('sampled', 'w') as outputFile:
for index, line in enumerate(inputFile):
# and maybe grab 3 more lines?
outputFile.write(line)
if index > SAMPLE_SIZE:
break
@acbart
acbart / ast_node_visitor.js
Created April 6, 2016 02:37
ast.NodeVisitor for Skulpt
/* Just a silly little bit of example code */
var filename = '__main__.py';
var python_source = 'a, b = 0';
parse = Sk.parse(filename, python_source);
ast = Sk.astFromParse(parse.cst, filename, parse.flags);
/* Actually useful stuff, taken from
https://github.com/python-git/python/blob/master/Lib/ast.py#L219 */
var iter_fields = function(node) {
@acbart
acbart / blockly_to_svg.js
Last active May 23, 2016 03:51
Blockly SVG -> Image
function renderSimple(workspace) {
aleph = workspace.svgBlockCanvas_.cloneNode(true);
aleph.removeAttribute("width");
aleph.removeAttribute("height");
if (aleph.children[0] !== undefined) {
aleph.removeAttribute("transform");
aleph.children[0].removeAttribute("transform");
aleph.children[0].children[0].removeAttribute("transform");
var linkElm = document.createElementNS("http://www.w3.org/1999/xhtml", "style");
linkElm.textContent = Blockly.Css.CONTENT.join('') + '\n\n';
# -*- coding: utf-8 -*-
"""
Created on Thu Jan 25 23:27:40 2018
@author: acbart
"""
import unittest
from unittest.mock import patch
import io
@acbart
acbart / accidental_recursion.py
Created February 16, 2018 01:40
What will be printed?
# Code without call outside, without call inside
def a():
print("a() was called")
# Code without call outside, with call inside
def b():
print("b() was called")
b()
# Code with call outside, without call inside
@acbart
acbart / tktextext.py
Last active February 25, 2018 17:51
Some proposed modifications to tktextext.py in order to support copy/paste of images
# Example URL: https://i.imgur.com/TqN0Be5.png
# This let's you copy/paste a URL into your source code (png, bmp anyway)
import base64
# This is for copying HTTP images
from urllib.request import urlopen
...
class EnhancedText(TweakableText):
def __init__(self, master=None, cnf={}, **kw):
@acbart
acbart / mockplt.py
Created March 1, 2018 05:28
A mocked out version of MatPlotLib
class MockPlt:
'''
Mock MatPlotLib library that can be used to capture plot data.
'''
def __init__(self):
self.plots = []
self._reset_plot()
def show(self, **kwargs):
self.plots.append(self.active_plot)
self._reset_plot()
@acbart
acbart / cs1064_worked_examples_data-documentation.json
Last active April 1, 2018 17:48
A description of the fields in the cs1064 WE dataset
# A list of dictionaries, where each dictionary represents a student and their assignment data
# Each user is uniquely defined by a given name, e.g., "Abomasnow"
# Each assignment's name is the human readable assignment name, e.g., "#43.4) Multiple Returns"
# The "events" key maps to a list of the student's events, given as a list of 4 values.
# The integer timestamp is an epoch time; note that some events trigger at the exact same time.
# Here are some common event/action types:
# code/set is when a student edits their code
# editor/run is when a student runs their code
# editor/reset is when they reset their code, and there's other editor/<Something> actions too
# feedback/<Something> is the specific kind of feedback that the student received