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 jwt from '@tsndr/cloudflare-worker-jwt'; | |
import { StatusError } from '../lib/errors'; | |
import { Config, RouterRequest, SocketAuth } from '../types'; | |
export function uses(request: RouterRequest) { | |
return (request.headers.get('authorization') || '').match(/^Bearer /i); | |
} | |
export async function auth(request: RouterRequest, noError?: boolean) { | |
return authSocket( |
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 type { ConvexClient } from 'convex/browser'; | |
import type { FunctionReference } from 'convex/server'; | |
import { derived, writable } from 'svelte/store'; | |
export function queryResults<Query extends FunctionReference<'query'>>( | |
client: ConvexClient, | |
query: Query, | |
initialArgs: Query['_args'] | |
): Query['_returnType'] { | |
const args = writable(initialArgs); |
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 purpose = "Purpose: obfuscate ttf file (convert to Microsoft's ODTTF format)" | |
const usage = "Usage: node obfuscate-ttf-to-odttf.js <guid-font-file.ttf> [<output-file.odttf>]" | |
const obfuscatedStartOffset = 0 | |
const obfuscatedEndOffset = 32 | |
const guidSize = 32 | |
const fs = require('fs') | |
const path = require('path') |
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 function getLocationHint(location: Location = {}) { | |
if (!location.continentCode && !location.point) return 'enam'; | |
const areas = continentCodes[location.continentCode || 'AN']; | |
let closest = areas[0]; | |
let shortestDistance = Infinity; | |
if (areas.length === 1 || !location.point) return closest; | |
const { lat, lon } = location.point; |
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
/** | |
* Simplify concurrency using the strategies described in | |
* https://blog.cloudflare.com/durable-objects-easy-fast-correct-choose-three/ using input gates and output gates by | |
* allowing certain actions to block other actions or to block the responses of other actions. | |
* To "block" an action or response means to defer it until after the blocking actions have been processed. This | |
* allows the state of an object to be consistent and avoid race conditions which may be hard to discover. | |
* It is a good idea to use this in conjunction with a cache for blockable actions (e.g. a storage mechanism) to ensure | |
* the blocking doesn't slow down the system. | |
* | |
* Definitions: |
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
/** | |
* Tiny. Compiled code for signals results in 15 lines of JS, < 500 bytes of uncompressed code. | |
* | |
* Usage: | |
* | |
* const clickedSave = createSignal<Doc>(); | |
* | |
* clickedSave(doc => { | |
* // do something to save the doc, or when the doc is saved | |
* }) |
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
{#if match !== null} | |
<slot></slot> | |
{/if} | |
<script> | |
import { getHistory, matchPath, ROUTING_CONTEXT } from './index.js'; | |
import { writable } from 'svelte/store.js'; | |
import { setContext, onDestroy } from 'svelte'; | |
const history = getHistory(); | |
const matchStore = writable(null); |
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 function observe(key, callback, opts) { | |
const single = !Array.isArray(key); | |
const keypaths = single ? [ key ] : key; | |
const parts = keypaths.map(keypath => keypath.replace(/\[(\d+)\]/g, '.$1').split('.')); | |
const keys = parts.map(parts => parts[0]); | |
const fn = callback.bind(this); | |
let last = parts.map(parts => getNestedValue(this.get(), parts)); | |
if (!opts || opts.init !== false) { |
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
function (user, context, callback) { | |
if (!user.app_metadata) { | |
user.app_metadata = {}; | |
} | |
if (!user.app_metadata.userId || user.app_metadata.userId.length < 24) { | |
var idLength = 24; | |
var chars = ( | |
'0123456789abcdefghijklmnopqrstuvwxyz' | |
).split(''); |
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
function (user, context, callback) { | |
var request = require('[email protected]'); | |
var async = require('[email protected]'); | |
// Check if email is verified, we shouldn't automatically | |
// merge accounts if this is not the case. | |
if (!user.email_verified) { | |
return callback(null, user, context); | |
} | |
var userApiUrl = auth0.baseUrl + '/users'; |
NewerOlder