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
from polygenerator import random_polygon | |
import matplotlib.pyplot as plt | |
def is_inside(edges, xp, yp): | |
cnt = 0 | |
for edge in edges: | |
(x1, y1), (x2, y2) = edge | |
if (yp < y1) != (yp < y2) and xp < x1 + ((yp-y1)/(y2-y1))*(x2-x1): | |
cnt += 1 |
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
// Note: this gist is a part of this OSS project that I'm currently working on: https://github.com/steven-tey/dub | |
export default async function getTitleFromUrl (url: string) { | |
const controller = new AbortController(); | |
const timeoutId = setTimeout(() => controller.abort(), 2000); // timeout if it takes longer than 2 seconds | |
const title = await fetch(url, { signal: controller.signal }) | |
.then((res) => { | |
clearTimeout(timeoutId); | |
return res.text(); | |
}) |
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
/* These rules are ignored when ui-monospace is supported. */ | |
@font-face { font-family: ui-monospace; src: | |
/* MacOS (El Capitan +) */ | |
local(Menlo-Regular), | |
/* Windows (11 +) */ | |
local(CascadiaCode-Regular), | |
/* Windows (Vista +) */ | |
local(Consolas), | |
/* Android */ | |
local(RobotoMono-Regular), |
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
// codecols designed after Rasmus Andersson's linelen_hist.sh | |
// https://gist.github.com/rsms/36bda3b5c8ab83d951e45ed788a184f4 | |
{ | |
println: println | |
default: default | |
map: map | |
stdin: stdin | |
range: range | |
filter: filter |
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
// https://rsms.me/inter/dynmetrics | |
const DynamicText = ({ className, children, fontSize = 15, tag = "span" }) => { | |
const pxToRem = (px) => { | |
return Number(px * 0.0625) | |
} | |
const dynamicLeading = (z) => { | |
const l = 1.4 | |
return Number(pxToRem(Math.round(z * l))) |
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
interface LifecycleFunction { | |
(): void; | |
} | |
interface EventCallback<T = unknown> { | |
(event: CustomEvent<T>): void; | |
} | |
export namespace Svelte { | |
export interface Fragment { | |
key?: string | null; | |
first?: Comment | 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
/* | |
* Change from https://gist.github.com/unki2aut/4ac81c33be2e8f121e80a26eba1735d7 | |
* - Use top level await (Node.js v14.8.0+) | |
* - To use top level await, you need to write a script as ES Modules | |
* - Set chokidar options to avoid duplicate building | |
* - Define NODE_ENV (For React) | |
* - Add API proxy setting by using proxy-middleware | |
*/ | |
import chokidar from "chokidar"; | |
import esbuild from "esbuild"; |
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 log from "ololog" | |
class Grid { | |
rows = [] | |
width = 0 | |
height = 0 | |
chars = { | |
active: ["┌", "─", "┒", "┃", "┛", "━", "┕", "│"], | |
inactive: ["┌", "─", "┐", "│", "┘", "─", "└", "│"], |
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
// styled component version | |
const Container = styled.div` | |
/*all of the styles*/ | |
` | |
function MyComponent() { | |
return <Container>{/*other stuff*/}</Container> | |
} | |
// css prop version |
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 { useEffect, useReducer } from 'react'; | |
type State<TState, TEffect> = TState & { | |
effects?: TEffect[]; | |
}; | |
export type UseFsmReducerEffects<TAction, TEffect extends { type: string }> = { | |
[K in TEffect['type']]: (params: { | |
effect: Extract<TEffect, { type: K }>; | |
dispatch: (action: TAction) => void; |
NewerOlder