Skip to content

Instantly share code, notes, and snippets.

@zevaverbach
zevaverbach / main.js
Last active November 20, 2023 06:55
Get remaining time in a Teachable course
// I created this for (and tested it on) a learn.cantrill.io course
// to quickly determine how much more video I have left to finish the course,
// so I could plan my time in advance of an AWS exam.
function getTotalMinutesLeftInCourse() {
let totalMinutes = 0;
for (const chapter of getChapters()) {
if (!chapterIsComplete(chapter)) {
const [minutes, seconds] = getMinutesAndSeconds(getLengthString(chapter.innerText))
@pims
pims / app.py
Last active January 3, 2024 20:26
Example of running a python script via python-wasi using the wasmtime wasm runtime
print("hello from a python script")
@mystal
mystal / odds.rs
Created December 22, 2021 18:19
Print odd number arguments
use std::env;
fn main() {
let odds: Vec<_> = env::args()
.skip(1)
.map(|s| s.parse::<i32>().unwrap())
.filter(|&n| n % 2 != 0)
.collect();
println!("odd numbers: {:?}", odds);
}
service: my-service
provider:
name: aws
region: ${opt:region, 'eu-west-1'}
stage: ${opt:stage, 'development'}
plugins:
- serverless-s3-sync
@Jack-Works
Jack-Works / 2018.js
Last active March 1, 2024 02:23
cRAzY eSnEXt (*all* proposals mixed in)
#! Aaaaaaaaaaa this is JS!!!
// https://github.com/tc39/proposal-hashbang
// This file is mixing all new syntaxes in the proposal in one file without considering syntax conflict or correct runtime semantics
// Enjoy!!!
// Created at Nov 23, 2018
for await(const x of (new A // https://github.com/tc39/proposal-pipeline-operator
|> do { // https://github.com/tc39/proposal-do-expressions
case(?) { // https://github.com/tc39/proposal-pattern-matching
when {val}: class {
@Rich-Harris
Rich-Harris / http-apis.md
Last active November 3, 2022 09:02
Next-gen Node HTTP APIs

I saw this poll on Twitter earlier and was surprised at the result, which at the time of writing overwhelmingly favours option 1:

Screen Shot 2020-09-10 at 10 19 22 AM

I've always been of the opinion that the (req, res, next) => {} API is the worst of all possible worlds, so one of two things is happening:

  • I'm an idiot with bad opinions (very possibly!)
  • People like familiarity
from flask import Flask, send_from_directory
import random
app = Flask(__name__)
# Path for our main Svelte page
@app.route("/")
def base():
return send_from_directory('client/public', 'index.html')
@jnothman
jnothman / fromisoformat.py
Created May 30, 2019 00:28
datetime.fromisoformat backported from Python 3.7
"""datetime.fromisoformat backported from Python 3.7
PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
--------------------------------------------
1. This LICENSE AGREEMENT is between the Python Software Foundation
("PSF"), and the Individual or Organization ("Licensee") accessing and
otherwise using this software ("Python") in source or binary form and
its associated documentation.
@Rich-Harris
Rich-Harris / README.md
Last active December 20, 2019 15:19
Source bytes: React vs Ember Octane vs Svelte

I'm procrastinating instead of working on a conference talk, so I decided to implement this component in Svelte to see which framework is most expressive:

Screen Shot 2019-03-30 at 16 42 16

Ember Octane

Here's the original, with the addition of an import for dataUriAsSrc (and updated per @chriskrycho's comment):

<img
addEventListener("fetch", event => {
event.respondWith(handleRequest(event.request));
});
/**
* Multiplex requests to a fixed list of destinations.
*
* It is intentional that we only support rewriting the incoming request URL to
* that of the destination. Everything else on the request is untouched.
*