Skip to content

Instantly share code, notes, and snippets.

View franciscotln's full-sized avatar

Francisco Neto franciscotln

View GitHub Profile
const pipe = (...fns) => {
let [res] = fns;
for (let i = 1, n = fns.length; i < n; i++) res = fns[i](res);
return res;
};
const concat = iter2 => async function* (iter1) {
yield* await iter1;
yield* await iter2;
};
@franciscotln
franciscotln / callbag.js
Last active December 3, 2018 12:54
Setter-setter and setter
const LIMIT = 10000;
let sinkRef, sending, completed, sourceDisposed;
const source = (type, data) => {
if (sourceDisposed || completed) {
return;
}
if (type === 0) {
@franciscotln
franciscotln / mapFirst.js
Last active June 10, 2018 22:24
Function mapFirstN: maps the first N elements found, given a predicate and transformation function
console.clear();
function measure(msg, fn) {
const start = Date.now();
fn();
console.log(msg, Date.now() - start, 'ms');
}
/**
* @description Will look for the first N elements that matches the predicate.
@franciscotln
franciscotln / callbag-create.js
Last active April 12, 2018 13:46
callbag-create
const create = prod => (start, sink) => {
if (start !== 0) return;
if (typeof prod !== 'function') {
sink(0, () => {});
return;
}
let init = got2 = false;
let unsub;
sink(0, t => {
got2 = got2 || t === 2;
@franciscotln
franciscotln / withView.js
Created February 3, 2018 11:44
separated view in react
const AppView = props =>
<div className='App'>
<PeopleList {...props.state} onDelete={props.deletePerson} />
</div>;
class App extends Component {
constructor(props) {
super(props);
import React from 'react';
const ListWrapper = ({ children }) => (
<div className='people-list-wrapper'>
<ul className='people-list'>
{children}
</ul>
</div>
);
@franciscotln
franciscotln / stuff-type.tsx
Created January 30, 2018 00:37
no outside data
import * as React from 'react';
import * as R from 'ramda';
import { connect, Dispatch } from 'react-redux';
import { bindActionCreators } from 'redux';
import { Title } from '../../shared/components/title';
import { StuffTypeItems } from '../../shared/components/subscription-calculator';
import { Button } from '../../shared/components/button';
import { ItemComponent } from './stuff-type/item';
import { setStuffType, SubscriptionCalculatorActions } from '../store/subscription-calculator.actions';
@franciscotln
franciscotln / scripts.js
Created January 29, 2018 23:25
controller factory, event delegation angularJs
angular
.module('myApp', [])
.factory('DataFactory', function DataFactory($q) {
return {
getData() {
return $q.when([
{id: 1, name: 'A'},
{id: 2, name: 'B'},
{id: 3, name: 'C'},
{id: 4, name: 'D'},
@franciscotln
franciscotln / all.elm
Created January 4, 2018 21:47
elixir-JS-elm
// Elixir
data = [
%{ id: 1, value: 0 },
%{ id: 2, value: 0 },
%{ id: 3, value: 0 }
]
Enum.map data, fn item ->
if item.id == 2 do
%{ item | value: item.value + 1 }
@franciscotln
franciscotln / mixins_and_composition.js
Last active February 25, 2017 16:26
mixins and composition
function compose(...fns) {
return arg => fns.reduceRight((prev, curr) => curr(prev), arg);
}
const fatherMixin = (BaseClass = class {}) =>
class Father extends BaseClass {
constructor() {
super()
this.frontendLang = 'JavaScript';
}