Skip to content

Instantly share code, notes, and snippets.

Avatar

Pablo Damnhorns nodkz

View GitHub Profile
@nodkz
nodkz / fix-package-json.ts
Created Jun 6, 2019
Make fixed versions for packages in package.json according to installed packages (w/ Lerna support)
View fix-package-json.ts
import * as glob from 'glob';
import * as fs from 'fs';
import * as path from 'path';
async function changePackage(ppp: any) {
try {
const filesToUpdate: string[] = await new Promise((resolve, reject) => {
glob(ppp, function(err, files) {
if (err) return reject(err);
return resolve(files);
@nodkz
nodkz / component.js
Created Aug 25, 2018
Relay: unmask fragment by reading data from store
View component.js
function itemTrackingHelper(relayContext, item) {
const {title, description} = unmaskFragmentData({
relayContext,
relayData: item,
fragmentPropName: 'item',
fragment: itemTrackingHelperFragment
});
}
const itemTrackingHelperFragment = graphql`
@nodkz
nodkz / fixPackageRelayCompiler.1.4.js
Created Jul 5, 2018
Add optionalChaining to relay-compiler@1.4.1
View fixPackageRelayCompiler.1.4.js
/* @flow */
const fs = require('fs');
// Add support for optionalChaining in relay-compiler 1.4
const filename = './node_modules/relay-compiler/bin/relay-compiler';
fs.readFile(filename, 'utf8', (err, data) => {
if (err) {
return console.log(err);
@nodkz
nodkz / 1-server-generate-sign-url.js
Last active Oct 20, 2019
Upload image to S3 with resizing using lambda functions via hooks
View 1-server-generate-sign-url.js
/* @flow */
/* eslint-disable no-param-reassign */
import express, { type $Request, type $Response } from 'express';
import uniqid from 'uniqid';
import aws from 'aws-sdk';
export type SignResult = {
publicUrl: string,
signedUrl: string,
@nodkz
nodkz / client.js
Last active Mar 15, 2018
Proposal for react-relay-network-modern-ssr package
View client.js
// client
import { RelayNetworkLayer } from 'react-relay-network-modern';
import RelaySSR from 'react-relay-network-modern-ssr/client';
const relaySSR = new RelaySSR(window.relayData);
const network = new RelayNetworkLayer([
relaySSR.getMiddleware(),
]);
@nodkz
nodkz / LookupQueryRenderer.js
Created Dec 27, 2017
Relay.Modern query renderers
View LookupQueryRenderer.js
/* @flow */
/* eslint-disable no-use-before-define, react/no-unused-prop-types */
import * as React from 'react';
import areEqual from 'fbjs/lib/areEqual';
// forked from https://github.com/robrichard/relay-query-lookup-renderer
// import type { CacheConfig, Disposable } from 'RelayCombinedEnvironmentTypes';
// import type { RelayEnvironmentInterface as ClassicEnvironment } from 'RelayEnvironment';
View ModernNetworkLayer.js
// __IS_SERVER__ declared via Webpack globals
// const __IS_SERVER__ = typeof process === 'object' && process + '' === '[object process]';
if (__IS_SERVER__) {
const RRNL = require('react-relay-network-modern/node8'); // eslint-disable-line
const graphql = require('graphql').graphql; // eslint-disable-line
const schema = require('schema').default; // eslint-disable-line
return new RRNL.RelayNetworkLayer([
RRNL.cacheMiddleware({
size: 100,
ttl: 900000,
@nodkz
nodkz / package.json
Created Nov 20, 2017
Ram disk via scripts
View package.json
{
"scripts": {
"ram": "yarn ram-check-disk && yarn ram-create-disk && yarn ram-link-node-modules && yarn ram-link-build && yarn install && yarn start",
"ram-check-disk": "[ -d /Volumes/npm_ram_disk ] && echo 'Disk already mounted!' && yarn build && exit 1 || exit 0",
"ram-create-disk": "diskutil erasevolume hfsx npm_ram_disk `hdiutil attach -nomount ram://1600000`",
"ram-link-node-modules": "mkdir /Volumes/npm_ram_disk/node_modules && rm -r -f ./node_modules && ln -s /Volumes/npm_ram_disk/node_modules ./node_modules",
"ram-link-build": "mkdir /Volumes/npm_ram_disk/build && rm -r -f ./build && ln -s /Volumes/npm_ram_disk/build ./build",
}
}
@nodkz
nodkz / user.js
Created Nov 8, 2017
Mongoose with flow example
View user.js
/* @flow */
/* eslint-disable func-names */
import { Schema } from 'mongoose';
import DB from 'schema/db';
import composeWithMongoose from 'graphql-compose-mongoose';
import composeWithRelay from 'graphql-compose-relay';
import crypto from 'crypto';
import bcrypt from 'bcrypt';
import type { $Request } from 'express';
@nodkz
nodkz / react-relay_vx.x.x.js
Created Oct 18, 2017
react-relay flowtype declaration
View react-relay_vx.x.x.js
import * as React from "react";
declare class RelayComponentClass<Props> extends React$Component<Props, any> {
static getFragment: Function;
};
declare type createFragmentContainer = <TBase>(
Component: Class<React$Component<TBase, any>> | (props: TBase) => React.Node,
fragmentSpec: any
) => Class<RelayComponentClass<TBase>>;
You can’t perform that action at this time.