
@stevekrouse
dlock - free distributed lock as a service
Usage
API
Acquire a lock.
The id path segment is the lock ID - choose your own.
https://dlock.univalent.net/lock/arbitrary-string/acquire?ttl=60
{"lease":1,"deadline":1655572186}
Another attempt to acquire the same lock within its TTL will fail with HTTP status code 409.
https://dlock.univalent.net/lock/01899dc0-2742-44f9-9c7b-01830851b299/acquire?ttl=60
{"error":"lock is acquired by another client","deadline":1655572186}
The previous lock can be renewed with its lease number, like a heartbeat
https://dlock.univalent.net/lock/01899dc0-2742-44f9-9c7b-01830851b299/acquire?ttl=60&lease=1
{"lease":1,"deadline":1655572824}
Release a lock
https://dlock.univalent.net/lock/01899dc0-2742-44f9-9c7b-01830851b299/release?lease=42
Message yourself on Telegram
Inspired by console.email
, this val lets you send yourself Telegram messages via the Val Town Telegram Bot. You can use it to make custom Telegram bots, such as this DallE one.
Usage
@stevekrouse.telegram(@me.secrets.telegram, "hi to me on telegram!")
@me.t("hello telegram!")
Installation
It takes less than a minute to set up!
-
Start a conversation with ValTownBot
-
Copy the secret it gives you
-
Save it in your Val Town secrets under
telegram
-
Send a message!
@stevekrouse.telegram(@me.secrets.telegram, "hi to me on telegram!")
Example: https://www.val.town/v/stevekrouse.exampleTelegramMessage
- (Bonus) Make a helper function
If you want to make it even easier to message yourself on telegram, ie @me.t("hello!")
then you can setup a helper function:
let t = (message, options) => @stevekrouse.telegram(@me.secrets.telegram, message, options);
Ensure you keep this function private otherwise anyone can message you on Telegram!
Commands
/roll
- Roll your secret in case you accidentally leak it./webhook
- Set a webhook to receive messages you send to @ValTownBot
Receiving Messages
If you send /webhook
to @ValTownBot, it will let you specify a webhook URL. It will then forward on any messages (that aren't recognized @ValTownBot commands) to that webhook. It's particularly useful for creating personal chatbots, like my telegram <-> DallE bot.
How it works
Telegram has a lovely API.
- I created a @ValTownBot via Bot Father.
- I created a webhook and registered it with telegram
- Whenever someone new messages @ValTownBot, I generate a secret and save it along with their Chat Id in
@stevekrouse.telegramValTownBotSecrets
(a private val), and message it back to them - Now whenever you call this val, it calls
telegramValTownBot
via the Run API (api
is a helper), which looks up your Chat Id via your secret and sends you a message
Telegram Resources
- Val Town Telegram Echo Bot Guide
- Telegram <-> DallE Bot
- Bot Father - the father of all Telegram Bots
- Telegram Bot Tutorial
Credits
This val was originally made by pomdtr.
☔️ Umbrella reminder if there's rain today
Setup
- Fork this val 👉 https://val.town/v/stevekrouse.umbrellaReminder/fork
- Customize the
location
(line 2). You can supply any free-form description of a location.
⚠️ Only works for US-based locations (where weather.gov covers).
How it works
- Geocodes an free-form description of a location to latitude and longitude – @stevekrouse.nominatimSearch
- Converts a latitude and longitude to weather.gov grid – @stevekrouse.weatherGovGrid
- Gets the hourly forecast for that grid
- Filters the forecast for periods that are today and >30% chance of rain
- If there are any, it formats them appropriately, and sends me an email
Planes Above Me
Inspired by https://louison.substack.com/p/i-built-a-plane-spotter-for-my-son
A little script that grabs that planes above you, just change line 4 to whatever location you want and it'll pull the lat/log for it and query.
Email with GPT-3
Send an email to stevekrouse.emailGPT3@valtown.email, it will forward it to gpt3, and email you back the response.