Skip to content

Instantly share code, notes, and snippets.

@gt3
gt3 / process-components.js
Created December 24, 2016 21:59
Tracks factory function, object literal => component
import {Component, PropTypes} from 'react'
import {beginPolling, putter, endPolling, endPollingAll, tryCloseAll} from './csp-utils'
const goPropKey = '$green'
let _isGreen = ctx => (props = ctx.props) => props[goPropKey] && ctx === props[goPropKey]
let _go = (outlet, mapper) => {
let put = putter(outlet)
return props => put(mapper(props, props[goPropKey])())
}
@gt3
gt3 / alts-timeout.js
Created January 1, 2017 17:34
js-csp timers use case for alts
let csp = require('js-csp')
let START, SHOULD_END, END
const app = () => {
START = +(new Date);
const ch = csp.chan();
csp.go(function* () {
yield csp.timeout(1000);
yield csp.put(ch, 42);
});
let TH = ({value}) => <th >{value}</th>
let TD = ({value}) => <td>{value}</td>
let Row = ({update, children}) => <tr onClick={update}>{children}</tr>
class Printer extends React.Component {
constructor(props) {
super(props)
this.state = {acc: []}
this.update = this.update.bind(this)
this.mult = this.mult.bind(this)
@gt3
gt3 / manual.jsx
Last active January 30, 2017 06:07
let next = it => v => it.next(v).value
function* mult(t) {
let acc = 0
while (true) yield acc = acc + t
}
function* cell(value) {
value = yield (<th key={value}>{value}</th>)
while (true) value = yield (<td key={value}>{value}</td>)
@gt3
gt3 / npm-build-FIXED
Last active February 5, 2017 18:42
js-csp errors on windows
C:\Users\Ankit\Documents\code\js-csp>npm run build
> js-csp@0.9.0 build C:\Users\Ankit\Documents\code\js-csp
> npm run build:node && npm run build:es && npm run build:browser
> js-csp@0.9.0 build:node C:\Users\Ankit\Documents\code\js-csp
> node -e "require('ncp').ncp('./src', './lib')" && cross-env BABEL_ENV=production npm run babel:node
@gt3
gt3 / markdownhere.css
Last active February 23, 2017 19:27 — forked from xiaolai/markdownhere.css
markdown-here-css
.markdown-here-wrapper {
font-size: 16px;
line-height: 1.8em;
letter-spacing: 0.1em;
}
pre, code {
font-size: 14px;
font-family: Roboto, 'Courier New', Consolas, Inconsolata, Courier, monospace;
@gt3
gt3 / presentation.jsx
Last active March 9, 2017 17:42
Temperature Calculator from React official docs
export const scaleNames = { c: 'Celsius', f: 'Fahrenheit' }
export class TemperatureInput extends React.Component {
constructor(props) {
super(props);
this.handleChange = this.handleChange.bind(this);
}
handleChange(e) {
this.props.onChange(e.target.value);
}
@gt3
gt3 / calculator.jsx
Last active March 8, 2017 20:20
Temperature Calculator from React official docs
import { scaleNames, TemperatureInput, BoilingVerdict } from './presentation.jsx'
function toCelsius(fahrenheit) {
return (fahrenheit - 32) * 5 / 9
}
function toFahrenheit(celsius) {
return (celsius * 9 / 5) + 32
}
@gt3
gt3 / calculator-with-chan.jsx
Last active March 20, 2017 14:07
Temperature Calculator with Channels
import { scaleNames, TemperatureInput, BoilingVerdict } from "./presentation.jsx"
import { chan, putAsync } from "js-csp"
import { RenderProcess } from "upcoming-react-csp-framework"
let NA = Symbol("empty")
function sanitize(input) {
let parsed = parseFloat(input), invalid = Number.isNaN(parsed) && NA
return { input, parsed, invalid }
}
@gt3
gt3 / encode-diff.js
Created April 12, 2017 22:07
finds difference in encodeURIComponent and encodeURI allowances
let arr = [], arr2 = []
for(let i=0; i<200; i++)
{
let s = String.fromCharCode(i)
if(s === encodeURIComponent(s)) arr.push(s)
if(s === encodeURI(s)) arr2.push(s)
}
//arr - // !'%()*-.~
console.log(arr.length, arr2.length)