Google Apps Script full stack?

A few weeks ago I brushed off my google apps scripting rust and managed to learn how to do a mass ownership change for a colleague who was leaving the institution. It always takes me a while to remember how everything works but I got it done (note: it’s doable, but the script has to be run by the original owner and the new person has to be in the same institution. Also, stupidly in my opinion, google gives the new person ownership of the entire directory structure, but it also puts the top-level label on every file and folder so it seems like all that stuff is at the top level — hence a second script I wrote for the new owner to run that gets rid of those labels).

Then my brother was interested in a web page that would work on his phone that would help him check in his bike shop customers. So I dug in a little deeper in to google apps script web apps. That’s what got this current fire really going (note: I made a page that’s driven by a simple spreadsheet that has items and price estimates in one sheet and work-order quotes in another sheet. He calls up the page and sees checkboxes for every item in that first sheet. He checks whatever makes sense and hits submit. He’s then shown a cost estimate where he can add notes (like customer name, etc) and hit submit again to save it in the second sheet).

Ok, so here’s what I’m working on and wondering about: Could I use google apps script web apps on some some small-scale full stack problems I’ve been working on? I do a lot of PHP/Laravel/MYSQL/LAMP/Javascript/CSS full stack programming, but it’s often overkill for a simple thing (like my brother’s problem). I do Laravel instead of python/Django, Ruby on Rails, or Meteor mostly because it’s easiest to get the sys admins at my institution to support PHP. Whatever, they all have basically the same functionality (and the same rabid fan bases). So I know how to do fully-functional database-driven web sites. That’s not my problem. Instead I’m interested in GAS web apps because they offer an intriguing list of opportunities:

  • No server to set up. It’s just google
    • baked in reliability etc
  • Super easy authentication/authorization. It’s already built in to the google ecosystem
  • The data layer looks and acts like a spreadsheet
    • Note that google sheets are promoted as spreadsheets but they’re really quite powerful due to “query” (see below) and the interconnectedness with all the other google stuff
    • End users are way more willing to engage with a data layer that looks like a spreadsheet than a mysql database. Take my brother, for example. I didn’t have to make a front-end script to allow him to change his price list. He’s perfectly happy to do that right in the spreadsheet
  • emailing is easy.
    • In Laravel, for example, you have to set up the right package, turn on SMTP stuff, and make sure you’re not pissing off your sys admins
  • Single page apps
    • I’m not actually sold on this, but I notice it in the PR sites I’ve been perusing. Basically you can just load one site and then interact with the server to change portions of the page. I did a ton of this with my “myTurnNow” app that lets up to 100 people engage with each other without having to raise their hands. But it sure it easier to use old fashioned “submit” buttons with multiple pages (yes, Meteor users, I know, I know, . . . shut up!)

So I decided to write this blog post not so much as a “how you do it” as “should I do it?” Most of those points above are interesting, but maybe I shouldn’t be so afraid to just fire up a fresh Laravel app and do even little stuff.

Here’s some downsides:

  • It’s kind of slow. You are having the script access a google drive doc and do stuff. That access is what’s seemingly pretty slow. If you just do non-data-layer stuff it’s pretty quick, but it’s noticeable so I thought I’d mention it.
  • Really playing with the data almost always requires running google sheets formulas. You don’t have to do this. Most of the web sites suggest just sucking all the data in and dealing with it in javascript. I think that’s fine unless you think the data’s going to scale a little. If you google “use google apps script to run sheets formulas” you’ll see a few “impossibles” in your results, but don’t despair! You can do a very dumb sounding thing:
    • Create a new sheet programmatically
    • Set the top left cell of the new sheet to something like “=query(mycoolsheet!A:E,  \”select max(A), B group by B\”)”
    • Read any data on that sheet into javascript/GAS
    • Delete the sheet
  • Ok, yes, I know, that seems really dumb. But I’ve done it a bunch now and it seems to work. It gives you access to the fantastically useful “query” formula and it dramatically reduces the amount of data you’d suck into javascript. Also you don’t have do basically rewrite your favorite spreadsheet formulas into javascript.
  • Weird urls: these are crazy looking but who cares (tinyurl exists, after all)

