Skip to content

Instantly share code, notes, and snippets.

View acbart's full-sized avatar

Austin Cory Bart acbart

View GitHub Profile
@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 / 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 / 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
# -*- 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 / blockly_to_svg.js
Last active August 5, 2024 00:03
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';
@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) {
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
(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
@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',
@acbart
acbart / gist:75e8ae0bec497da18b60
Last active August 29, 2015 14:28
Why is computing hard to learn?
I’m not familiar with that article, but it reminds me of one of my “first day of class” lectures.
Imagine you were assigned to write a 20-page paper, by the end of the semester, on Napoleon’s invasion of Russia. What would you need to know?
[Guided classroom discussion, usually producing something like the following:]
Know about Napoleon and Russia
Know how to do library research
Know how to structure a 20-page paper so it’s coherent.
Know how to budget your time so you finish it by the end of the semester
Now suppose you were required to write this paper in Swedish, using a quill pen. What else would you need to know?