Skip to content

Instantly share code, notes, and snippets.

View abiodun0's full-sized avatar

Abiodun abiodun0

View GitHub Profile
@abiodun0
abiodun0 / asyncComponent.js
Last active October 7, 2016 01:26
React Async Component
// 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 => {
@abiodun0
abiodun0 / finbocci.js
Last active February 8, 2017 10:28
Generators in python and javascript
function* getFibonacci() {
yield a = 0;
b = 1;
while (true) {
yield b;
b = a + b;
a = b - a;
}
}
@abiodun0
abiodun0 / BaseComponent.jsx
Created October 12, 2016 11:28
React Higher Order Inverse Component
export default (VideoComponent) => {
return class extends VideoComponent {
constructor(props) {
super(props);
this.displayConnectInstruction = this.displayConnectInstruction.bind(this);
this.handleCloseModal = this.handleCloseModal.bind(this);
}
displayConnectInstruction() {
@abiodun0
abiodun0 / decompose.js
Last active June 21, 2017 22:22
Denormalize with ramda and redux state
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
@abiodun0
abiodun0 / just_testing.swift
Last active October 13, 2016 01:46
type Alias function with closure callback in swift
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
@abiodun0
abiodun0 / BaseModel.js
Created October 13, 2016 18:45
Normalizing user data with classess.. Needs refactoring
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);
@abiodun0
abiodun0 / BarAsyncChat.js
Created October 15, 2016 05:08
Progressive web app idea
import React from 'react';
import AsyncComponent from './AsyncComponent';
import scheduleLoad from './loader';
const loader = (cb) => {
require.ensure([], (require) => {
cb(require('./BarChart'))
});
}
@abiodun0
abiodun0 / redux-ish.clj
Created October 17, 2016 10:48 — forked from nhusher/redux-ish.clj
Redux with basically no effort in clojurescript, plus core.async to handle asynchronous actions
(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)
@abiodun0
abiodun0 / socket_set_attr.py
Created October 26, 2016 12:49
set attribut with socket.io
import socket
setattr(socket._socketobject, 'x', 'someting')
socket = socket.socket()
print socket.x
print(type(socket))
@abiodun0
abiodun0 / connectRoleForm.js
Created October 27, 2016 15:12
Beauty of Compose
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) => {