Skip to content

Instantly share code, notes, and snippets.

View crossjs's full-sized avatar
🎯
Focusing

李文富 crossjs

🎯
Focusing
View GitHub Profile
@JohnBra
JohnBra / useStorage.tsx
Created July 4, 2022 22:44
Typed React useStorage hook for chrome extensions
import { Dispatch, SetStateAction, useState, useEffect, useCallback, useRef } from 'react';
export type StorageArea = 'sync' | 'local';
// custom hook to set chrome local/sync storage
// should also set a listener on this specific key
type SetValue<T> = Dispatch<SetStateAction<T>>;
/**
@sindresorhus
sindresorhus / esm-package.md
Last active June 6, 2024 20:54
Pure ESM package

Pure ESM package

The package that linked you here is now pure ESM. It cannot be require()'d from CommonJS.

This means you have the following choices:

  1. Use ESM yourself. (preferred)
    Use import foo from 'foo' instead of const foo = require('foo') to import the package. You also need to put "type": "module" in your package.json and more. Follow the below guide.
  2. If the package is used in an async context, you could use await import(…) from CommonJS instead of require(…).
  3. Stay on the existing version of the package until you can move to ESM.
@donfour
donfour / App.tsx
Last active December 15, 2023 02:12
Sample Editor.js plugin in React
import EditorJs from "react-editor-js";
import SimpleImage from "./SimpleImage";
const App = () => {
return (
<EditorJs
tools={{
simpleImage: SimpleImage,
}}
/>
@rahularity
rahularity / work-with-multiple-github-accounts.md
Last active June 7, 2024 10:26
How To Work With Multiple Github Accounts on your PC

How To Work With Multiple Github Accounts on a single Machine

Let suppose I have two github accounts, https://github.com/rahul-office and https://github.com/rahul-personal. Now i want to setup my mac to easily talk to both the github accounts.

NOTE: This logic can be extended to more than two accounts also. :)

The setup can be done in 5 easy steps:

Steps:

  • Step 1 : Create SSH keys for all accounts
  • Step 2 : Add SSH keys to SSH Agent
@superjose
superjose / .gitlab-ci.yml
Last active February 19, 2024 10:22
This is an example of a .gitlab-ci.yml that is required for Continuous Integration on GitLab projects.
# Reference: https://www.exclamationlabs.com/blog/continuous-deployment-to-npm-using-gitlab-ci/
# GitLab uses docker in the background, so we need to specify the
# image versions. This is useful because we're freely to use
# multiple node versions to work with it. They come from the docker
# repo.
# Uses NodeJS V 9.4.0
image: node:9.4.0
# And to cache them as well.
@navix
navix / readme.md
Last active August 4, 2023 09:02
TypeScript Deep Partial Interface

TypeScript Deep Partial Interface

export type DeepPartial<T> = T extends Function ? T : (T extends object ? { [P in keyof T]?: DeepPartial<T[P]>; } : T);

Before typescript@3.1

type DeepPartial = {
@perfecto25
perfecto25 / Jira API - Bash
Last active January 30, 2023 09:58
Jira API examples
# get all Custom fields on Jira server
curl -D- -u user:password -X GET -H "Content-Type: application/json" https://jira.instance.com/rest/api/2/field
# get JSON output of an issue
curl -D- -u user:password -X GET -H "Content-Type: application/json" https://jira.instance.com/rest/api/2/search?jql=key=INFO-68
# make 2 issues linked to each other
curl -u user:password -w '<%{http_code}>' -H 'Content-Type: application/json' https://jira.instance.com/rest/api/2/issueLink -X POST --data '{"type":{"name":"Related Incident"},"inwardIssue":{"key":"ISS-123"},"outwardIssue":{"key":"SYS-456"}}'
@paulirish
paulirish / what-forces-layout.md
Last active June 6, 2024 11:32
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Generally, all APIs that synchronously provide layout metrics will trigger forced reflow / layout. Read on for additional cases and details.

Element APIs

Getting box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
@Dr-Nikson
Dr-Nikson / README.md
Last active June 8, 2023 12:04
Auth example (react + redux + react-router)