View expand-all-files-on-github-diff-page.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
document.querySelectorAll('button[aria-label="Toggle diff contents"]').forEach(b => b.click()) |
View generate-importable-blob.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const bytes = await Deno.readFile(new URL('./thumbnail.png', import.meta.url)) | |
const encoder = new TextEncoder() | |
const contents = encoder.encode( | |
`export const thumbnail = new Blob(new Uint8Array(${ | |
JSON.stringify(Array.from(bytes)) | |
}), { type: 'image/png' })` | |
) | |
await Deno.writeFile(new URL('./hardcoded-thumbnail.ts', import.meta.url), contents) |
View remove-www.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const status = 301 | |
addEventListener('fetch', event => { | |
const url = new URL(event.request.url) | |
url.hostname = url.hostname.replace(/^www\./, '') | |
event.respondWith(Response.redirect(url.toString(), status)) | |
}) |
View async_iterators_throw_catch_test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { assertEquals } from 'https://deno.land/std@0.125.0/testing/asserts.ts' | |
Deno.test('async iterator throw in next should throw in for scope', async () => { | |
const results: number[] = [] | |
const numbers = (() => { | |
let counter = 0 | |
const iterator: AsyncIterator<number> = { | |
// deno-lint-ignore require-await |
View deferred.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class Deferred<T = void, E = Error> { | |
#promise: Promise<T> | |
// deno-lint-ignore ban-ts-comment | |
// @ts-ignore | |
resolve: (arg: T) => void | |
// deno-lint-ignore ban-ts-comment | |
// @ts-ignore | |
reject: (arg: E) => void | |
constructor() { |
View task.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
console.log('Fetching...') | |
const res = await fetch('https://example.com') | |
const body = new Uint8Array(await res.arrayBuffer()) | |
console.log('---') | |
await Deno.stdout.write(body) | |
console.log('---') | |
console.log('Done.') |
View server.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Start listening on port 8080 of localhost. | |
const server = Deno.listen({ port: 8080 }) | |
console.log('HTTP webserver running...') | |
const headers = Object.freeze({ | |
'Content-type': 'plain/text' | |
}) | |
for await (const conn of server) { | |
// deno-lint-ignore no-extra-semi |
View params.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule POC.Params do | |
import Ecto.Changeset | |
@spec permit(map, map) :: map | |
def permit(input, types) do | |
{types, nested} = Enum.reduce(types, {%{}, %{}}, &process_types/2) | |
{%{}, types} | |
|> cast(input, Map.keys(types)) | |
|> permit_nested(nested) |
View router.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule AppWeb.Router do | |
use AppWeb, :router | |
pipeline :browser do | |
plug Plug.Parsers, | |
parsers: [:urlencoded, :multipart, :json], | |
pass: ["*/*"], | |
json_decoder: Phoenix.json_library() | |
plug Plug.MethodOverride |
View poller.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Example.Poller do | |
use GenServer | |
@backoff [ | |
50, | |
100, | |
150, | |
250, | |
400, | |
650 |
NewerOlder