6
votes
What programming/technical projects have you been working on?
This is a recurring post to discuss programming or other technical projects that we've been working on. Tell us about one of your recent projects, either at work or personal projects. What's interesting about it? Are you having trouble with anything?
I've been planning on using Deno (a batteries-included Node.js alternative with more Typescript focus) for a project, but I'm still getting familiar with Deno and wanted to practice with it. I previously learned Rust by doing some Advent of Code challenges with it, so I decided to do the same thing again with Deno.
When I did the Advent of Code challenges with Rust, I found the aocf library which handled fetching the challenge input while running your solution, which was convenient and allowed me to avoid committing my personal challenge inputs or session cookie into the repository. I decided to make a similar project for Deno: aocd. (And here's an example repo using it: https://github.com/Macil/deno-advent2021.)
I also made it so Aocd has a built-in template for setting up a new project directory for Advent of Code solutions. I wanted Aocd to provide a recommended answer on how to use it end-to-end, to be a good tool for people learning Deno, and to be quick to use so people could focus on the Advent of Code challenges themselves.
I found Deno to work really well for Advent of Code. It had refreshingly little boilerplate compared to my previous solutions using Rust. When using Rust, it took me too much time just figuring out how I wanted to organize my code. With Rust, I ended up splitting every day's solution into its own package in a Cargo workspace, so each day's solution required its own couple subdirectory and Cargo.toml config file. With Deno, I mainly just have a folder of
day_NUMBER.ts
files, and any of them can be executed directly by itself. There is no package manager config at all necessary to make the source scripts work. There are some config files in the repo for VS Code and making CI tests works, but none of it is involved in how Deno executes one of the solution scripts. A solution script could be copied out of the repo by itself and still have what it needs to execute the same way elsewhere. (It bugged me a little bit how when people posted their code here in the Tildes Advent of Code threads, most people's code wasn't usable by itself without a package manager config that wasn't supplied; Deno doesn't have that issue as all library imports are fully qualified in source.)I also added a neat little feature to Aocd: safe-run. It lets you take a Deno script that uses the Aocd library for fetching a problem input, and run it within Deno's default sandbox, entirely closed off from the internet or your computer's files, except that it's allowed to fetch problem inputs from your account and optionally submit answers if you passed that flag in. The sandboxed script isn't allowed to read your Advent of Code session cookie or manipulate Aocd's cache; it's only allowed to do use stdin/stdout or talk to the parent Aocd process which handles that. This is useful if you want to try out someone else's solution script (maybe they're getting the wrong result and want help debugging it) and you haven't fully reviewed their script (and its imported libraries) to be sure it won't try anything malicious on your computer. You can even use safe-run to run a script directly from a URL:
aocd safe-run https://raw.githubusercontent.com/Macil/deno-advent2021/main/day_1.ts
I keep a massive movie / tv watchlist in Google Sheets. I had a few folks help with the scripts and the result is amazing. Right now it's using OMDB as the main and TMDB for some supplemental info.
Essentially you use
=OMDB(A:C)
with A having the year, B having the title, or C having the IMDB ID. It'll search using either the title alone or the title and year or just the IMDB ID.omdb.gs
PropertiesService.getScriptProperties().setProperty('omdbkey', 'APIKEY');/**
Returns omdb information
@param {A2:C5} data
@param {"public"|"private"} type
@return {array} range of information from API
@customfunction
*/
function OMDB(data, type = 'private') {
if (data[0].length != 3) {
throw new Error('No valid range of data is given')
}
let key
if (type == 'private') {
type = 'private.'
key =
&apikey=${omdbKey}
}
var omdbKey = PropertiesService.getScriptProperties().getProperty('omdbkey');
const urls = data.map(d => {
const [year, title, id] = d
if (id != "") {
return
https://${type}omdbapi.com/?apikey=${omdbKey}&plot=full&i=${id}
} else if (title != "" && year != "") {
return
https://${type}omdbapi.com/?apikey=${omdbKey}&y=${year}&plot=full&t=${title}
} else if (title != "") {
return
https://${type}omdbapi.com/?apikey=${omdbKey}&plot=full&t=${title}
} else {
return
http://google.com
}
})
const requests = UrlFetchApp.fetchAll(urls)
return requests.map(request => {
try {
const data = JSON.parse(request.getContentText())
const { Type, imdbID, Year, Title, imdbRating, Metascore, Plot, Language, Director, Actors, Awards, Runtime, Genre, Writer, Rated } = data
return [Type, imdbID, Year.substring(0,4), Title, imdbRating, Metascore/10, Plot, Language, Director, Actors, Awards, Runtime, Genre, Writer, Rated]
} catch (err) {
return ["", "", "", "", "", "", "", "", "", "", "", "", "", "", ""]
}
})
}
It works well. It can do 900+ records in one go, which is way better than the previous iteration. I used to use TVMaze, but the output isn't as good as IMDB.
Image of the static dataset
not shown: it'll also give recommendations for films in the set that haven't been watched. One where English is the dominant language, one for foreign, and then one from everything.