Skip to content

Instantly share code, notes, and snippets.

@jrson83
jrson83 / router.ts
Created May 20, 2023 18:00 — forked from idan/router.ts
basic router in typescript
export type Route = {
method: "*" | "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "HEAD" | "OPTIONS" | "CONNECT" | "TRACE"
path: string
regexp: RegExp
handler: (request: Request, route: MatchedRoute) => Promise<Response>
}
export type MatchedRoute = Route & {
url: URL
}
@jrson83
jrson83 / changelog.js
Created June 1, 2023 11:10 — forked from NicolasRitouet/changelog.js
Changelog.js
#!/usr/bin/env node
// TODO(vojta): pre-commit hook for validating messages
// TODO(vojta): report errors, currently Q silence everything which really sucks
'use strict';
var child = require('child_process');
var fs = require('fs');
var util = require('util');
@jrson83
jrson83 / bem-and-sass.md
Created July 2, 2023 01:07 — forked from radist2s/bem-and-sass.md
BEM & SASS best practices

BEM & SASS best practices

Every block should be in separated file named as block.

Filename: rating-star.scss

.rating-star {
    $font-size: 0.5em;
    
    display: inline-block; // `display` style may be set freely
@jrson83
jrson83 / code.tsx
Created July 4, 2023 22:05 — forked from pettaysergey/code.tsx
Code-1
import * as React from 'react';
export const getNodeArray = <Props = any>(
components: React.ReactNode,
filter?: string | React.ComponentClass<any> | React.SFC<any>,
) => {
let result = React.Children.toArray(components).map(React.Children.only) as React.ReactElement<Props>[];
if (filter) {
result = result.filter((c) => {
import { useState, useLayoutEffect } from 'react'
type FullScreenState = boolean
type ToggleFullScreen = () => void
function useFullScreen<E extends HTMLElement>(ref: React.RefObject<E>): [FullScreenState, ToggleFullScreen] {
const [isFullScreen, setFullScreen] = useState(
Boolean(document.fullscreenElement),
)
@jrson83
jrson83 / type-scale.sass
Created July 31, 2023 03:17 — forked from nfrostdev/type-scale.sass
SASS Type Scale
// The basis of calculations, and your root html font size.
$base-font-size: 16px
// Change this to your type scale modifier.
// https://type-scale.com/
$type-scale: 1.25
// The desired unit supports "rem", "em", and "%".
$desired-unit: 'rem'
// Generate a type scale value based on the number of steps if this is ascending or descending.
// It is recommended to compile with the "--precision 3" flag to avoid long decimals.
@jrson83
jrson83 / input.scss
Created July 31, 2023 13:44
Generated by SassMeister.com.
.collapse {
width: 100%;
margin: 1rem 0;
border: 1px solid var(--x33);
border-radius: 0.25rem;
background: #fff;
background-color: var(--x22);
&__header {
@jrson83
jrson83 / input.scss
Created July 31, 2023 13:45
Generated by SassMeister.com.
@use 'sass:map';
$colors: () !default;
$colors: map.merge(
(
'light': (
'color-bg': hsl(0deg 0 100),
'color-surface': hsl(0deg 0 90),
'color-text': hsl(0deg 0 0),
'color-text-2': hsl(0deg 0 10),
@jrson83
jrson83 / input.scss
Created August 1, 2023 04:39
Generated by SassMeister.com.
@use 'sass:map';
@use 'sass:math';
$font-size-base: 1rem !default;
$font-size-min: 0.875rem !default;
$font-size-max: 1.125rem !default;
$font-ratios: () !default;
$font-ratios: map.merge(
(
@jrson83
jrson83 / detect.ts
Created August 14, 2023 01:01
detect package manager
import fs from 'node:fs/promises'
import path from 'node:path'
import { exec } from 'node:child_process'
import { promisify } from 'node:util'
export const execAsync = promisify(exec)
export interface PackageJson {
name: string