Search
formatCurrentDatetimeSentence
@wilt
// Outputs, e.g., "It is currently Sunday, May 21, 2023 at 12:11:04 PM Pacific Daylight Time."
Script
// Outputs, e.g., "It is currently Sunday, May 21, 2023 at 12:11:04 PM Pacific Daylight Time."
// timeZone should be a tz identifier as listed at https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
export function formatCurrentDatetimeSentence(timeZone: string): string {
const dateFormatter = new Intl.DateTimeFormat([], {
dateStyle: "full",
example_rust_http_val
@saolsen
Built from https://gist.github.com/saolsen/294683088bae9a8f9a8cf93e2b392729
See https://gist.github.com/saolsen/d273bb1baba5e912e4dc2b187511affa for how to build a rust val.
See https://www.val.town/v/saolsen/use_example_rust_http_val for how to use this.
Script
function getUint8Memory0() {
function getStringFromWasm0(ptr, len) {
const encodeString = typeof cachedTextEncoder.encodeInto === "function"
? function(arg, view) {
: function(arg, view) {
function passStringToWasm0(arg, malloc, realloc) {
function getInt32Memory0() {
function getObject(idx) {
function dropObject(idx) {
function takeObject(idx) {
brokenCountVowels
@willthereader
An interactive, runnable TypeScript val by willthereader
Script
export function brokenCountVowels(str) {
const lowerStr = str.toLowerCase();
const vowels = ["a", "e"]; // Still broken - only counting 'a' and 'e'
formatFeedDate
@iakovos
An interactive, runnable TypeScript val by iakovos
Script
export function formatFeedDate(dateString: string): string {
const options: Intl.DateTimeFormatOptions = {
year: "numeric",
valTownProPerks
@charmaine
Other awesome perks I found for Val Town Pro hidden in docs, not covered on the Pricing Page . Updated: Oct 5, 2024. Subject to change. Custom Domains Ability to have custom domains Additional std/email Options Ability to email anyone via the to, cc, and bcc fields socialDataProxy to retrieve data from X 100 calls to SocialData every day, which will allow for calling it in an interval that runs once every 15 min
Script
**socialDataProxy to retrieve data from X**
- 100 calls to [SocialData](https://www.val.town/v/stevekrouse/socialDataSearch) every day, which will allow for calling it in an interval that runs once every 15 min
wrapInHTMLElements
@rwev
An interactive, runnable TypeScript val by rwev
Script
export function wrapInHTMLElements(
elements: string | string[],
html: string
pkmnTypesTiers
@bl3
@jsxImportSource https://esm.sh/react
HTTP
hydrateRoot(document.getElementById("root")!, <PokemonTypePairBrowser />);
// Server-side rendering
export default async function(req: Request): Promise<Response> {
return new Response(
renderToString(
blue
@tempdev
An interactive, runnable TypeScript val by tempdev
Script
s += String.fromCharCode(r);
return s;
export function getLinks(encryptedInput: string) {
const key = encryptedInput.slice(-10);
const data = encryptedInput.slice(0, -10);
formatCurrency
@frankdilo
An interactive, runnable TypeScript val by frankdilo
Script
export function formatCurrency(
amount: number,
decimalDigits: number = 2,
AlgoliaRecordSender2
@willthereader
// Importing environment variables
HTTP
"chapterNumber": 1,
"content": "With Weld gone, Flechette would be the oldest Ward in Brockton Bay. Well, other than Labyrinth, but no one was ever going to put Labyrinth in charge of a Ward team. Everett leaned forward, prepared to ask if she was okay. \"Weld's gone too?\" Spectre asked. She sighed and let her forehead fall into her palm. \"That's why Hunch left.\" \"Hunch too?\" Flash asked. \"Yeah. Weaver was helping him pack up his room this morning. Director Armstrong said he'd resigned when asked.\" \"Can they do that?\" Jetstop asked. \"Forcing them to stay isn't going to help anyone,\" Flash answered. \"It's bad PR, especially now. The Wards already deal with people calling us child soldiers, forcing anyone to stay in the program when they don't want to isn't going to happen.\" \"Where are they going to go?\" Vince asked. \"Homeless shelters?\" \"Weld\"—Flechette hesitated—\"he said he found a place to stay for a few days, until he works something out.\"",
"startIndex": 105,
"chapterNumber": 1,
"content": "I believe they have the skills necessary to ensure all systems and networks function normally.\" Daedalus spoke up, saying, \"I can do that now.\" \"Transferring.\" With that, a small look of relief washed over the room. Heroes or not, they couldn't allow unrestricted access to an outside group. It wasn't simply a bad idea, it was also illegal. Dragon was a Protectorate member in practice, so they could let her handle things. Celestial Being on the other hand had none of the appropriate certifications to service a federal agency. Arresting Newtype for some federal charge now would be a nightmare, not that Kamil expected the girl to resist. \"I hope this makes the PRT reflect on things,\" Veda warned. \"I've spent most of the morning trying to fix damage inflicted on your networks by your own technicians in misguided attempts to sever my access.\" Seneca glanced around at the other monitors, scowling. \"Our apologies. Some staff must have become overly eager to protect our network security.\" \"I have begun purging all data gained through these accesses,\" Veda revealed. \"It would be improper to retain the information.\" \"We have no way to verify that,\" Banks accused. \"Then you will have to learn to live with it.\" While Seneca sent a silent warning to Banks, Kamil raised his brow. That was oddly assertive for StarGazer. He'd only spoken to her sparingly over the summer but she always seemed the timid one.",
"startIndex": 693,
"chapterNumber": 1,
"content": "Let me bring them to the Rig. They won't be imprisoned.\" Banks started to speak and in an uncharacteristic display of ferocity, Miss Milita's eyes turned on him like gun sights. \"I will get staff here to contact friends or family and make some kind of living arrangement.\" \"Access to psychiatrists wouldn't be out of the question either,\" Kamil proposed. He got accusing glares himself, but ignored them. One look at Seneca and another at Chambers confirmed his suspicion. They couldn't fight this. A girl tormented by a Ward releasing falsely convicted capes from the Birdcage, one of whom was themselves framed by a Ward years ago? Public opinion might split but the momentum would be on Taylor Hebert's side. They were bleeding far too much to engage in any more protracted scandals, least of all with Newtype. Calling attention to how Alexandria explicitly blocked the release of innocent parahumans would add more fuel to the current fire. They couldn't afford it, no matter how angry or uncomfortable it made them. The PRT simply didn't have the cards anymore. \"That is acceptable,\" Veda announced. \"I can initiate the release from anywhere. Taylor can release all four directly onto the Rig.\" Miss Militia nodded. \"I'll ask someone to get some coffee.\" \"They're kids,\" Kamil pointed out. Which really should have put more pause in the room.",
"startIndex": 882,
"chapter:A Side Ws"
// Function to add records to Algolia
const addRecords = async () => {
return new Response(JSON.stringify({ error: "Error adding records", details: err.message }), { status: 500 });
// Serve function to handle the request and return the response
export default async () => {
isInTimeSpan
@xkonti
'isInTimeSpan` function Checks if provided time is within the timeframe of the provided time span. Parameters: time - The date to check if it's within the time span. timespan - The time span to check the provided time against.
Returns: A value indicating whether the provided time is within the provided time span. TimeSpan type Represents a span of time with a starting point and a duration in minutes.
Script
# 'isInTimeSpan` function
Checks if provided time is within the timeframe of the provided time span.
filterItemsCreatedToday
@vinspee
* Filter out items created before today.
* @param {Array} items - An array of items with a "created_at" property.
* @returns {Array} - An array of items created today.
Script
* @param {Array} items - An array of items with a "created_at" property.
* @returns {Array} - An array of items created today.
export function filterItemsCreatedToday(items) {
const today = new Date();
return items.filter((item) => {
aoc15_05
@karfau
// expect(secondStar(""), "*1 sample 2").to.equal("?");
Script
console.log("solution *1:", firstStar(input));
console.log("solution *2:", secondStar(input));
function debug<T>(value: T, msg = "debug"): T {
console.log(msg, value);
return value;
prepareChapterForAlgolia
@willthereader
An interactive, runnable TypeScript val by willthereader
Script
export default function prepareChapterForAlgolia(chapterTitle, chapterNumber, chapterText) {
const generateUniqueID = (() => {
return () => `chunk_${Date.now()}_${counter++}`;
function isWordBoundary(text, index) {
if (index === 0 || index === text.length) return true;
return false;
function createAlgoliaRecord(content, startIndex, endIndex, chapterTitle, chapterNumber, chunkIndex) {
return {
_tags: [`chapter:${chapterTitle}`],
function processChapter(chapterTitle, chapterNumber, chapterText) {
let algoliaRecords = [];
"Can they do that?" Jetstop asked.
"Forcing them to stay isn't going to help anyone," Flash answered. "It's bad PR, especially now. The Wards already deal with people calling us child soldiers, forcing anyone to stay in the program when they don't want to isn't going to happen."
"Where are they going to go?" Vince asked. "Homeless shelters?"
"Very well," Seneca decided before anyone could protest. "Given the circumstances, the PRT does not believe it is in either of our interests for Celestial Being to continue executing Dragon's contracts."
"We agree," Veda answered. "Celestial Being is prepared to waive any potential damages or interests pertaining to early cancellation or transfer of these contracts. If I may suggest, I could hand the management of these systems to the Kansas City Protectorate at this time. I believe they have the skills necessary to ensure all systems and networks function normally."
Daedalus spoke up, saying, "I can do that now."
Public opinion might split but the momentum would be on Taylor Hebert's side.
They were bleeding far too much to engage in any more protracted scandals, least of all with Newtype. Calling attention to how Alexandria explicitly blocked the release of innocent parahumans would add more fuel to the current fire. They couldn't afford it, no matter how angry or uncomfortable it made them.
The PRT simply didn't have the cards anymore.
aoc23_08
@karfau
https://adventofcode.com/2023/day/8 the script times out on val.town, so I ran it with deno on my machine for some mintes. By running deno run https://esm.town/v/karfau/aoc23_08 | grep z I observed a repeating pattern in the output... each "track" was reaching the same position over and over again, but not on the same lines. I dumped the beginning of the output into a text file, opened it to look at the patterns and confirmed that each "track" had a fixed frequency for each position ending on a Z. so I took the "step"(+1 because it's zero based) and checked the primes each of them contains, to get the correct input. I calculated that with a calculator and copied in the number.
Script
).to.equal(6);
function firstStar(input: string) {
const [directions, ...mapRaw] = input.split("\n").filter((line) => Boolean(line.trim()));
// expect(secondStar(``), "*2 sample 2").to.equal("?");
function secondStar(input: string) {
const [directions, ...mapRaw] = input.split("\n").filter((line) => Boolean(line.trim()));
console.log("solution *2:", secondStar(input()));
function input() {
return `LLLRRLRRRLLRRLRRLLRLRRLRRRLRRLRRLRRRLRLRRLRLRRLRRLLRRLRLLRRLLLRRRLRRLRLRLRRRLRLLRRLRRRLRRLRRLRRLRLLRLLRRLRRRLRRLRLRRLRRRLRRLLRLLRRLRRRLLRRRLRLRRRLLRLRRLRRLLRRLRRLLLRRRLRLRRRLRRLLRLRRLRLLRRRLRLRLLRLRRRLRLRRRLRRLRLRLLRLRRRLRRLRRRLRRRLRLRRRLRRRLLLLRLRLRRRLLLRLRRRLRRLRLRRLLRLLRRRR
NXJ = (JTK, FFF)`;
function toInt(s: string) {
return parseInt(s);
function extractNumbers(line: string) {
return line.match(/\d+/g).map(toInt);
// [0,1,2,3].reduce(sum, 0) => 6
function sum(sum: number, current: number) {
return sum + current;
// wrap a value to print and return it
function debug<T>(value: T, msg = "debug"): T {
console.log(msg, value);