This file contains 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
config.devServer = { | |
proxy: { | |
//here we declare to proxy all the requests not handled by webpack. I this case everything webpack bundle is in | |
// dist/ and so we don't proxy it to let the webpack dev server handle it | |
'!**/dist/**': { | |
//set the URL of the wordpress site | |
target: 'http://mysite.test', | |
changeOrigin: true, | |
onProxyRes: function(proxyRes, req, res) { | |
if( proxyRes.headers && |
This file contains 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 { Component } from "React"; | |
export var Enhance = ComposedComponent => class extends Component { | |
constructor() { | |
this.state = { data: null }; | |
} | |
componentDidMount() { | |
this.setState({ data: 'Hello' }); | |
} | |
render() { |
This file contains 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
var flattenObject = function(ob) { | |
var toReturn = {}; | |
for (var i in ob) { | |
if (!ob.hasOwnProperty(i)) continue; | |
if ((typeof ob[i]) == 'object') { | |
var flatObject = flattenObject(ob[i]); | |
for (var x in flatObject) { | |
if (!flatObject.hasOwnProperty(x)) continue; |
This file contains 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
// I define the callback function interface for the .map() method. This entire interface | |
// is parameterized with the given Type <T> so that we can facilitate "type argument | |
// inference" in the method signature for .map(). | |
interface TokensMapCallback<T> { | |
( token: string ) : T; | |
} | |
class Tokens { | |
private _tokens: string[]; |
This file contains 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
// I map the current collection onto another collection using the given operator. | |
// Undefined products of the operation will automatically be removed from the final | |
// results (filter value 'undefined' can be overridden). | |
Array.prototype.mapAndFilter = function( | |
operator, | |
valueToFilter = undefined, | |
context = null | |
) { | |
var results = this |
This file contains 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 the core angular services. | |
import { Component } from "@angular/core"; | |
import _ = require( "lodash" ); | |
// Import the application services. | |
import { GridSelection } from "./grid.component"; | |
import { GridSelectionEvent } from "./grid.component"; | |
interface Game { | |
letters: string[][]; |
This file contains 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
// http://paqmind.com/posts/fluent-api-debunked/ | |
var R = require("ramda"); | |
var sales = [ | |
{id: 1, price: "500"}, | |
{id: 2, price: "1500"}, | |
{id: 3, price: "750"}, | |
{id: 4, price: "1750"}, | |
{id: 5, price: "150"}, |
This file contains 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
// the functional programming version | |
const find2 = (f => f(f))(f => | |
(next => (x, y, i = 0) => | |
(i >= x.length) ? null : | |
(x[i] === y) ? i : | |
next(x, y, i+1))((...args) => | |
(f(f))(...args))); | |
let arr = [0, 1, 2, 3]; | |
console.log(find2(arr, 2)); |
This file contains 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
/* | |
Curry(咖喱) 的概念很简单:只传递给函数一部分参数来调用它,让它返回一个函数去处理剩下的参数。 | |
- 柯里化: http://baike.baidu.com/view/2804134.htm | |
- Currying: https://en.wikipedia.org/wiki/Currying | |
- Lodash: https://lodash.com/docs#curry | |
- Lodash-FP:https://github.com/lodash-archive/lodash-fp | |
- Ramda:http://ramdajs.com/ | |
*/ | |
function match(what) { |
This file contains 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
let add = (val, fun) => fun(val + 3); | |
let multiplication = (val) => val * 3; | |
console.log(add(2, multiplication)); | |
//-------------------------------- | |
let test = { | |
a: 10, | |
b: 20, | |
c: 30 | |
}; |