Skip to content

Instantly share code, notes, and snippets.

View BenjaminVerble's full-sized avatar

Benjamin Verble BenjaminVerble

View GitHub Profile
const pull = require('pull-stream')
const promisePull = require('pull-promise')
const { compose, createStore, applyMiddleware, combineReducers } = require('redux')
const createActorMiddleware = require('redux-pull-actors')
const initialDate = Date.now() - 2000;
function dumbAsync (state = 'hello dumb ajax', action) {
if (action.type === 'ajax_complete') {
return action.payload
const pull = require('pull-stream')
const promisePull = require('pull-promise')
const { compose, createStore, applyMiddleware, combineReducers } = require('redux')
const createActorMiddleware = require('redux-pull-actors')
function dumbAjax (state = 'hello dumb ajax', action) {
if (action.type === 'ajax_complete') {
return action.payload
}
return state
var pull = require('pull-stream')
var log = typeof bin.log === 'function' ? bin.log : console.log;
function promiseThing(text) {
return new Promise(function(resolve, reject){
setTimeout(function(){
if (text.length > 10) {
var e = new Error() // couldn't pass message here in webackbin
e.message = 'text too long'
import pull, { values, asyncMap, collect, map, take } from 'pull-stream'
const concatAfter = (x) => (y) => y + x
const concatXyzAfter = concatAfter('_xyz')
pull(
values(['file1','file2','file3', 'fhqwhgads']),
map(concatXyzAfter),
collect((err, array) => bin.log(array))
)
import pull, { values, asyncMap, collect, map, take } from 'pull-stream'
const concatAfter = (x) => (y) => y + x
const concatXyzAfter = concatAfter('_xyz')
const asyncConcatXyzAfter = (data, cb) => {
setTimeout(() => {
if (typeof data !== 'string' || data.length > 5) return cb(true) // abort here (not a filter)
cb(null, concatXyzAfter(data))
}, 1000)
}
function values(array) { // this function only needed for the counter
var i = 0
return function (abort, cb) {
if (abort) return cb(abort)
if (i >= array.length) {
return cb(true, array[i++])
} else {
return cb(null, array[i++])
}
}
import { createStore } from 'redux'
import { install, loop, Effects } from 'redux-loop'
const isEven = (value) => value % 2 === 0
const firstAction = (payload) => ({
type: 'FIRST_ACTION',
payload
})
@BenjaminVerble
BenjaminVerble / better-nodejs-require-paths.md
Created September 9, 2016 17:27 — forked from branneman/better-nodejs-require-paths.md
Better local require() paths for Node.js

Better local require() paths for Node.js

Problem

When the directory structure of your Node.js application (not library!) has some depth, you end up with a lot of annoying relative paths in your require calls like:

var Article = require('../../../models/article');

Those suck for maintenance and they're ugly.

Possible solutions

/*
warning.js:36Warning: Unknown props `deactivated`, `hover` on <div> tag. Remove these props from the element. For details, see https://fb.me/react-unknown-prop
in div (created by Instyled)
in Instyled (created by RootElement)
in div (created by RootElement)
in RootElement
*/
@BenjaminVerble
BenjaminVerble / index.js
Last active April 26, 2016 17:59
mutable data + observable + react
const react = require('react')
const reactDOM = require('react-dom')
var r = react.createElement
// Data / Actions
let count = 0
let observer = null
function emitChange() {
observer(count);