Skip to content

Instantly share code, notes, and snippets.

View zaydek's full-sized avatar
🤠
Howdy!

Zaydek MG zaydek

🤠
Howdy!
View GitHub Profile
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
@steven-tey
steven-tey / title-from-url.ts
Last active July 9, 2023 19:48
Get Title from URL
// 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();
})
@jonathantneal
jonathantneal / ui-monospace.css
Created July 31, 2022 23:16
CSS ui-monospace polyfill (448 bytes minified, 182 gzipped)
/* 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),
@thesephist
thesephist / codecols.oak
Created March 30, 2022 01:17
Count and plot histograms of line length in source code
// 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
@thomaswangarchive
thomaswangarchive / DynamicText.jsx
Created February 28, 2022 20:28
Inter dynamic tracking as a React component
// 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)))
@pushkine
pushkine / svelte.ts
Last active February 9, 2021 09:37
Accurate typings for Svelte's compiler output, includes comments for ambiguous properties and type functions for advanced use cases
interface LifecycleFunction {
(): void;
}
interface EventCallback<T = unknown> {
(event: CustomEvent<T>): void;
}
export namespace Svelte {
export interface Fragment {
key?: string | null;
first?: Comment | null;
@mtgto
mtgto / serve.mjs
Last active August 25, 2023 03:10
Hot reload and do incremental builds with `esbuild`
/*
* 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";
@steveruizok
steveruizok / render-state.js
Last active November 17, 2020 14:01
Render a State Designer state in the terminal.
import log from "ololog"
class Grid {
rows = []
width = 0
height = 0
chars = {
active: ["┌", "─", "┒", "┃", "┛", "━", "┕", "│"],
inactive: ["┌", "─", "┐", "│", "┘", "─", "└", "│"],
// styled component version
const Container = styled.div`
/*all of the styles*/
`
function MyComponent() {
return <Container>{/*other stuff*/}</Container>
}
// css prop version
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;