Skip to content

Instantly share code, notes, and snippets.

Rodrigo Navarro reu

Block or report user

Report or block reu

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View immutable-example.rb
Person = Immutable.new(:name, :age)
p1 = Person.new(name: "Sasha", age: 30) # <Person @name="Sasha", @age=30>
p2 = p1.with_name("Tori") # <Person @name="Tori", @age=30>
p3 = p2.update(name: "Craudio", age: 10) # <Person @name="Craudio", @age=10>
Person.new(name: "Sasha").with_age(30).with_name { |name| "#{name} Grey" } # <Person @name="Sasha Grey", @age=30>
@reu
reu / proxy.js
Created Mar 22, 2019
Simple HTTP proxy
View proxy.js
const http = require("http");
const { PORT, PROXY_HOST, PROXY_PORT } = process.env;
http
.createServer((req, res) => {
const proxyRequest = http
.request({
hostname: PROXY_HOST,
port: PROXY_PORT || 80,
@reu
reu / example.js
Last active Nov 8, 2018
HTML builder DSL
View example.js
import { h1, div, p } from "./html";
div([
h1({ class: "title" }, "Title"),
p("A nice text"),
]);
View simple-permanent-redirect.js
const http = require("http");
const path = require("path");
const target = process.env.TARGET; // ex: google.com
const port = process.env.PORT || 80;
http
.createServer(({ url, headers }, res) => {
const protocol = headers["x-forwarded-proto"] || "http";
res.writeHead(308, { Location: `${protocol}://${path.join(target, url)}` });
View hackish-url-parser.js
// @flow
import {
always,
memoize,
pick,
} from "ramda";
type ParsedURL = {
protocol: string,
View batch-map.js
const { curry, splitEvery } = require("ramda");
const batchMap = curry((batchSize, fn, list) =>
splitEvery(batchSize, list)
.map(batch => all => Promise.all(batch.map(fn)).then(res => all.concat(res)))
.reduce((results, batch) => results.then(batch), Promise.resolve([]))
);
module.exports = batchMap;
View collapsable.js
import React, {
Component,
PropTypes,
} from "react";
import {
Animated,
View,
} from "react-native";
View mkdirp.js
const fs = require("fs");
const path = require("path");
const promisify = fn => (...args) =>
new Promise((resolve, reject) =>
fn(...args, (err, res) => err === null ? resolve(res) : reject(err))
);
const mkdir = promisify(fs.mkdir);
const stat = promisify(fs.stat);
@reu
reu / farfetch-graphql.js
Last active Mar 3, 2017
Farfetch GraphQL fragments plugin
View farfetch-graphql.js
const graphQLFragments = (fragments = {}) => req => {
const uniq = list => list.filter(value => list.indexOf(value) == list.lastIndexOf(value));
const hasFragment = graphQL => graphQL.match(/\.{3}\s*([A-Za-z0-9\_]+)/g) != null;
const findFragments = graphQL =>
graphQL
.match(/\.{3}\s*([A-Za-z0-9\_]+)/g)
.map(fragment => fragment.trim().replace(/^\.{3}/, ""))
.filter(fragment => fragment.match(/\s+on\s+/) == null)
.map(fragment => {
if (fragment in fragments) {
@reu
reu / cpf.js
Created May 9, 2016
CPF validator JS
View cpf.js
"use strict";
const blackList = [
"00000000000",
"11111111111",
"22222222222",
"33333333333",
"44444444444",
"55555555555",
"66666666666",
You can’t perform that action at this time.