Instantly share code, notes, and snippets.

Nyaning in O(1)

# Jiayi Hujiayihu

Nyaning in O(1)
• Sort options
Last active May 22, 2019
Cross-project utilities
View utils.ts
 export type Omit = Pick>; export type ValueOf = T[keyof T]; export function assertNever(_: never): never { throw new Error('Unreachable code'); } export function debounce) => void>(fn: F, delay: number): F { let timer: number;
Created Sep 23, 2018
Determine the intersection of a segment, having ad edge in the center of circle, with the circle itself
View intersect.ts
 /** * Determine the intersection of a segment, having ad edge in the center of circle, * with the circle itself */ function intersect( xc: number, yc: number, radius: number, x1: number, y1: number
Created Sep 23, 2018
Determine the intersection point of two line segments, but considering also colinear segments as intersection
View segment-intersection.js
 /** * Determine the intersection point of two line segments, but considering also * colinear segments as intersection * @see {@link http://paulbourke.net/geometry/pointlineplane/} */ function intersect( x1, y1, x2, y2, x3, y3, x4, y4 ) {
Last active Sep 23, 2018
Find the nearest point in the perimeter of a rectangle to a given point. JavaScript/TypeScript porting
View getNearestPointInPerimeter.js
 /** * TS porting of https://stackoverflow.com/questions/20453545/how-to-find-the-nearest-point-in-the-perimeter-of-a-rectangle-to-a-given-point */ function clamp(x: number, lower: number, upper: number): number { return Math.max(lower, Math.min(upper, x)); } export function getNearestPointInPerimeter( l: number,
Last active May 26, 2018
View streams.hs
 module Stream where import Stream.Internal import Debug.Trace import Control.Arrow import Control.Applicative -- | Get the first element of a stream. headS :: Stream a -> a
Created Dec 24, 2017 — forked from davidgilbertson/copyStyles.js
View copyStyles.js
 function copyStyles(sourceDoc, targetDoc) { Array.from(sourceDoc.styleSheets).forEach(styleSheet => { if (styleSheet.cssRules) { // for
Created Dec 8, 2017
Pure JS animated scrollTop using requestAnimationFrame
View scroll.ts
 export function animateScrollTop(element: HTMLElement, value: number, timing: number) { let start: number = null; let animationToken: number; const valueSign = value >= 0 ? 1 : -1; const currentScroll = element.scrollTop; const step = (timestamp: number) => { if (!start) { start = timestamp; }
Created Mar 9, 2017
Allow subscription, as Promise, to redux-saga and redux-observable POJO actions
View action-lifecycle.middleware.ts
 import { Middleware } from 'redux'; export interface IActionLifecycle { resolveType: string; rejectType: string; } /** * Middleware which allows to chain async actions as Promises. * @see https://github.com/redux-observable/redux-observable/issues/90
Last active Jul 9, 2019
Minimal action creator factory for redux-observable and redux-saga
View actionCreator.ts
 import { IAction } from '../types/redux.types'; import { actionTypes as errorTypes, showError } from './errors.actions'; interface IPayloadCreators { request(...args: any[]): any; success(...args: any[]): any; failure?(errorMsg: string): any; } interface IActionCreator {
Created Feb 19, 2017
View iTerm-profile.json
 { "Right Option Key Sends" : 0, "Tags" : [ ], "Ansi 12 Color" : { "Red Component" : 0.1268280595541, "Color Space" : "Calibrated", "Blue Component" : 0.998526930809021, "Alpha Component" : 1,
You can’t perform that action at this time.