Skip to content

Instantly share code, notes, and snippets.

@gynekolog
gynekolog / remove-apollo-suspense-queries.ts
Last active August 7, 2024 09:34
Usage: jscodeshift -t ./remove-apollo-suspense-queries.ts ./your-file.ts
import type { API, FileInfo } from "jscodeshift";
// @graphql-codegen/typescript-react-apollo package generates SuspenseQuery functions that are not supported in used apollo versions.
// The codegen package does not provide an option to disable this feature, so we need to remove the generated SuspenseQuery functions manually.
export default function transform(file: FileInfo, api: API): string | undefined {
const j = api.jscodeshift.withParser("ts");
const root = j(file.source);
// Find and comment out all function declarations that end with "SuspenseQuery"
root
@gynekolog
gynekolog / bytesToSize.ts
Created March 18, 2024 11:38
Typescript To Convert Bytes To MB, KB, Etc
export function convertBytes(bytes: number, options: { useBinaryUnits?: boolean; decimals?: number } = {}): string {
const { useBinaryUnits = false, decimals = 2 } = options;
if (decimals < 0) {
throw new Error(`Invalid decimals ${decimals}`);
}
const base = useBinaryUnits ? 1024 : 1000;
const units = useBinaryUnits
? ["Bytes", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"]
@gynekolog
gynekolog / pagination.ts
Last active March 26, 2024 16:05
Pagination generator
// The code is based on https://gist.github.com/kottenator/9d936eb3e4e3c3e02598#gistcomment-3238804
type PageItem = number | "...";
export const getRange = (start: number, end: number): PageItem[] => {
if (end < start) throw Error(`End number must be higher then start number: start ${start}, end ${start}`);
const rangeLength = end - start + 1;
return Array(rangeLength)
.fill(0)
@gynekolog
gynekolog / lang_chrome_osx.md
Last active August 14, 2022 09:47 — forked from kentbrew/lang_chrome_osx.md
How to change the Chrome default language on OSX

How to Change your Chrome Default Language

Open up a Terminal window. (If you have never seen Terminal before, go to Spotlight Search and type "Terminal.")

In the Terminal box, try this:

defaults read com.google.Chrome AppleLanguages

If you see this: