Skip to content

Instantly share code, notes, and snippets.

View mmollaverdi's full-sized avatar

Mehdi Mollaverdi mmollaverdi

  • Melbourne
View GitHub Profile
@mmollaverdi
mmollaverdi / HalJson.scala
Last active August 29, 2015 14:15
Modeling a HAL Resource and providing JSON encoders for that in Scala - using Shapeless Heterogenous lists and Argonaut
// The following, models a HAL Resource based on HAL specification:
// http://stateless.co/hal_specification.html
// And provides Argonaut JSON encoders for that model
// (Argonaut is a purely functional Scala JSON library)
// http://argonaut.io/
import shapeless._
import shapeless.ops.hlist.{ToTraversable, Mapper}
import argonaut._, Argonaut._
///////////////////////////
@mmollaverdi
mmollaverdi / HalResource.scala
Last active September 1, 2015 23:44
Modeling a HAL Resource and providing JSON encoders for that in Scala - using Shapeless Heterogenous lists and Argonaut
// The following, models a HAL Resource based on HAL specification:
// http://stateless.co/hal_specification.html
// And provides Argonaut JSON encoders for that model
// (Argonaut is a purely functional Scala JSON library)
// http://argonaut.io/
import shapeless._
import shapeless.ops.hlist.{ToTraversable, Mapper}
import argonaut._, Argonaut._
import scala.language.existentials
import scala.language.higherKinds
@mmollaverdi
mmollaverdi / 1019739.json
Created March 10, 2015 23:02
Sample agent data in FAA S3 bucket
{
"linkedSalespeopleIds" : [
"1019739"
],
"name" : "Tanya Su",
"emailAddresses" : [
"tanyasu@century21.com.au"
],
"agency" : {
"name" : "Anderson & Co. Century 21 - Carnegie",
@mmollaverdi
mmollaverdi / logged.js
Created April 29, 2016 11:06
Logged HOC
const logged = ComposedComponent => React.createClass({
render() {
console.log(`Rendering ${ComposedComponent.displayName}`);
return <ComposedComponent ...{this.props} />
}
});
export default function featureToggles(state={}, action) {
switch (action.type) {
case Actions.FEATURE_TOGGLES_UPDATED:
return { ...state, ...action.data };
default:
return state;
}
}
Before After
export default function featureToggles(state={}, action) {
  switch (action.type) {
    case Actions.FEATURE_TOGGLES_UPDATED:
      return { ...state, ...action.data };
    default:
      return state;
 }
const initialState = // initial state;
module.exports = (state = initialState, action) => {
switch (action.type) {
case FILTER_UPDATED: // return new state containing the updated filter value
case FILTERS_CLEARED: // return new state reset to initial value
case TAB_SWITCHED: // return new state containing the location filter value from previous tab
case FILTERS_ROUTED: // return new state containing user's most recent location search
case SEARCH_HISTORY_ITEM_SELECTED: // set the state to the selected item from search history
default: return state;
module.exports = {
updateFilters: currentFiltersState => (filterName, filterValue) => // return new filers state containing the updated filter value
clearFilters: currentFiltersState => // return new state reset to initial value
switchTab: currentFiltersState => // return new state containing the location filter value from previous tab
routeFilters: currentFiltersState => mostRecentSearch => // return new state containing user's most recent location search
selectSearchHistory: currentFiltersState => selectedSearchFromHistory => // return selected search item from search history
};
import React from 'react';
import stateTransformers from './searchFormStateTransformers';
import SearchForm from './SearchForm';
module.exports = class SearchFormContainer extends React.Component {
constructor(props) {
super(props);
this.state = // initial state
this.stateUpdaters = {
updateFilters: (filterName, filterValue) =>
const stateUpdaterProvider = stateTransformers => Component => {
class StateUpdaterProvider extends React.Component {
getChildContext() {
return stateTransformers;
}
render() {
return <Component {...this.props} />;
}
}