Skip to content

Instantly share code, notes, and snippets.

View dcdunkan's full-sized avatar

Dunkan dcdunkan

View GitHub Profile
@dcdunkan
dcdunkan / slot-machine.ts
Last active February 8, 2024 07:15
Resolve Telegram's slot machine dice value (from tdesktop source)
const e = ["🔤", "🫐", "🍋", "7️⃣"];
function computePartValue(value: number, partIndex: number) {
return ((value - 1) >> (partIndex * 2)) & 0x03; // 0..3
}
function resolve(value: number) {
if (value <= 0 && value > 64) return;
let text = `${value}:`;
for (let i = 0; i < 3; i++) text += ` e[computePartValue(value, i)]`;
@dcdunkan
dcdunkan / deno_deta_base.ts
Last active March 27, 2023 10:06
Tiny https://deta.sh base client.
export class Base {
private rootUrl: string;
constructor(private projectKey: string, baseName: string) {
const projectId = projectKey.split("_")[0];
this.rootUrl = `https://database.deta.sh/v1/${projectId}/${baseName}`;
}
async request(query: string, payload?: unknown) {
const [method, ...pathname] = query.split(" ");
const response = await fetch(`${this.rootUrl}${pathname.join(" ")}`, {
@dcdunkan
dcdunkan / slideshare_bot.ts
Last active March 27, 2023 10:07
Slideshare downloader
import { Bot, InputFile } from "https://deno.land/x/grammy@v1.8.0/mod.ts";
import { DOMParser } from "https://deno.land/x/deno_dom@v0.1.22-alpha/deno-dom-wasm.ts";
import { StatusMessage } from "https://gist.githubusercontent.com/dcdunkan/235859eac749d36f4df7c00b99fbbc8f/raw/status.ts";
const bot = new Bot(Deno.env.get("BOT_TOKEN")!);
bot.command("start", async (ctx) => await ctx.reply("yeah!"));
bot.on("message:text").on("::url", async (ctx) => {
const url = ctx.message.text;
@dcdunkan
dcdunkan / example.ts
Last active February 3, 2022 13:07
Telegraph API wrapper different parse mode examples
/*
* This is just for demonstrational purposes. A minimal one, haven't used so many
* available tags, markdown syntaxes. See the library and documentation here:
* https://github.com/dcdunkan/telegraph.
*/
import { Telegraph, parse } from "https://deno.land/x/telegraph/mod.ts";
const tph = new Telegraph({
// SANDBOX access token from Official API Docs: https://telegra.ph/api