Skip to content

Instantly share code, notes, and snippets.

View nonsensecreativity's full-sized avatar

Hermanto Lim nonsensecreativity

View GitHub Profile
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 &&
@nonsensecreativity
nonsensecreativity / Enhance.js
Created June 12, 2017 10:02 — forked from sebmarkbage/Enhance.js
Higher-order Components
import { Component } from "React";
export var Enhance = ComposedComponent => class extends Component {
constructor() {
this.state = { data: null };
}
componentDidMount() {
this.setState({ data: 'Hello' });
}
render() {
@nonsensecreativity
nonsensecreativity / Object Flatten
Created June 12, 2017 10:03 — forked from penguinboy/Object Flatten
Flatten javascript objects into a single-depth object
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;
@nonsensecreativity
nonsensecreativity / map.ts
Created June 12, 2017 10:04 — forked from bennadel/map.ts
Using Type Argument Inference When Accepting Generic Callbacks In TypeScript And Node.js
// 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[];
@nonsensecreativity
nonsensecreativity / filter.js
Created June 12, 2017 10:06 — forked from bennadel/filter.js
I Wish JavaScript Had A Way To Map And Filter Arrays In A Single Operation
// 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
@nonsensecreativity
nonsensecreativity / app.component.ts
Created June 12, 2017 10:07 — forked from bennadel/app.component.ts
Attempted Regular Expression Pattern Search Game For RegEx Day 2017 Using Angular 4.1.3
// 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[][];
// 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"},
@nonsensecreativity
nonsensecreativity / functional.js
Created June 12, 2017 10:17 — forked from wuliupo/functional.js
Functional programming
// 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));
@nonsensecreativity
nonsensecreativity / curry.js
Created June 12, 2017 10:19 — forked from wuliupo/curry.js
Currying-柯里化
/*
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) {
@nonsensecreativity
nonsensecreativity / monad example
Created June 12, 2017 10:20 — forked from duncan60/monad example
functional programming
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
};