Skip to content

Instantly share code, notes, and snippets.

View maraisr's full-sized avatar
:fishsticks:

marais maraisr

:fishsticks:
View GitHub Profile
@sibelius
sibelius / setupSubscription.tsx
Created February 13, 2020 16:35
basic setupSubscription for Relay Environment
import { SubscribeFunction, Observable } from 'relay-runtime';
import { SubscriptionClient } from 'subscriptions-transport-ws';
import config from '../config';
import { getToken } from '../components/auth/security';
export const setupSubscription: SubscribeFunction = (request, variables) => {
const query = request.text;
const authorization = getToken();
const { createServer } = require('http');
createServer((req, res) => {
res.writeHead(200, {
Connection: 'Transfer-Encoding',
'Content-Type': 'text/html; charset=utf-8',
'Transfer-Encoding': 'chunked'
});
res.write(`
@sibelius
sibelius / useLocalQuery.tsx
Created July 26, 2019 19:24
useLocalQuery hook to consume local data from a GraphQL Query
const useLocalQuery = <TQuery extends {response: any; variables: any}>(
environment: Environment,
query: any,
inVariables: TQuery['variables'] = {}
): TQuery['response'] | null => {
const variables = useDeepEqual(inVariables)
const [dataRef, setData] = useRefState<SelectorData | null>(null)
const disposablesRef = useRef<Disposable[]>([])
useEffect(() => {
const {getRequest, createOperationDescriptor} = environment.unstable_internal
/** Converts destructured parameters with default values to non-shorthand syntax, fixing Edge 16 & 17. */
module.exports = (babel, options = {}) => {
const { types: t } = babel;
const isArrowParent = p => p.parentKey=='params' && p.parentPath && p.parentPath.isArrowFunctionExpression();
return {
name: "transform-edge-default-parameters",
visitor: {
AssignmentPattern(path) {
@maxboeck
maxboeck / donottrack.js
Last active November 6, 2023 10:00
Check "Do Not Track" Client Hint
const allowsTracking = () => {
const dnt =
window.doNotTrack ||
navigator.doNotTrack ||
navigator.msDoNotTrack
if (dnt === 1 || dnt === '1' || dnt === 'yes') {
return false
}
if ('msTrackingProtectionEnabled' in window.external) {
return !window.external.msTrackingProtectionEnabled()
<script>
export default {
props: {
span: {
type: String,
default: null
}
},
render: function (createElement) {
return createElement(
@ro-savage
ro-savage / relayStore.js
Created February 12, 2019 10:42
Implement a cache and fetch with relay
// This code is untested. It may new some minor modifications to work
import RelayQueryResponseCache from "relay-runtime/lib/RelayQueryResponseCache";
import {
Environment,
Network,
RecordSource,
Store,
Observable
@Jessidhia
Jessidhia / react-scheduler.md
Last active March 1, 2024 13:51
Implementation notes on react's scheduling model as of (shortly before) 16.8.0

Implementation notes on react's scheduling model as of (shortly before) 16.8.0

While the public API intended for users to use is the scheduler package, the reconciler currently does not use scheduler's priority classes internally.

ReactFiberScheduler has its own internal "mini-scheduler" that uses the scheduler package indirectly for its deadline-capable scheduleCallback.

This is kind of a documentation of implementation details that I suppose will be gone by the end of the year, but what can you do.

@gricard
gricard / webpack4upgrade.md
Last active February 29, 2024 20:23
Just some notes about my attempt to upgrade to webpack 4

If you enjoyed reading this, I'm intending to do more blogging like this over here: https://cdgd.tech

This is not a complaint about Webpack or v4 in any way. This is just a record of my process trying it out so I could provide feedback to the webpack team

Hmm... I don't see any docs for 4.0 on https://webpack.js.org. I guess I'll just wing it. All I need to do is npm i -D webpack@next, right?

+ webpack@4.0.0-beta.2
@JordanReiter
JordanReiter / input-month-polyfill.js
Last active January 25, 2023 08:55
Polyfill for input type="month" with no dependencies.
(function() {
var monthInputs = document.querySelectorAll('input[type="month"]'),
checkDateInput = document.createElement('input'),
dateSupported = false,
months = [],
lang = document.documentElement.lang || navigator.language,
DEFAULT_SPAN = 5;
if (monthInputs[0].type === 'month') {
// browser supports month input; no need for polyfill