Skip to content

Instantly share code, notes, and snippets.

@monkindey
monkindey / getter.js
Created August 16, 2017 02:47
getter just like vue computed property
import React, { Component } from 'react';
import ReactDOM from 'react-dom';
class Getter extends Component {
firstAndLastName() {
return `${this.props.firstName} ${this.props.lastName}`;
}
get fullName() {
return `${this.props.firstName} ${this.props.lastName}`;
@monkindey
monkindey / inject.js
Last active August 16, 2017 02:39
React higher-order component
import React, { Component, cloneElement } from 'react';
import ReactDOM from 'react-dom';
const injectRender = Decorated => {
class Inject extends Decorated {
render() {
const renderElement = super.render();
const children = React.Children
.map(renderElement.props.children, child => {
if (typeof child === 'string') {
@monkindey
monkindey / engine.js
Created August 5, 2017 08:06
How to customize your view engine with express
app.set('view engine', 'html');
app.engine('html', require('ejs').renderFile);
@monkindey
monkindey / diao.js
Created July 30, 2017 14:39
utf-8 buffer gbk
const iconv = require('iconv-lite');
const diaoEn = 'diao';
const diao = '很屌';
const diaoUTFBuf = Buffer.from(diao);
// 用utf-8编码的很屌, 然后用gbk去解码, 导致乱码了
const decoded = iconv.decode(diaoUTFBuf, 'gbk');
// mojibake(乱码)
去追一个高产的人的所有repo, 你会发现很多好玩的东西。
他们的解决思路总是让你意想不到, 所以分开去追吧, 然后把在开源世界学习的东西反馈到业务上。
@monkindey
monkindey / inversion.c
Created December 9, 2014 07:42
逆序对(树状数组)
/**
* @author monkindey
* @date 2014.11.27
* @description 用树状数组实现逆序对
* @idea {
* 数组离散化
* 离散化数组进行树状数组操作
* }
*/
#include <stdio.h>
@monkindey
monkindey / the_smallest_n_elements.c
Created December 9, 2014 07:41
序列和的前n小元素(二叉堆)
/**
* @author monkindey
* @date 2014.11.25
* @description 序列和的前n小元素
*/
#include <stdio.h>
#include <malloc.h>
int rows[3], columns[3];
int main() {
@monkindey
monkindey / the_closet_value.c
Created December 9, 2014 07:37
最接近的数(双向链表)
/**
* @author monkindey
* @date 2014.11.24
* @idea {
* 1. 给A数组排序(快排)
* 2. 从小到大顺序构造双向链表
* }
*/
#include <stdio.h>
@monkindey
monkindey / code_resume.js
Last active August 29, 2015 14:09
code self-introduction
/**
* @author: monkindey
* @date: 2014-11-15
* @descripion: 用面向对象的代码来介绍自己
*/
! function() {
// HELPER
function extend(sup, overrides) {
var sub = overrides && overrides.constructor || function() {
sup.apply(this, arguments);
@monkindey
monkindey / client_offset_scroll.js
Last active August 29, 2015 14:06
offsetheight clientheight scrollheight区别
/**
* @author monkindey
* @date 2014-09-23
* @reference http://stackoverflow.com/questions/22675126/
* what-is-offsetheight-clientheight-scrollheight
*/
var $id = function(id){
return document.getElementById(id);
};
var box = $id('box');