My current project: I need to write a bunch of reviews for a bunch of folks (I am in the dean’s office these days, after all). I want to be able to access both the formal stuff I’ve written and any notes that I have for this year and all years for every person I’m reviewing. I could do this in a heartbeat (ok, a day) in Laravel, but then I’m the forever owner, even when I’m out of the dean’s office. Doing this in GAS seemed like a fun project and, if it’s successful, I can just transfer ownership to someone else.

I’ve got it working, after lots of fits and starts, and now I’m writing to you, dear reader, to find out if it’s worth exploring more and putting this tool in my tool chest.

So what do you think? Here’s some starters for you:

  • Laravel sucks. If you’re not doing Ruby you’re just dumb
  • This is really interesting. What’s the learning curve like?
  • Laravel sucks. If you’re not doing Django you’re just dumb.
  • I really like the ______ aspect of this. Do you think that you could also _______?
  • Laravel sucks. If you’re not using Meteor you’re just dumb.
  • Tell me more about myTurnNow, that sounds really useful
  • Laravel sucks. If you’re not using carrier pigeons you’re just dumb.
  • I’ve used GAS and have come to the conclusion that . . .
  • You never explicitly said that GAS was google apps script so I stopped reading. You suck.
Posted in HUWebApps, programming, Uncategorized | 3 Comments

Helium whistling

Earlier today my son asked me a question I didn’t know the answer to. So I took to twitter:

A few people chimed in on twitter, but mostly they suggested I try the experiment. Being that son’s birthday today we happened to have some helium around. So we tried it. But before we did (and before I let you see the video . . . oh, you went down and watched the video and are now back up to this paragraph, I see how it goes) we thought about how we’d know if your whistle sounded different. So we tested each other to see if we could match pitches. We also used the piano to give random pitches. By the way, I’ve talked before about my ability to match a pitch while whistling.

So, here’s the experiment:

My take, especially at the end, is that it did affect my whistle.

So here’s my theory: The helium changes the speed of sound in my mouth cavity which raises the resonant frequency of the effective Helmholtz resonator. Really that’s the same thing that happens when you talk with helium. There the helium doesn’t affect the vibrations of your vocal folds/chords since that’s decided by the tension in them which is decided by you. However, those vibrations have lots of resonances and the helium in your oral chamber raises the resonances of the chamber so higher resonances of the vocal folds/chords are amplified making you sound higher. Since the resonances of the vocal folds/chords are roughly harmonic, you typically sound an octave higher.

When you whistle you aren’t choosing the tension of your vocal folds/chords. You are shaping your lips/mouth cavity from memory to be a shape that causes a Helmholtz resonance with a particular frequency. When you have helium in your mouth, the resonance goes up and so does the frequency you hear.

So what do you think? Here’s some starters for you:

  • Why do you keep saying vocal folds/chords?
  • What about the other kind of whistle where some people use their fingers?
  • How do we know you were trying just as hard to match the pitch when you claimed that it wasn’t right?
  • I don’t think you understand how sound is generated at all in both whistles and talking. Here’s a tutorial for you.
  • So you decided to pop your son’s balloon? On his birthday? What kind of monster are you?
  • Why are you too lazy to see if the heard frequency compared to the expected frequency matches the ratio of sound speeds in helium and air?
  • You wrote “raises you whistle” instead of “raises your whistle” in your tweet. How do you ever expect people to take you seriously?
  • You posted this before the youtube video was ready. What, you think I have the time to come back when it’s ready? Thanks for nothing, loser.
Posted in fun, physics, teaching, twitter | 3 Comments

Blooming energy

Today I saw that the tree outside my office window had blossomed over the weekend:tree

So I got to wondering how much energy it had used to do that. I asked the question on twitter

