Skip to content

Instantly share code, notes, and snippets.

View lucasbento's full-sized avatar
:shipit:

Lucas Bento lucasbento

:shipit:
View GitHub Profile
@taion
taion / server.js
Last active March 11, 2024 10:20
GraphQL subscription server with Socket.IO, backed by Redis Pub/Sub
const redisClient = redis.createClient(REDIS_URL);
const listeners = Object.create(null);
function addListener(channel, listener) {
if (!listeners[channel]) {
listeners[channel] = [];
redisClient.subscribe(channel);
}
listeners[channel].push(listener);
@sibelius
sibelius / prepareObjectSnapshot.js
Created September 15, 2016 21:39
Prepare an object to be snapshoted by jest
/**
* Prepare an object to be snapshoted by jest
* replace objectID
* replace datetime
* frozen same specific keys
* @param obj
* @returns {{}}
*/
export function prepareObject(obj, frozenKeys = []) {
const placeholder = {};
@mjackson
mjackson / resolvePromise.js
Last active September 9, 2018 08:23
An easy way to do async APIs in JavaScript that support both promises *and* callbacks!
// Here is a function that I use all the time when creating public
// async APIs in JavaScript:
const resolvePromise = (promise, callback) => {
if (callback)
promise.then(value => callback(null, value), callback)
return promise
}
// Sometimes I like to use callbacks, but other times a promise is
@vdh
vdh / Root.jsx
Created September 26, 2016 23:55
Moderately-successful hot reloading for react-router v3
import React, { PropTypes } from 'react';
import { Provider } from 'react-redux'; // Or something else, if you're not using Redux
import Router from 'react-router/lib/Router';
const Root = ({ store, history, routes }) => (
<Provider store={store} key="provider">
<Router history={history} routes={routes} />
</Provider>
);
@knowbody
knowbody / ex-navigation.md
Last active July 17, 2023 10:14
My exponent's ex-navigation docs/thoughts

Exponent - ex-navigation

This is for now, for my personal use only, things might not be correctly explained here. For the official docs please check: https://github.com/exponentjs/ex-navigation/blob/master/README.md

Navigation bar configuration

On every screen you can use the built-in navigation bar, you can add a title, left button, right button or change navigation bar’s style. All you need to do is pass appropriate params to navigationBar in the route configuration:

import React, { Component } from 'react';
@kastermester
kastermester / es-preset.js
Created October 25, 2016 11:51
Webpack hot reloading of relay schemas
// loaction: loaders/es-preset.js
// This file is a combination of the following babel presets:
// es2015, react, stage-0.
// Difference is that the es2015-template-literals is taken out. Of the es2015 preset.
// This allows us to run relay transformations on the code afterwards (which will then transform any remaining template literals).
module.exports = preset({});
function preset(context, opts) {
var moduleTypes = ["commonjs", "amd", "umd", "systemjs"];
var loose = false;
function transformOrigin(matrix, origin) {
const { x, y, z } = origin;
const translate = MatrixMath.createIdentityMatrix();
MatrixMath.reuseTranslate3dCommand(translate, x, y, z);
MatrixMath.multiplyInto(matrix, translate, matrix);
const untranslate = MatrixMath.createIdentityMatrix();
MatrixMath.reuseTranslate3dCommand(untranslate, -x, -y, -z);
MatrixMath.multiplyInto(matrix, matrix, untranslate);
@reyawn
reyawn / vs-code-icon-names.json
Created October 28, 2016 13:45
Visual Studio Code icon names for shortcuts
[
"alert",
"arrow-down",
"arrow-left",
"arrow-right",
"arrow-small-down",
"arrow-small-left",
"arrow-small-right",
"arrow-small-up",
"arrow-up",
extension AXError: Error { }
// For some reason values don't get described in this enum, so we have to do it manually.
extension AXError: CustomStringConvertible {
fileprivate var valueAsString: String {
switch (self) {
case .success:
return "Success"
case .failure:
return "Failure"
@voodooattack
voodooattack / gql-directives.js
Last active January 5, 2020 09:57
GraphQL-Sequelize auto-model functionality. Directly translates the schema language into database models via directives.
const { parse, visit, print, Kind, BREAK } = require('graphql/language');
const { buildASTSchema } = require('graphql/utilities');
const { addResolveFunctionsToSchema } = require('graphql-tools');
const Sequelize = require('sequelize');
const { graphql } = require('graphql');
const jexl = require('jexl');
const deepAssign = require('deep-assign');
const { resolver: sequelizeResolver } = require('graphql-sequelize');
const { inspect } = require('util');