Skip to content

Instantly share code, notes, and snippets.

View gigobyte's full-sized avatar

Stanislav Iliev gigobyte

  • Sofia, Bulgaria
View GitHub Profile
@connect((store) => ({
moviesWithGosling: store.movies.filter(movie => movie.get('cast').includes(1512))
}))
@connect((store, ownProps) => ({
category: getCategoryById(ownProps.categoryId, store.sports.get('categories')),
matches: filterMatchesByCategoryId(ownProps.categoryId, ownProps.matches)
}))
import React from 'react'
const fetchResources = (mapResourcesToProps) => (ComposedComponent) => {
return class extends React.Component {
static displayName = `Fetch(${ComposedComponent.displayName || ComposedComponent.name})`
render() {
return <ComposedComponent {...this.props} />
}
}
const fetchResources = (mapResourcesToProps) => (ComposedComponent) => {
return class extends React.Component {
static displayName = `Fetch(${ComposedComponent.displayName || ComposedComponent.name})`
state = {}
componentDidMount() {
const mapResult = mapResourcesToProps(this.props)
const resourceProps = Object.keys(mapResult)
const resourcePromises = Object.values(mapResult)
const styleable = (ParentComponent) => class extends ParentComponent {
static displayName = `Styleable(${ParentComponent.displayName || ParentComponent.name})`
}
const styleable = (ParentComponent) => class extends ParentComponent {
static displayName = `Styleable(${ParentComponent.displayName || ParentComponent.name})`
render() {
const originalElement = super.render()
const className = `${originalElement.props.className} ${this.props.className}`
const style = {...originalElement.props.style, ...this.props.style}
const newProps = {...originalElement.props, className, style}
return React.cloneElement(originalElement, newProps)
@styleable
class Example extends React.Component {
render() {
return (
<div className="test" style={{fontSize: 30}}>
Test
</div>
)
}
}
// Separate url validation logic from Replies.sayInvalidLinkedInUrl side effect.
// This way you can reuse this function in other methods
const getUrlFromEvent = (event) => Maybe.of(event)
.filter(x => event.message.nlp.entities.url)
.filter(x => event.message.nlp.entities.url[0].domain !== 'linkedin.com')
.chain(x => Maybe.fromNullable(extract(event.message.nlp.entities.url)))
consume.onUserState('preferences/linkedin/url', ({ event, userId }) => getUrlFromEvent(event)
.caseOf({
Just: (url) => Promise.all([User.updatePreferences(userId, {linkedIn: url[0]}), Dispatch.linkedInUrlReceived({ userId })]),
interface ADTKind<T> {
kind: T
}
type ADT1<Name, T> = (...args: [T]) => ADTContainer1<Name, T>
type ADT2<Name, T, T2> = (...args: [T, T2]) => ADTContainer2<Name, T, T2>
type ADT3<Name, T, T2, T3> = (...args: [T, T2, T3]) => ADTContainer3<Name, T, T2, T3>
class ADTContainer1<Name, T> implements ADTKind<Name> {
kind: Name = null as any as Name
@gigobyte
gigobyte / infix-do-notation.hs
Created January 11, 2019 20:16
Infix vs do notation
headerToUsername :: Text -> Maybe Text
headerToUsername authHeader = do
JWT.stringOrURIToText <$> (JWT.sub =<< JWT.claims <$> JWT.decode authHeader)
headerToUsernameDo :: Text -> Maybe Text
headerToUsernameDo authHeader = do
unverifiedJwt <- JWT.decode authHeader
subject <- JWT.sub $ JWT.claims unverifiedJwt
return $ JWT.stringOrURIToText subject