and got a lot of interesting answers involving mass/energy, carbon bond energy, etc.

I’m not sure what the answer is, so I thought I’d post about it to see what other answers I could get. I’m really interested in what happened over the weekend, and I have a hazy memory of seeing tiny green buds before the weekend. So really I figured the buds all existed and just had to be forced out. I figured something had to move a few centimeters with, say, a kg-weight worth of force. That’s just me guessing though.

Of course with that approach (and really all the approaches people were using on twitter), you have to have an estimate of how many blooms there are. So I decided to see if Mathematica could help me with that.

I imported the image and used the image mouse-over tools to find the color of the blooms. Then I set all pixels that weren’t within a ColorDistance of 0.2 (found empirically) of that color to black. Then I did a DistanceTransform of that to replace all pixel values with the distance to the nearest black pixel. Then I used MaxDetect on that to find the centers of all of the blooms. Then I used MorphologicalComponents and ComponentMeasurements to count them (just under 3000) and HighlightImage to make this image:treehighlight

I think it did a pretty good job of finding all the blooms that way.

So, with roughly 3000 blooms in a period of 3 days, how much energy did it take? I’m not sure but I hope you can help.

Here are some starters for you:

  • What’s wrong with a mass/energy approach?
  • Just cut some off, burn them, and see how much you raise the temperature of water. Then multiply!
  • Why didn’t you use ImageJ for this? (here’s the link to the original image if you want to try)
  • The way you calculated the number of blooms is dumb, a much better way is . . .
  • Why do you care about the energy, I thought you said energy doesn’t exist?
  • Why can’t you just enjoy the view instead of ruining it with all this science?
  • On twitter you said that the tree sprouted. What are you, an idiot?
  • If you’re asking about energy, why does the three days part matter?
  • You didn’t say anything about seeing some green before the weekend on Twitter, thanks for having me waste my day.
Posted in technology, fun, mathematica, physics | 3 Comments

Quantum economies in higher ed

Well, I’m in the dean’s office now. Pause while the wordpress server handles the sudden exodus from this page. Ok, now we’re ready. I wanted to get some thoughts down (and seek useful advice from you, dear reader) about how we can incentivize various activities in higher ed. The reason I titled this “quantum economies” is that I’m realizing that most of my incentives (carrots and sticks) come in quite large chunks. What I’m trying to figure out is a way to have smaller chunks at my disposal.

I just got back from a conference that was all about assessment of general education in higher ed. Most of the people there have either a) drunk the koolaid about assessment, or b) have accreditation breathing down their necks. I’d say I’m really in both camps. One of the most common points of discussion in the hallways was how to get better buy in for various assessment activities on our various campuses. Some give stipends to those who really try to i) collect data, ii) analyze data, and iii) make changes accordingly. Some make sure to give a shout out to programs that are doing some or all of all 3 of those things. But I have to say that most of us were feeling like we don’t really have great ways to incentivize programs to do this necessary work.

So I thought about what we do. One thing we do is explicitly pay attention to the assessment work that departments have done when doing both program reviews and reviews of new hire requests. Some at the conferences were aghast when I told them that latter one, but for me it feels appropriate. My problem is that it’s too big. Our departments hire on average every 5 years or so, and our program review cycle is similar. That’s too rare and too big to really make the day-to-day incentives that I’m looking for. The problem for me is that we don’t have that many other program-level sticks or carrots.

I did have one idea that some at the conference thought was amusing. Some said that it would definitely work while others just assumed I was joking. I’m not sure. I definitely originally thought of it as a joke but maybe there’s something to it. What do you think: If your program doesn’t do assessment work, all (or most? or many? or more than usual?) of your classes have to be at 8am. We struggle a little to get people to teach at that time (I could write a whole other post about the interesting conversation on our campus about that time slot) and most would rank it towards the bottom of their favorite time to teach. Some at the conference also talked about courses that meet on Fridays in a similar vein.

