Skip to content

Instantly share code, notes, and snippets.

Avatar

Eliseu Monar dos Santos eliseumds

View GitHub Profile
View serverJson.ts
export function serializeServerDataToJsonString(data: Object): string {
const jsonString = JSON.stringify(data);
return jsonString
.replace(/<\/script/gim, '</_escaped_script')
.replace(/<!--/gm, '\\u003C!--')
.replace(new RegExp('\u2028', 'g'), '\\u2028')
.replace(new RegExp('\u2029', 'g'), '\\u2029')
.replace(/\\/g, '\\\\')
.replace(/\n/g, '\\n')
View keybase.md

Keybase proof

I hereby claim:

  • I am eliseumds on github.
  • I am eliseumds (https://keybase.io/eliseumds) on keybase.
  • I have a public key whose fingerprint is A769 D45E 5412 B851 7005 F236 E133 86CB DA8D D9B1

To claim this, I am signing this object:

View FormValueSelector.js
import React, { PureComponent, PropTypes } from 'react';
import { connect } from 'react-redux';
import { formValueSelector } from 'redux-form';
/*
Example usage:
* Get the value of a single form field:
<FormValueSelector fieldName="phone">
View ElementQuery.js
import React, { Component, PropTypes } from 'react';
import ReactDOM from 'react-dom';
import isNumber from 'lodash/isNumber';
import elementResizeDetector from 'element-resize-detector';
let erd;
if (__CLIENT__) {
erd = elementResizeDetector({
strategy: 'scroll'
View getXRange.js
getXrange(data) {
const xRange = this.props.xRange
let max = -Infinity
let min = Infinity
if (xRange.max) {
max = xRange.max
}
if (xRange.min) {
min = xRange.min
if (xRange.pivotNumber) {
@eliseumds
eliseumds / Areadme.md
Last active Aug 29, 2015
Requests manager
View Areadme.md

Some reading before it: https://gist.github.com/eliseumds/8f970d8929e61b981438

How to cancel a bunch of requests?

var requestManager = new RequestManager();
var request1 = myApi.get('/resource1');
var request2 = myApi.get('/resource2');

requestManager.addAll([request1, request2]);
@eliseumds
eliseumds / Areadme.md
Last active Aug 29, 2015
Cached API client with decorator
View Areadme.md

Cached API client with decorator

This approach has some really cool benefits:

  • The API class stays as a small and clean unit
  • Easy to use other caching techniques. Even multiple are supported simultaneously
  • Explicit code

Http Client

@eliseumds
eliseumds / Areadme.md
Last active Aug 29, 2015
Number formatter
View Areadme.md

Number Formatter: how to use

// some pre-made formatters
var myFormatFn = NumberFormatter.PERCENT; // check NumberFormatter.js for more
myFormatFn(0.54122); // '54.1%'
myFormatFn('0.54122'); // '54.1%'

var formatter = new NumberFormatter();
@eliseumds
eliseumds / Areadme.md
Last active Aug 29, 2015
Date formatting
View Areadme.md

Date Formatter: how to use

var formatter = new DateFormatter();

// get a formatting callback(date) -> string
var myChartSettings = {
    tickFormatter: formatter.createCallbackUsing(DateFormatter.FULL_HOUR)
};
You can’t perform that action at this time.