Skip to content

Instantly share code, notes, and snippets.

View KubaJastrz's full-sized avatar
🗳️
Beware of Big Package

Kuba Jastrzębski KubaJastrz

🗳️
Beware of Big Package
View GitHub Profile
@akwodkiewicz
akwodkiewicz / resolver.js
Created May 10, 2024 08:59
Custom Jest resolver to solve "dual state" issues with self-referencing and subpath imports in TypeScript projects
/**
* This resolver forces Jest to look at a *custom* `"jest"` condition in `package.json#exports`.
*
* Whenever you use self-referencing imports or subpath imports in the source code (or tests)
* the default behaviour of Jest is to go to the package's manifest for information, and resolve
* the import by choosing one of the conditions that are used by Node ("node", "default", etc.).
*
* The issue is that "node"/"default" usually points to transpiled `.js` files, whereas if you decide to
* run the tests on the `.ts` source code (with the help of a transformer such as ts-jest or @swc/jest),
* you need Jest to **only** load the `.ts` files. Otherwise, you end up with duplicated classes,
$palettes: (
"blue": (
lightest: hsl(201, 87%, 72%),
lighter: hsl(201, 81%, 65%),
light: hsl(201, 77%, 58%),
base: hsl(201, 75%, 51%),
dark: hsl(201, 77%, 46%),
darker: hsl(201, 81%, 41%),
darkest: hsl(201, 87%, 36%)
),

Boolean() or !! (double bang, double negation)?

What's the best way to answer the question "true or false?" in JavaScript

JavaScript does not bother you too much with types (at first), which is both a blessing and a cure. But we all know the Boolean type. Boolean variables can either be true or false. Yes or no.

Every value in JavaScript can be translated into a boolean, true or false. Values that translate to true are truthy, values that translate to false are falsy. Simple.

This is about two ways to make that translation.

@atomiks
atomiks / LazyTippy.jsx
Last active February 9, 2023 02:10
Lazy Tippy
// Will only render the `content` or `render` elements if the tippy is mounted to the DOM.
// Replace <Tippy /> with <LazyTippy /> component and it should work the same.
const LazyTippy = forwardRef((props, ref) => {
const [mounted, setMounted] = useState(false);
const lazyPlugin = {
fn: () => ({
onMount: () => setMounted(true),
onHidden: () => setMounted(false),
@pie6k
pie6k / useShareForwardedRef.tsx
Created October 23, 2019 10:02
forwardRef hook
import React, { useRef, forwardRef, Ref, useEffect } from 'react';
import { TextInputProps, TextInput } from 'react-native';
import styled from 'styled-components/native';
interface Props extends TextInputProps {
showEditLabel?: boolean;
}
const Input = styled.TextInput``;
@tkrotoff
tkrotoff / FrontendFrameworksPopularity.md
Last active July 14, 2024 18:01
Front-end frameworks popularity (React, Vue, Angular and Svelte)
@swyxio
swyxio / 1.md
Last active February 8, 2024 22:30
Learn In Public - 7 opinions for your tech career

2019 update: this essay has been updated on my personal site, together with a followup on how to get started

2020 update: I'm now writing a book with updated versions of all these essays and 35 other chapters!!!!

1. Learn in public

If there's a golden rule, it's this one, so I put it first. All the other rules are more or less elaborations of this rule #1.

You already know that you will never be done learning. But most people "learn in private", and lurk. They consume content without creating any themselves. Again, that's fine, but we're here to talk about being in the top quintile. What you do here is to have a habit of creating learning exhaust. Write blogs and tutorials and cheatsheets. Speak at meetups and conferences. Ask and answer things on Stackoverflow or Reddit. (Avoid the walled gardens like Slack and Discourse, they're not public). Make Youtube videos

@chrisriesgo
chrisriesgo / emoji-code-review-comments.md
Last active March 1, 2024 13:05
Emoji Code Review Comments

Emoji Code Review Comments

Legend

Emoji Translation
😃 😍 I like this!
No changes or acknowledgements needed. Just wanted to say well done.
⚠️ Problem
This is a blocking issue and requires changes.
🔧 🎨 Suggestion
Not blocking, but a suggestion or idea for improvement. Feel free to disagree and move on.
QuestionNot blocking, but requires an answer by the PR/code author.
@lukechilds
lukechilds / get_latest_release.sh
Created August 9, 2016 19:43
Shell - Get latest release from GitHub
get_latest_release() {
curl --silent "https://api.github.com/repos/$1/releases/latest" | # Get latest release from GitHub api
grep '"tag_name":' | # Get tag line
sed -E 's/.*"([^"]+)".*/\1/' # Pluck JSON value
}
# Usage
# $ get_latest_release "creationix/nvm"
# v0.31.4
@robmiller
robmiller / git-cleanup-repo
Last active February 27, 2024 10:09
A script for cleaning up Git repositories; it deletes branches that are fully merged into `origin/master`, prunes obsolete remote tracking branches, and as an added bonus will replicate these changes on the remote.
#!/bin/bash
# git-cleanup-repo
#
# Author: Rob Miller <rob@bigfish.co.uk>
# Adapted from the original by Yorick Sijsling
git checkout master &> /dev/null
# Make sure we're working with the most up-to-date version of master.
git fetch