This is definitely smaller than “you can’t hire” but it’s still pretty . . . petty I guess is the right word. At the conference others talked about how it would be great if getting to teach a gen ed course was something people fought over. They talked about how if those were the only, say, 18-person capped classes on campus then people would beg to teach them. Basically we were all trying to find ways to reward those who do good work (again: i) measure, ii) analyze, iii) correct) and, I suppose, punish those who don’t. One problem, of course, is the vicious negative cycle the “bad” programs would undergo with most if not all of these ideas.

So I’m still kicking around some thoughts. I’d love to get some more from you. I guess my goals are:

  1. That we find a better way to value assessing our learning outcomes.
  2. That we incentivize programs to do that hard work and take it seriously.
  3. (most importantly) that we become better at serving our students.

I’ll end with my favorite quote from Kathleen Landy at the conference:

Assessment is not an autopsy, it’s a physical.

Thoughts? Here are some starters for you:

  1. That’s not at all what ‘quantum’ means. It’s clear you’re on the dark side of administration if you can’t even remember that from your physics teacher days. I’m out.
  2. I tried to leave this page but wordpress insisted I stay and read all this drivel. That’s 5 minutes I’ll never get back.
  3. I like the idea of ____ but I think a better twist on it would be . . .
  4. I hate the idea of _____ though I suppose you could make it better by . . .
  5. Who is General Ed? What’s his last name?
  6. Boy for me assessment of learning outcomes is definitely a bloody autopsy. What do you mean by it being a physical instead?
  7. I love teaching at 8am, this didn’t make any sense to me at all.
  8. Instead you should punish programs by …
  9. You should never use sticks, you should always use carrots and here’s why . . .
  10. You should never use carrots, you should always use sticks and here’s why . . .
  11. You should make any department that’s not doing their assessment do all their programming in python (long time readers will get that)
Posted in dean, Uncategorized | 11 Comments

Lasers bouncing inside stuff

I’ve written before about how I sometimes like to imagine what would happen if you shot a laser in a fully mirrored room. Back then I did a bunch of cool stuff with flat walls, mostly by calculating the distance beyond the wall a bouncing ball was and having a potential energy function that brought the ball back. Recently I’ve been trying to figure out how to do that in much more complex shapes so I’ve been playing around with Mathematica’s “Region” capabilities. It took me a while, but I think I finally have a decent version with arbitrary shapes.

For those that don’t want to read any more, here’s a laser bouncing around inside a cow:

perfect (non-diffracting) laser beam bouncing around inside a cow

perfect (non-diffracting) laser beam bouncing around inside a cow

I was hoping that there would be an easy function like “normal to surface” or something but I couldn’t find anything close enough. There is a nice “RegionDistance” function that tells you how far from a region (a cow) you are. Unfortunately I couldn’t use that as my potential energy because to do the differential equation solving I need to be able to take a derivative of that (that’s what gives you the forces and hence the acceleration of the ball) and Mathematica didn’t really like that (I don’t blame it, it’s not really a differentiable function).

So then I started playing around with “RegionNearest” which tells you what part of a region is closest to your current position (ie the position of the ball). With that, here’s what I do:

  1. Define the region (cow=ExampleData[{“Example3D”, “Cow”}, “MeshRegion”])
  2. Find the boundary of the region (BoundaryRegion[cow])
  3. Launch the laser/ball
  4. Constantly check to see if the position is within some small distance of the boundary
  5. If it is, find the nearest point on the boundary and use that to determine the normal to the boundary (current point minus the boundary point).
  6. Use the normal vector to reflect the velocity vector
  7. repeat 4-7 until your computer crashes.

What’s really handy is the “WhenEvent” feature of Mathematica’s differential equation solver “NDSolve.” WhenEvent basically does part 4 above and triggers the function for 5 and 6. It’s so useful that I use it for this situation that isn’t really a differential equation. Basically I just say the force is zero everywhere and add the WhenEvent feature to do the reflections. It works great!

