Skip to content

Instantly share code, notes, and snippets.

Avatar

Rodrigo Ribeiro rodrigopr

View GitHub Profile
View gist:39feb18b34ce1819f07475d55d231c5d
{
profileheader: {
condition: (cur, last) => cur.pid !== last.pid || cur.timestamp > last.timestamp + 15
},
time: {
condition: (cur, last) => cur.timestamp.day != last.timestamp.day
},
time: {
condition: (cur, last) => last.id == profile.lastRead
}
View trace.output
test.js:5
5: const dontWork = <WrappedExample name={123} />; // it start working if we uncomment the line in the other file
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ React element `WrappedExample`
5: const dontWork = <WrappedExample name={123} />; // it start working if we uncomment the line in the other file
^^^ number. This type is incompatible with
6: type ExampleProps = { name: string };
^^^^^^ string. See: container.js:6
Trace:
* path 1:
5: const dontWork = <WrappedExample name={123} />; // it start working if we uncomment the line in the other file
View typed.createRelayContainer.js
// @flow
/* eslint-disable jsx-control-statements/jsx-jcs-no-undef, no-unused-vars */
import React from 'react';
import Relay from 'react-relay';
/*
* Type mapping:
* D - DefaultProps
View deepShallow.js
import { shallow } from 'enzyme';
const deepShallow = (endCondition) => (element) => {
let wrapper = shallow(element);
while (wrapper.node && !endCondition(wrapper)) {
wrapper = wrapper.shallow();
}
return wrapper;
}
@rodrigopr
rodrigopr / Link.react-test.js
Last active Aug 10, 2016
snapshot testing with enzyme (hack)
View Link.react-test.js
View relay-fetch.js
import _ from 'lodash';
import React from 'react';
import Relay from 'react-relay';
import RelayQuery from 'react-relay/lib/RelayQuery';
import GraphQLStoreQueryResolver from 'react-relay/lib/GraphQLStoreQueryResolver'
import RelayFragmentPointer from 'react-relay/lib/RelayFragmentPointer';
import RelayMetaRoute from 'react-relay/lib/RelayMetaRoute';
class DummyComponent extends React.Component {
render() {
View 0-relay-extract-deep-selections.js
function getFieldList(context, asts = context.fieldASTs) {
//for recursion...Fragments doesn't have many sets...
if (!Array.isArray(asts)) asts = [asts]
//get all selectionSets
var selections = asts.reduce((selections, source) => {
if(source.selectionSet) {
selections.push(...source.selectionSet.selections);
}
@rodrigopr
rodrigopr / gist:414e5311fb7ddb70effa
Last active Aug 29, 2015
Flask installable module draft
View gist:414e5311fb7ddb70effa
class Resource(object):
def __init__(self, path, type): ...
def install(self, destination_map): ...
class ExModule(FlaskModule):
@property
def blueprints(self):
return [app, admin]
@property
View HttpxToHttpFilter.scala
import com.twitter.finagle.{Filter, Service}
import com.twitter.finagle.http.{Request HttpRequest, Response HttpResponse}
import com.twitter.util.Future
import io.finch.{HttpRequest HttpxRequest, HttpResponse HttpxResponse}
import org.jboss.netty.handler.codec.http.{HttpResponse NettyHttpResponse}
/**
* Convert from finagle new `Httpx` to the `Http` representation
*
* This is required to make `httpx` services compatible
View ex.scala
class FormatEncoder[Encoder <: EncodeResponse[_]] {
def encoder[A]: Encoder[A] = implicitly[Encoder[A]] // implicit encode must be in scope =/
}
class Formats(encoders: (String, FormatEncoder[_])*, defaultFormat: String) {
private val formatsHash = encoders.toMap
private val default = formatsHash(defaultFormat)
def encodeFor[A](httpReq: HttpRequest): EncodeResponse[A] = formatsHash.getOrElse(???, default).encoder[A]
}