This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// getComponent is a function that returns a promise for a component | |
// It will not be called until the first mount | |
function asyncComponent(getComponent) { | |
return class AsyncComponent extends React.Component { | |
static Component = null; | |
state = { Component: AsyncComponent.Component }; | |
componentWillMount() { | |
if (!this.state.Component) { | |
getComponent().then(Component => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function* getFibonacci() { | |
yield a = 0; | |
b = 1; | |
while (true) { | |
yield b; | |
b = a + b; | |
a = b - a; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default (VideoComponent) => { | |
return class extends VideoComponent { | |
constructor(props) { | |
super(props); | |
this.displayConnectInstruction = this.displayConnectInstruction.bind(this); | |
this.handleCloseModal = this.handleCloseModal.bind(this); | |
} | |
displayConnectInstruction() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { compose, mapObjIndexed, values } from 'ramda'; | |
export const denormalize = compose( | |
values, | |
mapObjIndexed((val, key) => ({ ...val, id: key })) | |
); | |
//the ramda part might be confusing at first glance. `mapObjIndexed` | |
// let's me access the object key and stuff it in the object itself, and | |
// `values` drops all keys and converts it to an array. `compose` runs both those functions from right to left. | |
// `ramda` curries by default, so after i build the function all i need to do is pass it data |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
typealias function = (String) -> String | |
let someProperty: function = {(value: String) -> String in | |
// create a default value for someProperty inside this closure | |
// someValue must be of the same type as SomeType | |
return value | |
} | |
print(someProperty("abiodun")) | |
// This can be refactored to this |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { _ } from 'underscore' | |
import { classify } from 'underscore.string' | |
String.prototype.lowercaseFirstLetter = function () { | |
return this.charAt(0).toLowerCase() + this.slice(1); | |
}; | |
function delegate(model, delegations = []) { | |
delegations.forEach(delegation => { | |
let classifyProperty = classify(delegation.property); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import AsyncComponent from './AsyncComponent'; | |
import scheduleLoad from './loader'; | |
const loader = (cb) => { | |
require.ensure([], (require) => { | |
cb(require('./BarChart')) | |
}); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns reduxish.state-tools | |
(:require-macros [cljs.core.async.macros :refer [go go-loop]]) | |
(:require [cljs.core.async.impl.protocols :refer [WritePort ReadPort]] | |
[cljs.core.async :refer [<!]])) | |
(defn channel? [ch] | |
(and (satisfies? WritePort ch) (satisfies? ReadPort ch))) | |
(defn dispatch! [reducer state value] | |
(println value) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
setattr(socket._socketobject, 'x', 'someting') | |
socket = socket.socket() | |
print socket.x | |
print(type(socket)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UpdateRoleForm from './updateRoleForm'; | |
const mapStateToprops = (state, ownProps) => { | |
return { | |
initialValues: ownProps.role, | |
form:`update_role_form${(ownProps.role.id).toString()}` | |
} | |
} | |
const mapDispatchToProps = (dispatch) => { | |
return { | |
serviceUpdateRole: (data, resolve, reject) => { |