Skip to content

Instantly share code, notes, and snippets.

View brainysmurf's full-sized avatar

Adam Morris brainysmurf

View GitHub Profile
import time
prompt = """
You have a choice:
a) $1 million, right now
b) $0.02 right now, then doubled every month
"""
while True:
@brainysmurf
brainysmurf / CollectColumnsThatContainsNames.md
Last active September 24, 2023 12:06
Learn how to identify and output all columns that have certain text

GSheets Formula Tipizoid #1

Learn how to collect a series of columns that that contains target text in the header. Link to Example

The data

You have a database-like table in a Google spreadsheet that is the output of a Google Form that asks questions on a variety of topics. The form itself is organized into sections, where the the first question ("What grade are you in?") will then jump to the relevant section with grade-specific questions. Each section has some questions that repeat ("English") but others that do not ("Design" because students don't take Design until 9th Grade). The result is the following:

        (  First section in form   ) (    Second section in form   )
@brainysmurf
brainysmurf / README.md
Last active July 28, 2019 04:25
A post mortem of writing a kernel in Jupyter notebook with metakernel

Writing a custom kernel for Jupyter

Introduction / movitation

Already, Jupyter notebook system is great for sharing course content, and does it in a way that I can constantly write and improve it. However, there was one drawback in the course that I'm offering (IB Diploma Computer Science) and it's that it teaches Pseudocode, and not any official language. That means that I can't just ask them to open the terminal, or use a text editor and execute.

However, like all Open Source tools, Jupyter is very customizable. So I set to work. This is what I wanted:

  1. students can input pseudocode from scratch
  2. student can play with and improve code provided to them
@brainysmurf
brainysmurf / import.py
Created December 24, 2019 11:46
Installing package into IDLE
import subprocess
import sys
subprocess.check_call([sys.executable, "-m", "pip", "install", "arcade"])
# If you wish to reverse the install, uncomment the following line:
# subprocess.check_call([sys.executable, "-m", "pip", "uninstall", "--yes", "arcade"])
try:
@brainysmurf
brainysmurf / README.md
Last active November 5, 2020 07:38
Concurrency (lack thereof) in Google Apps Scripts V8

Concurrency in Google AppsScripts (V8)

Steps to reproduce

  • Run useForLoop independently, and observe it takes about 7 seconds to complete
  • Run entrypoint which calls useForLoop three times, asynchronously
  • Observe that the second run takes at least three times as long as the first run to complete
  • Repeat the process above but in a browser, and observe the expected behaviour

Conclusion: Even though the documentation indicates that you can define async functions, and that you can make Promises, it ain't actually async.

@brainysmurf
brainysmurf / submit.md
Created February 13, 2020 00:36 — forked from tanaikech/submit.md
Benchmark: Reading and Writing Spreadsheet using Google Apps Script

Benchmark: Reading and Writing Spreadsheet using Google Apps Script

October 12, 2018 Published.

October 18, 2018 Updated. In order to compare with Advanced Google Service, a result of Sheets API by UrlFetchApp was added to Appendix.

@brainysmurf
brainysmurf / README.md
Last active February 13, 2020 11:57
Loop Benchmarks: V8 vs RHINO

Loop Benchmarks: V8 vs RHINO

Looping code was written to be compatible with both engines. It simply does nested loops with multiplication in the body.

  • Conclusion: V8 is way faster.
  • Caveat: This does not paint a complete picture.

Results:

RHINO

@brainysmurf
brainysmurf / Code.js
Created February 22, 2020 03:40
'use strict' and Google AppsScript with V8 Runtime
function globalStrictMode_() {
'use strict';
return function () {
return this; // returns null in strict mode, global object if not
}.apply(null, []);
}
function globalDefaultMode_() {
return function () {
return this; // returns null in strict mode, global object if not
@brainysmurf
brainysmurf / README.md
Last active December 25, 2023 03:00
Named parameters, required parameters, and interfaces

Interfaces in Javascript for Google Apps Scripts

I really like named parameters. I can live without them, but there is one place where I really need them. Cases in which I want to create a class and the paramters are guaranteed to be present, nothing extra. This is one way of implementing them. (It's kinda ugly, but kinda cool.)

Project Key

Either copy into your project, or use as a library: MWzXfEDYTWuJ_Xj0ap9H8-68b30WIDiE_

Wrong behaviour

@brainysmurf
brainysmurf / README.md
Last active June 21, 2024 05:53
Things one can get used to for the V8 Google Apps Scripts engine

Things one can get used to for the V8 Google Apps Scripts engine

A bit of a monologue about various syntax changes and adjustments in learning and using the tool.

Logging is slooooooow

I know. Everyone knows.

That's why I wrote a library that writes to a spreadsheet instead. Ever since I started using it I'm far more productive. I don't know how people are still putting with that god-awful lagging logger.