I should note that I started this project wondering what happens in a sphere. But it turns out that it’s super boring:

Then I went on to an ellipsoid, but that was pretty boring too. So, I went with the cow (my sons helped pick that). When my son saw the one above, he was really interested in what happens when it goes down a leg. Here you go:

going down the leg

going down the leg

Cool, huh?

Thoughts? Here are some starters for you:

  1. I’m in this class and … wait … nevermind
  2. This is cool. I especially like . . .
  3. This is dumb, you forgot about . . .
  4. You should try this shape . . .
  5. Why didn’t you use python to do this?
  6. How do you do the vector math with the normal vector and the velocity vector to do the reflection?
  7. What if the cow moves?
  8. Wait, I thought you were in the dean’s office now. Why are you still doing this cool stuff, aren’t you just a stuffed suit?
  9. Why do you only sometimes italicize the word Mathematica?
Posted in fun, mathematica, physics | 3 Comments

Non-majors teaching tools

This January I’m teaching a 4-wk intensive course called “Hamline Mythbusters”. On the first day of class I verified my assumption: this would be the last science class ever taken by nearly the whole class. They’re almost entirely seniors (the class filled in 10 minutes on the first day of registration) and they’re using this class to fulfill our disciplinary breadth requirement. I’ve been doing a few fun things in this course and I just wanted to get a few of them down here.

Estimation day

On estimation days the students work in groups to determine things like “how many piano tuners work in the twin cities?” or “how many gallons of gas are used in the US every year?” My grading scale is determined by:

\text{score}=100-10 \left|\log_3\left(\frac{x}{\text{actual}}\right)\right|

which is the same as saying a letter grade off for every factor of 3 you are off from the actual answer.

We’ve only had one of these days so far (the gas question) and I was really pleased with the result. Out of the 11 teams, only 2 were more than a factor of 3 off and both of those were due to a simple mistake where they multiplied by average gas mileage instead of dividing. It took the slowest team an hour so next time (tomorrow) I’m going to do multiple ones so that the groups can divide and conquer.

The connection to science is just developing a good number sense and to realize that they know a lot more than they think they know. By the way, I put a box at the front of the room so that they couldn’t just google all the answers:

20170106_111857

Debate day

The day before debate day (actually on Friday to prep for Monday) they are told to bring in 2 pro and 2 con sources for debate day. On our first debate day we did “The US should use nuclear power for it’s dominant source of energy.”

In class they broke into the pro and con teams (randomly) and were tasked with finding 5 main topics and to break into groups to develop good quotes from their sources about their topic. Each group in the main debate was responsible for presenting one new idea and rebutting one idea from the other side. The debate ran: pro new idea, con rebuttal, con new idea, pro rebuttal repeat.

I mostly enforced the rule that when they presented they had to basically just read from their sources. This really worked well! My only complaint is that they didn’t really attack each others’ sources’ authenticity.

I graded the efforts with 50% of the points for turning in their annotated sources (making clear which quotes they used) and 50% based on a reflection paragraph on who won and how the authenticity of the sources affected the debate (the consensus was that it didn’t).

What If blog post

I told them to familiarize themselves with Randall Monroe’s What If blog and to prepare a blog post of their choosing. I’ve graded the first drafts so far and they’re all doing some pretty interesting things, ranging from picking on Trump through ice in place of sidewalks to having all cats disappear. I’m encouraging them to really take things to as many new levels as they can. They’ve got some work to do on future drafts, including drawing some funny/ironic cartoons, but I’m really excited about where this is going.

10 100 word assignment

Borrowing again from Randall Monroe, I’m asking them to submit an explanation of a scientific or technical things using the 10 100 most used words in the English language. That’s what they’re doing peer editing on as I type this post.

We talked about the analogy between a scientist needing to change her vocabulary when talking with the general public and them having to do this assignment. We talked about possibly allowing a glossary where they could introduce new words that must be defined using the 10 100 words.

Lateral thinking

