// contexts/index.ts
import { getContext, hasContext, setContext } from 'svelte';
export const create = <Context>(identifier: string) => {
const key = Symbol();
return {
set(context: Context) {
return setContext<Context>(key, context);
},
type Point = {
x: number;
y: number;
};
const interpolate = (center: Point) => (amount: number) => (pt: Point) => {
return (n: number) => {
const angle = n * amount;
const c = Math.cos(angle);
import { derived } from 'svelte/store';
import type { Readable } from 'svelte/store';
export const conditionally =
(readable: Readable<boolean>) =>
<T>(whenTrue: T, whenFalse: T): Readable<T> =>
derived(readable, ($readable): T => {
return $readable ? whenTrue : whenFalse;
});
I appreciate anyone that decides to support the stream but some people don't want their presence to be broadcasted.
I usually just find a playlist or collection of video game music or an OST to put on in the background.
This gist isn't mathematically rigorous so don't expect it to be as formal as something you'd find in academia.
This problem arises in various math and computer science topics where your input range needs to be transformed to fit into a different range. For example, let's say you had frequency data of a song at a particular moment in time. Each sample is a value that ranges from 0
to 255
. In interval notation, it would be written as [0, 255]
. The square brackets denote that the endpoints are inclusive - in other words, 0
and 255
are acceptable. We want to take a sample in this range and map it to a different range. Let's say our output range is [-1, 1]
. The [-1, 1]
range actually pops up a lot in various fields such as graphics programming or trigonometry. For example the range for the sine
and cosine
functions is [-1, 1]
.
So we want to take the range [0, 255]
and map it to the range [-1, 1]
. Of course, we'd want the mapping t
const normalize = (min: number) => (max: number) => (x: number) => (x - min) / (max - min);
// usage
const min = 25;
const max = 100;
const n = normalize(min)(max);
const ns = [32, 62.5, 90].map(n);
const typedKeys = <O extends {}>(o: O) =>
Object.keys(o) as Array<keyof O>;
const o = {
first: 'josh',
last: 'o'
};
const keys = Object.keys(o);
const swap = <T>(t: T[], i: number, j: number) => { | |
[t[i], t[j]] = [t[j], t[i]]; | |
}; | |
export const shuffle = <T>(t: T[]) => { | |
for (let i = t.length - 1; i > 0; i -= 1) { | |
const j = Math.floor(Math.random() * (i + 1)); | |
swap(t, i, j); | |
} | |
}; |
[ | |
{ | |
"name": "bug", | |
"color": "#A8B820", | |
"halfEffectiveAgainst": [ | |
"fairy", | |
"fighting", | |
"fire", | |
"flying", | |
"ghost", |