Skip to content

Instantly share code, notes, and snippets.

View reaktivo's full-sized avatar
👋

Marcel Miranda Ackerman reaktivo

👋
View GitHub Profile
@reaktivo
reaktivo / useCallbagSubscription.js
Created November 12, 2018 18:06
Callbag Subscription with React Hooks
import { useState, useEffect } from "react";
import { pipe } from "callbag-basics";
import subscribe from "callbag-subscribe";
export default fns => {
const [value, setValue] = useState(null);
useEffect(
() =>
pipe(
...fns,
@reaktivo
reaktivo / Timer.js
Created October 29, 2018 09:04
Playing around with React Hooks + Callbags
import React, { useState, useEffect } from "react";
import { interval, map, pipe, merge } from "callbag-basics";
import subscribe from "callbag-subscribe";
import of from "callbag-of";
const usePipeStream = fns => {
const [value, setValue] = useState(null);
// maybe should use useCallback on the pipe and then run it
useEffect(
@reaktivo
reaktivo / state.js
Created August 29, 2018 15:21
State Ideas
const state = {
// user: {
// isLoggedIn: false,
// email: "",
// password: "",
// details: {
// firstName: "",
// lastName: ""
// }
// },
@reaktivo
reaktivo / ANicerPattern.js
Last active July 20, 2018 14:20
Stateful functional component sketch
import React, { PureComponent } from "react";
import ReactDOM from "react-dom";
import "./styles.css";
const withState = render =>
class extends PureComponent {
state = { value: "xxx" };
onChange = event => this.setState({ value: event.target.value });
render = () => render(this);
};
@reaktivo
reaktivo / usage.js
Last active July 18, 2018 08:04
Render Children with State Handlers
import withStateHandlers from 'withStateHandlers';
const initialState = {
value: '',
}
const handlersFactory = ({ props, state, setState }) => {
return {
setValue(value) {
setState({ value });
@reaktivo
reaktivo / Dimensions.js
Created April 24, 2018 09:02
React Native Dimensions Render Component
import React from 'react';
import PropTypes from 'prop-types';
import { Dimensions as RNDimensions } from 'react-native';
const dimensionsShape = PropTypes.shape({
width: PropTypes.number,
height: PropTypes.number,
});
// eslint-disable-next-line react/prop-types
@reaktivo
reaktivo / validateBsn.js
Created March 29, 2018 15:34
BSN Netherlands validation
export default const validateBsn = (bsn = '') => {
// Needs to be 9 characters
if (bsn.length !== 9) {
return false;
}
const VALUES = [9, 8, 7, 6, 5, 4, 3, 2, -1];
const total = bsn
.split('') // make it an enumerable
.reduce((p, c, i) => Number(p) + c * VALUES[i], 0);
const express = require('express');;
const app = express();
app.get('/first.js', (req, res) => {
setTimeout(() => {
res.send('alert("First script")');
}, 350);
})
app.get('/second.js', (req, res) => {
do (jQuery) ->
$ = jQuery
insertAtCaret = (value) ->
if document.selection # IE
@focus()
sel = document.selection.createRange()
sel.text = value
do (jQuery) ->
$ = jQuery
wrap = (fn) ->
(e) ->
fn e
do e.stopPropagation
do e.preventDefault
false