Skip to content

Instantly share code, notes, and snippets.

View kentcdodds's full-sized avatar
🤓
working hard to make the world better with software

Kent C. Dodds kentcdodds

🤓
working hard to make the world better with software
View GitHub Profile
@kentcdodds
kentcdodds / package-exact.js
Last active February 2, 2024 12:08
make your package.json dependencies be the exact version that's in your node_modules currently
/* jshint node:true */
/* eslint-env node */
/*
* This will look at the current version of all of your dependencies and update your package.json
* with the specific version that you currently have in node_modules. This will save you from the
* sadness that is: DEPENDENCY MANAGEMENT
*
* Place this file in a folder that's a a sibling to your package.json and node_modules
* Then simply run: node scripts/package-strict
@kentcdodds
kentcdodds / get-watchers.js
Last active December 4, 2023 22:34
Get Watchers of element and its children
function getWatchers(root) {
root = angular.element(root || document.documentElement);
var watcherCount = 0;
function getElemWatchers(element) {
var isolateWatchers = getWatchersFromScope(element.data().$isolateScope);
var scopeWatchers = getWatchersFromScope(element.data().$scope);
var watchers = scopeWatchers.concat(isolateWatchers);
angular.forEach(element.children(), function (childElement) {
watchers = watchers.concat(getElemWatchers(angular.element(childElement)));
@kentcdodds
kentcdodds / .gitignore
Last active November 28, 2023 17:31
This will create a Google Voice "native" app on your computer
node_modules
@kentcdodds
kentcdodds / fake.js
Created August 22, 2014 19:28
github contribution graph fake
var colors = [
'rgb(30, 104, 35)', 'rgb(68, 163, 64)', 'rgb(140, 198, 101)', 'rgb(214, 230, 133)', 'rgb(238, 238, 238)'
];
var days = $('#calendar-graph').find('rect.day');
days.css({
fill: colors[4]
});
days.on('click', function(e) {
e.stopPropagation();
$this = $(this);
@kentcdodds
kentcdodds / create-required-context.js
Created May 15, 2018 22:31
create react context that has a validated consumer.
// create a React context Provider/Consumer pair that
// validates the consumer is rendered within a provider
function createRequiredContext(name) {
const Context = React.createContext()
function Consumer(props) {
return (
<Context.Consumer {...props}>
{val => {
if (!val) {
@kentcdodds
kentcdodds / notes.md
Created October 17, 2023 03:10
Survey notes
type ScaleSurveyQuestion = {
  id: string;
  question: string;
  type: 'multiple-choice'
  choices: Array<{label: string; answer: string}>;
};

type FreeformSurveyQuestion = {
  id: string;
import 'dotenv/config.js'
import chromadb from 'chromadb'
import { RetrievalQAChain } from 'langchain/chains'
import { ChatOpenAI } from 'langchain/chat_models/openai'
import { OpenAIEmbeddings } from 'langchain/embeddings/openai'
import { Chroma } from 'langchain/vectorstores/chroma'
const { OpenAIEmbeddingFunction, ChromaClient } = chromadb
const COLLECTION_NAME = 'test-collection'
diff --git var/folders/kt/zd3bfncd0c3gjx25hbcq483c0000gn/T/kcdshop/diff/full-stack-testing/exercises__sep__11.finish__sep__01.solution.finished/rbb60w04h7/.env var/folders/kt/zd3bfncd0c3gjx25hbcq483c0000gn/T/kcdshop/diff/full-stack-testing/exercises__sep__11.finish__sep__01.problem.finished/rbb60w04h7/.env
index d049969..4ac848d 100644
--- var/folders/kt/zd3bfncd0c3gjx25hbcq483c0000gn/T/kcdshop/diff/full-stack-testing/exercises__sep__11.finish__sep__01.solution.finished/rbb60w04h7/.env
+++ var/folders/kt/zd3bfncd0c3gjx25hbcq483c0000gn/T/kcdshop/diff/full-stack-testing/exercises__sep__11.finish__sep__01.problem.finished/rbb60w04h7/.env
@@ -1,2 +1,6 @@
DATABASE_URL="file:./data.db"
SESSION_SECRET="super-duper-s3cret"
+RESEND_API_KEY="some-secret-key"
+GITHUB_TOKEN="MOCK_abc12392lfkjlsf0"
+GITHUB_CLIENT_ID="MOCK_Iv1.abc12392lfkjlsf0"
export const sessionKey = 'sessionId'
export const authenticator = new Authenticator<string>(sessionStorage, {
sessionKey,
})
authenticator.use(
new GitHubStrategy(
{
clientID: process.env.GITHUB_CLIENT_ID,
@kentcdodds
kentcdodds / diff.patch
Last active July 19, 2023 17:47
Big git diff
diff --git var/folders/kt/zd3bfncd0c3gjx25hbcq483c0000gn/T/kcdshop/diff/data-modeling/exercises__sep__01.init__sep__01.problem.named/39yuovg9r3j/app/root.tsx var/folders/kt/zd3bfncd0c3gjx25hbcq483c0000gn/T/kcdshop/diff/data-modeling/exercises__sep__09.finished__sep__01.problem/39yuovg9r3j/app/root.tsx
index 7dee21b..6c3aa4b 100644
--- var/folders/kt/zd3bfncd0c3gjx25hbcq483c0000gn/T/kcdshop/diff/data-modeling/exercises__sep__01.init__sep__01.problem.named/39yuovg9r3j/app/root.tsx
+++ var/folders/kt/zd3bfncd0c3gjx25hbcq483c0000gn/T/kcdshop/diff/data-modeling/exercises__sep__09.finished__sep__01.problem/39yuovg9r3j/app/root.tsx
@@ -104,7 +104,6 @@ export const meta: V2_MetaFunction = () => {
{ name: 'description', content: `Your own captain's log` },
]
}
-// change