Skip to content

Instantly share code, notes, and snippets.

View machadogj's full-sized avatar

Gustavo Machado machadogj

View GitHub Profile
@machadogj
machadogj / home.js
Created May 10, 2018 02:17
State based navigation PoC
import React, { Component, PropTypes} from 'react';
import { View } from 'react-native';
import {
Container,
Title,
Message,
Button
} from '../components';
import { connect } from 'react-redux';
import { actions as mainActions} from '../store/models/main';
@machadogj
machadogj / wrapper.js
Created May 26, 2017 22:27
Why does my component re-render?
// helper for debugging why your (pure) component is re-rendering
const wrapper = (Cmp) => (props) => {
if (wrapper.prevProps) {
console.log('re-rendering', Cmp.name);
Object.keys(props)
.filter(k => wrapper.prevProps[k] !== props[k])
.forEach(k => console.log(k, wrapper.prevProps[k], props[k]));
}
wrapper.prevProps = props;
return <Cmp {...props} />
@machadogj
machadogj / component.js
Created August 22, 2016 19:06
Hacky way to scroll form on keyboard show.
componentWillUnmount() {
registerScrollViewForm.unregister(this.scrollviewForm);
}
_setFormScrollView(scrollView) {
this.scrollview = scrollviewForm;
registerScrollViewForm.register(scrollView);
}
render() {
@machadogj
machadogj / hud.js
Last active August 22, 2016 15:16
Simple in progress (hud) component.
import React, { Component, PropTypes } from 'react';
import {
ActivityIndicator,
StyleSheet,
View
} from 'react-native';
export default class HudComponent extends Component {
static propTypes = {
@machadogj
machadogj / picker.js
Created March 17, 2016 20:18
React native simple picker
"use strict";
import React from "react-native";
let {
StyleSheet,
View,
ScrollView,
PropTypes,
Component,
Text
@machadogj
machadogj / server.js
Created November 8, 2013 18:49
Express error handling
var express = require('express');
var app = express();
app.get('/', function (req, res, next) {
next({ status: 403, message: 'this is forbidden'});
});
app.use(function (err, req, res, next) {
res.send(err.status || 500, err.message || "something broke");
});
@machadogj
machadogj / users.coffee
Created August 16, 2013 13:22
Example of global scope being a problem when code is converted from js.
###
Include database config.
@var [Object] db
@api private
###
###
Set users collection
@machadogj
machadogj / MyClass.js
Created April 5, 2013 20:59
Sample code for understanding error handling in node.js.
var util = require('util'),
EventEmitter = require('events').EventEmitter;
var MyClass = function () {
if (!(this instanceof MyClass)) return new MyClass();
EventEmitter.call(this);
};
@machadogj
machadogj / -n 100 -c 1
Created November 2, 2012 20:19
Express App Load Tests
PS D:\apache\bin> .\ab.exe -n 100 http://one.org:3000/
This is ApacheBench, Version 2.3 <$Revision: 1373084 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking one.org (be patient).....done
Server Software:
Server Hostname: one.org
@machadogj
machadogj / server.js
Created September 26, 2012 17:27
HTTPS With SNI not working on IE9
var https = require('https');
var fs = require('fs');
var crypto = require("crypto");
var options = {
SNICallback: function (hostname) {
console.log('hostname: ' + hostname);
return crypto.createCredentials({
key: fs.readFileSync('default.key'),
cert: fs.readFileSync('default.crt')