Skip to content

Instantly share code, notes, and snippets.

View wperron's full-sized avatar
🚀
Launching into orbit

William Perron wperron

🚀
Launching into orbit
View GitHub Profile
@wperron
wperron / file_server.bundle.js
Created February 16, 2021 18:20
Deno Run Esbuild output
#!/usr/bin/env -S deno run --allow-net --allow-read
(() => {
var __defProp = Object.defineProperty;
var __export = (target2, all) => {
for (var name in all)
__defProp(target2, name, {get: all[name], enumerable: true});
};
// _util/os.ts
var osType = (() => {
@wperron
wperron / data.csv
Created February 17, 2021 20:52
Running d3 with Deno and Skypack
fruit qty
apple 1
banana 2
cantaloupe 3
@wperron
wperron / strdiff.ts
Last active June 3, 2021 14:43
test PR #948
import { assertEquals } from "./testing/asserts.ts";
Deno.test("a", () => {
assertEquals("lorem ipsum something foobar baz", "lorem ipsum some other thing foobar baz");
});
Deno.test("aa", () => {
assertEquals("this is different from the other string", "lorem ipsum some other thing foobar baz");
});
@wperron
wperron / broadcast.ts
Last active July 13, 2021 18:17
broadcast
import { delay } from "https://deno.land/std@0.101.0/async/delay.ts";
const send = new BroadcastChannel("a");
const recv = new BroadcastChannel("a");
addEventListener("fetch", (event) => {
event.respondWith(handler(event.request));
})
function handler(_req) {
addEventListener("fetch", (event) => {
event.respondWith(handler(event.request));
});
async function handler(req: Request): Promise<Response> {
if (typeof BroadcastChannel !== "undefined") {
console.log("found broadcast channel");
return new Response("true");
}
return new Response("false");
@wperron
wperron / README.md
Last active June 22, 2021 12:14
Sum of all integers up to N

Summing up all numbers up to n

This is a comparison of two functions that sum up all the integer numbers from 1 to n and returns that sum.

Benchmarks

$ deno test --allow-read add.ts
Check file:///home/wperron/github.com/wperron/gists/add/add.ts
running 4 benchmarks ...
// includes-all
needles.map((elem) => haystack.includes(elem)).reduce((found, curr) => found && curr);
// includesAny
needles.some((elem) => haystack.includes(elem));
// includesNone
!needles.some((elem) => haystack.includes(elem));
// mapNotNullish
@wperron
wperron / main.js
Last active July 13, 2021 14:28
Deno Deploy get Trace ID
addEventListener("fetch", (e) => {
let ray = e.request.headers.get("x-deno-ray");
console.log(ray);
e.respondWith(new Response(ray, {status: 200}));
});
@wperron
wperron / main.js
Last active July 19, 2021 15:52
Deno Deploy recursive request
addEventListener("fetch", (e) => {
e.respondWith(handler(e));
});
function handler(e) {
return fetch(e.request)
}
@wperron
wperron / fibonacci.ts
Created July 26, 2021 18:56
Fibonnaci with Deno
import { cyan } from "https://deno.land/std@0.103.0/fmt/colors.ts";
export function fib(n: number): number {
if (0 <= n && n <= 1) {
return n;
}
let a = 0, b = 1;
for (let i = 0; i < n; i++) {
[a, b] = [b, a + b];