Lateral thinking puzzles are those party games where you lay out a situation and the audience has to ask yes/no questions to determine the whole story. Here’s an easy one: 5 pieces of coal, a carrot, and a scarf and found on a lawn. There’s a logical reason why they’re there, what is it? The answer is that a snowman melted.

I’m using them sparingly (ok, I did 3 of them today) because I think they are good practice for the questions they need to ask themselves during their mythbusting explorations. To do well at lateral thinking puzzles you have to constantly question your assumptions and double check what you think you know. Sound familiar? I think it’s quite similar to the traits of good scientists!

Ok, that’s all I’ve got for now. It’s a fun class, though the grading is killing me. Do you have any thoughts? Here are some starters for you:

  • I’m in this class and I really love ____ and here’s why.
  • I’m in this class and I really hate ____ and here’s why.
  • Why don’t you say the 1000 most used words instead of ten hundred?
  • What rubric do you use for assessing these writing assignments?
  • Wait, where’s the Mathematica assignmen? (that’s for Rhett as long-time readers will recognize)
  • What if they make a different assumption during the estimation day than your google search that provides the so-called “actual number?”
  • I think lateral thinking is not a good analogy for problem solving and here’s why. Instead you should ____.
  • How much is Monroe paying you? (He probably doesn’t actually like me very much.)
  • I hear you’re moving into the Dean’s office. Are you just mailing this course in?
Posted in syllabus creation, teaching, Uncategorized | 2 Comments

Physics majors practice presentations

For years we’ve been working to give our physics majors opportunities to improve their presentation skills. We do a lot of oral exams but we also want our students to do well in more formal settings. We have a junior/senior seminar that the students take for 4 semesters, and they have to present in three of them. For their first one (fall of their junior year typically) we don’t want them to stress out over physics content so, assuming they don’t have a research project to report on, we tell them to give us a short presentation on a general physics concept that they understand well. This post is my thinking on how to improve that.

Typically students pick something like a projectile problem and they present it kind of like a mix between an oral exam and a mock teaching situation. The former is weird because it’s usually a really easy problem (for juniors) and the latter is problematic because that kind of presentation tends not to be how we’d choose to teach the material (no interactivity, for example). Normally we end with some token physics criticism/question but them concentrate on suggestions for how they could present better.

My biggest problem with this setup is how fake it is. It’s not the type of presentation they’ll likely be giving in the future. Then they’d much more likely be talking about a data-driven decision or conclusion they’ve reached. They likely wouldn’t be defending their understanding of a simple concept and they certainly shouldn’t be teaching like that (mostly dark room, only one person talking, etc).

So my current idea is to have them still have a pretty safe and easy thing to prepare but to have it be much more in the spirit of the types of presentations we’d like to see from them. I thought it might be cool if they could present their data from a lab they’ve already done. It might be a simple lab from general physics or something, so likely none of us would be surprised by the outcome, but they could be asked to approach it as trying to convince someone of the conclusions they’ve drawn. We could then really help them focus on what aspects of the presentation need focus (well done data plots, clear explanation of any theory necessary, etc). We still might make minor physics criticisms or questions but we could focus on the presentation skills we really care about.

I figure we could ask students in their first one or two physics classes to pick the lab write up they are most proud of and we could keep it for them to hand back when their juniors. We could do that early in the semester so they could have time to get their presentations ready.

Your thoughts? Here are some starters for you:

  • I’m in this class and I like this plan a lot, here’s why . . .
  • I’m in this class and this is a stupid plan, here’s why . . .
  • Why not force them to do an actual experiment? You act like it’s only worth 0.5 credits or something.
  • Would this work for the labs that are more along the lines of verification labs (“yep, I get 9.8 m/s/s”)?
  • Why have them pick their best one? Maybe the lab instructor should pick it
  • Maybe you could make sure that no two students do the same lab. Here’s how I’d set that up . . .
  • I like presentations based on ________ better, here’s why . . .
Posted in syllabus creation, teaching | 5 Comments