Skip to content

Instantly share code, notes, and snippets.

View gigobyte's full-sized avatar

Stanislav Iliev gigobyte

  • Sofia, Bulgaria
View GitHub Profile
type input = `Card 1: 41 48 83 86 17 | 83 86 6 31 17 9 48 53
Card 2: 13 32 20 16 61 | 61 30 68 82 17 32 24 19
Card 3: 1 21 53 59 44 | 69 82 63 72 16 21 14 1
Card 4: 41 92 73 84 69 | 59 84 76 51 58 5 54 83
Card 5: 87 83 26 28 32 | 88 30 70 12 93 22 82 36
Card 6: 31 18 13 56 72 | 74 77 10 23 35 67 36 11`;
type Split<
Str extends string,
Separator extends string,
// Elm architecture - all data fetching is in the reducer
reducer(state, action) {
if (action === LOCATION_CHANGE && action.payload === '/send-payment') {
return loop(state, Cmd.action(fetchData()))
}
if (action === FETCH_DATA) {
return loop(state, corporateApiCall())
}
@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
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
// 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 })]),
@styleable
class Example extends React.Component {
render() {
return (
<div className="test" style={{fontSize: 30}}>
Test
</div>
)
}
}
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)
const styleable = (ParentComponent) => class extends ParentComponent {
static displayName = `Styleable(${ParentComponent.displayName || ParentComponent.name})`
}
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)
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} />
}
}