Skip to content

Instantly share code, notes, and snippets.

@AndrewIngram
AndrewIngram / PostDetail.jsx
Last active October 23, 2022 01:56
Updated Next.js with Relay (still using getInitialProps)
import React from "react";
import { graphql } from "react-relay";
import createPageContainer from "../relay/createPageContainer";
import PostLayout from "../components/PostLayout";
import Header from "../components/Header";
import Shell from "../layouts/Shell";
@AugustoCalaca
AugustoCalaca / UserAddedSubscription.spec.ts
Last active March 22, 2023 23:43
An example of how to test graphql subscriptions with jest
import { graphql, subscribe, parse } from 'graphql';
import {
connectMongoose,
disconnectMongoose,
clearDbAndRestartCounters,
getContext,
} from '../../../../../test/helpers';
import { schema } from '../../../../schema/schema';
@stubailo
stubailo / graphql-field-finder.js
Last active November 9, 2020 18:55
Find all GraphQL queries in your codebase that use a certain field
// This is a script that looks for usage of a specific field in GraphQL
// queries in your codebase.
//
// First, add a .graphqlconfig in your directory pointing to your schema
// Then, run the script with:
//
// node graphql-field-finder.js Field.name
//
// It will output a list of files and queries that contain the field you're
// looking for:
@jlisee
jlisee / protobuf-js-enum-to-int.js
Created October 30, 2018 02:56
Use protobuf.js to turn string fields in to integers so you can run Message.verify on the object
const PRIMITIVE_PROTO_TYPES = new Set([
'double',
'float',
'int32',
'int64',
'uint32',
'uint64',
'sint32',
'sint64',
'fixed32',
@wesbos
wesbos / async-await.js
Created February 22, 2017 14:02
Simple Async/Await Example
// 🔥 Node 7.6 has async/await! Here is a quick run down on how async/await works
const axios = require('axios'); // promised based requests - like fetch()
function getCoffee() {
return new Promise(resolve => {
setTimeout(() => resolve('☕'), 2000); // it takes 2 seconds to make coffee
});
}
@afraser
afraser / draftjs_inline_equations.js
Last active May 11, 2021 02:05
Demonstrates inline equations with copy/paste supported in draft.js
<!--
Copyright (c) 2013-present, Facebook, Inc. All rights reserved.
This file provided by Facebook is for non-commercial testing and evaluation
purposes only. Facebook reserves all rights not expressly granted.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
@cboettig
cboettig / docker-compose.yml
Last active December 31, 2023 15:23
debugging NGINX configuration for Jupyter
jupyter:
image: jupyter/datascience-notebook
environment:
- PASSWORD=${PASSWORD}
nginx:
image: nginx
links:
- jupyter
@jboner
jboner / latency.txt
Last active July 30, 2024 02:24
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@muddylemon
muddylemon / standard-privacy-policy.html
Created May 13, 2012 02:44
Standard Privacy Policy
<div class="privacy-policy">
<h1>Privacy Policy</h1>
<section id="privacy-information-we-collect">
<h3>What information do we collect?</h3>
<p>We collect information from you when you register on our site, place an order, subscribe to our newsletter, respond to a survey or fill out a form.</p>
<p>When ordering or registering on our site, as appropriate, you may be asked to enter your: name, e-mail address, mailing address, phone number, credit card information or social security number. You may, however, visit our site anonymously.
Google, as a third party vendor, uses cookies to serve ads on your site. Google's use of the DART cookie enables it to serve ads to your users based on their visit to your sites and other sites on the Internet. Users may opt out of the use of the DART cookie by visiting the Google ad and content network privacy policy.</p>
</section>