Skip to content

Instantly share code, notes, and snippets.

View orion55's full-sized avatar

Orion55 orion55

  • 17:55 (UTC +05:00)
View GitHub Profile
@orion55
orion55 / index.d.ts
Created August 28, 2023 04:59
stats
type Comparator<T> = (a: T, b: T) => number;
type GetIndex = <T>(input: T[], comparator: Comparator<T>) => number;
export const getMaxIndex: GetIndex;
export const getMinIndex: GetIndex;
export const getMedianIndex: GetIndex;
type GetElement = <T>(input: T[], comparator: Comparator<T>) => T | null;
export const getMaxElement: GetElement;
export const getMinElement: GetElement;
@orion55
orion55 / index.d.ts
Created August 28, 2023 04:38
str-utils
declare module 'str-utils' {
type StrUtil = (input: string) => string;
export const strReverse: StrUtil;
export const strToLower: StrUtil;
export const strToUpper: StrUtil;
export const strRandomize: StrUtil;
export const strInvertCase: StrUtil;
}
@orion55
orion55 / promisify.ts
Created August 23, 2023 06:06
promisifyAll
type CallbackBasedAsyncFunction<T> = (callback: (response: ApiResponse<T>) => void) => void;
type PromiseBasedAsyncFunction<T> = () => Promise<T>;
export function promisify<T>(fn: CallbackBasedAsyncFunction<T>): PromiseBasedAsyncFunction<T> {
return () => new Promise<T>((resolve, reject) => {
fn((response) => {
if (response.status === 'success') {
resolve(response.data);
} else {
reject(new Error(response.error));
@orion55
orion55 / filterPersons01.ts
Created August 22, 2023 05:38
filterPersons01
const getObjectKeys = <T>(obj: T) => Object.keys(obj) as (keyof T)[];
export function filterPersons(persons: Person[], personType: User['type'], criteria: Partial<Omit<User, 'type'>>): User[];
export function filterPersons(persons: Person[], personType: Admin['type'], criteria: Partial<Omit<Admin, 'type'>>): Admin[];
export function filterPersons(persons: Person[], personType: Person['type'], criteria: Partial<Person>): Person[] {
return persons
.filter((person) => person.type === personType)
.filter((person) => {
let criteriaKeys = getObjectKeys(criteria);
return criteriaKeys.every((fieldName) => {
@orion55
orion55 / filterUsers.ts
Last active August 22, 2023 05:38
filterUsers
interface User {
type: 'user';
name: string;
age: number;
occupation: string;
}
interface Admin {
type: 'admin';
name: string;
@orion55
orion55 / Skeleton.tsx
Last active July 5, 2023 09:18
Skeleton
const Skeleton = styled.div`
border-radius: 4px;
background: ${({ theme }) => theme.color["Neutral/Neutral 10"]};
animation: flashing 1s infinite alternate;
@keyframes flashing {
0% {
opacity: 1;
}
90%,
@orion55
orion55 / media.scss
Last active March 3, 2024 17:34
Media queries
@include media-extra-small-down() {
}
@include media-extra-small-only2() {
}
@include media-compact-only() {
@orion55
orion55 / input.scss
Last active September 29, 2022 04:54
autofill
input {
&:-webkit-autofill,
&:-webkit-autofill:hover,
&:-webkit-autofill:focus {
background: $input-background;
border: 1px solid $text-input-primary;
-webkit-text-fill-color: $text-input-primary;
transition: background-color 5000s ease-in-out 0s;
-webkit-box-shadow: 0 0 0 1000px $input-background inset !important;
}
@orion55
orion55 / fils.scss
Created August 9, 2022 12:15
Create default scss-styles - saturn
@import "src/styles/colors.scss";
@import "src/styles/adaptive.scss";
@import "src/styles/variables.scss";
.$TM_FILENAME_BASE$ {
}
@orion55
orion55 / file.tsx
Created August 9, 2022 12:14
Create function components - orion55
import React from "react";
import styles from "./styles.module.scss";
import classNames from "classnames";
interface $TM_FILENAME_BASE$Props {
className?: string;
}
let cx = classNames.bind(styles);
const $TM_FILENAME_BASE$ = (props: $TM_FILENAME_BASE$Props) => {