Skip to content

Instantly share code, notes, and snippets.

@LeopoldTal
LeopoldTal / tough-dough.html
Created September 14, 2021 09:02
tf-idf tutorial
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>tf-idf tutorial</title>
<script src="https://d3js.org/d3.v5.min.js"></script>
<script src="./set-documents.js"></script>
</head>
@LeopoldTal
LeopoldTal / README.md
Last active April 17, 2021 22:57
Inform string benchmark

Simple string truncation benchmark

Motivation

Inform seems rather lacking in string manipulation utilities: There doesn't seem to be any way to slice a string, nor any way to change one in place except by match replacement.

As a result, it's unclear what the best way to truncate a string is. This story file is a simple benchmark for 6 different methods:

  • building the new string character-by-character from the start
  • copying the string then erasing the extra characters left-to-right
@LeopoldTal
LeopoldTal / README.md
Last active October 3, 2020 18:32
Match words inside phone numbers

This example coding interview asks:

On a phone keypad, each letter corresponds to a digit.

A phone keypad, where digit 2 corresponds to letters A, B, C

This means that phone numbers can contain English words, e.g. 1-(800)-356-9377 contains flowers.

Given a phone number, and a list of words, return the words contained in the phone number.

@LeopoldTal
LeopoldTal / README.md
Last active August 21, 2020 07:02
Scraper for official government statistics for COVID-19 in France

Scraper for official government statistics for COVID-19 in France

Purpose

For no reason I can fathom, the French government publishes daily COVID-19 cases and deaths as an infographic, with no text version. There are also no archives: only the latest update is available.

Recovery statistics are published on a different source, which has a (somewhat wonky) API and data for each day.

This is a quick and (very) dirty script to scrape the latest statistics off these two sites.

@LeopoldTal
LeopoldTal / binary-search.js
Created June 24, 2020 19:08
Cleanroom binary search challenge
/*
Cleanroom binary search challenge
Write a binary search, correct the first time, without testing. They say it's harder that it sounds.
https://reprog.wordpress.com/2010/04/19/are-you-one-of-the-10-percent/
*/
// Binary search
// Obnoxiously careful - if there's any mistake here I fail the challenge
// Putting all my thought process as comments so you can make fun
@LeopoldTal
LeopoldTal / liz.txt
Created May 13, 2020 16:23
The longest possible way to style Queen Elizabeth II
Her Majesty Elizabeth the Second, by the Grace of God of the United Kingdom of Great Britain and Northern Ireland and of Her other Realms and Territories Queen, Head of the Commonwealth, Defender of the Faith, by the Grace of God, Queen of Antigua and Barbuda and of Her other Realms and Territories, Head of the Commonwealth, by the Grace of God, Queen of the Commonwealth of The Bahamas and of Her other Realms and Territories, Head of the Commonwealth, by the Grace of God, Queen of Barbados and of Her other Realms and Territories, Head of the Commonwealth, by the Grace of God, Queen of Belize and of Her Other Realms and Territories, Head of the Commonwealth, by the Grace of God, of the United Kingdom, Canada and Her other Realms and Territories Queen, Head of the Commonwealth Defender of the Faith, by the Grace of God, Queen of the United Kingdom of Great Britain and Northern Ireland and of Grenada and Her other Realms and Territories, Head of the Commonwealth, by the Grace of God, Queen of Jamaica and of Her
@LeopoldTal
LeopoldTal / cheese-pool.js
Last active December 15, 2019 21:49
Making a swimming pool out of cheese
const DEFAULT_POOL_DIAMETER = 25; // m
const DEFAULT_POOL_DEPTH = 1.5; // m
// Cheese tensile strengths in kPa
// Sundaram Gunasekaran & M. Mehmet Ak
// _Cheese Rheology and Texture_ (2002)
// Table 3.2, p. 126
const CHEESES = {
'American cheese': 138,
'Appenzell': 22,
@LeopoldTal
LeopoldTal / mandelbrot.c
Created September 1, 2018 21:58
Mandelbrot set ASCII art
/*
* Mandelbrot set ascii art
*/
#include <stdio.h>
#include <string.h>
/* Params */
//TODO: these should be command line arguments
@LeopoldTal
LeopoldTal / fishgame.py
Last active April 21, 2016 22:29
A* solver for Fish Are Not Naturally Monogamous
"""fishgame
Solver for Fish Are Not Naturally Monogamous
http://www.kongregate.com/games/chickenprop/fish-are-not-naturally-monogamous"""
def flip_sex(fish):
return {"M":"F", "F":"M"}[fish]
def trivial_heuristic(fg):
return 0