Search

Results include substring matches and semantically similar vals. Learn more
wilt avatar
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",
saolsen avatar
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) {
willthereader avatar
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'
iakovos avatar
formatFeedDate
@iakovos
An interactive, runnable TypeScript val by iakovos
Script
export function formatFeedDate(dateString: string): string {
const options: Intl.DateTimeFormatOptions = {
year: "numeric",
charmaine avatar
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**
ww.val.town/v/stevekrouse/socialDataSearch) every day, which will allow for calling it in an interval that runs once every 15
rwev avatar
wrapInHTMLElements
@rwev
An interactive, runnable TypeScript val by rwev
Script
export function wrapInHTMLElements(
elements: string | string[],
html: string
bl3 avatar
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(
tempdev avatar
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);
frankdilo avatar
formatCurrency
@frankdilo
An interactive, runnable TypeScript val by frankdilo
Script
export function formatCurrency(
amount: number,
decimalDigits: number = 2,
willthereader avatar
AlgoliaRecordSender2
@willthereader
// Importing environment variables
HTTP
"chapterNumber": 1,
answered. \"It's bad PR, especially now. The Wards already deal with people calling us child soldiers, forcing anyone to stay
"startIndex": 105,
"chapterNumber": 1,
I believe they have the skills necessary to ensure all systems and networks function normally.\" Daedalus spoke up, saying, \
"startIndex": 693,
"chapterNumber": 1,
much to engage in any more protracted scandals, least of all with Newtype. Calling attention to how Alexandria explicitly bl
"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 () => {
xkonti avatar
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.
vinspee avatar
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) => {
karfau avatar
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;
willthereader avatar
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.
answered. "It's bad PR, especially now. The Wards already deal with people calling us child soldiers, forcing anyone to stay
"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 o
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.
much to engage in any more protracted scandals, least of all with Newtype. Calling attention to how Alexandria explicitly bl
The PRT simply didn't have the cards anymore.
karfau avatar
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 `LLLRRLRRRLLRRLRRLLRLRRLRRRLRRLRRLRRRLRLRRLRLRRLRRLLRRLRLLRRLLLRRRLRRLRLRLRRRLRLLRRLRRRLRRLRRLRRLRLLRLLRRLRRRLRRLRLR
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);