Skip to content

Instantly share code, notes, and snippets.

View hacker0limbo's full-sized avatar
:electron:
Where the fuck I am

Limboer hacker0limbo

:electron:
Where the fuck I am
  • eBay
  • 21:34 (UTC +08:00)
View GitHub Profile
@hacker0limbo
hacker0limbo / .bash_profile
Created September 5, 2019 04:16
.zshrc 和 .bash_profile 备份
#enables colorin the terminal bash shell export
export CLICOLOR=1
#setsup thecolor scheme for list export
export LSCOLORS=gxfxcxdxbxegedabagacad
# lambda prompt
export PS1="\[\e[0;35m\]λ\[\e[m\] \[\e[33;40m\]\@\[\e[m\] \[\e[0;32m\]\W \[\e[m\]"
#sets up theprompt color (currently a green similar to linux terminal)
@hacker0limbo
hacker0limbo / fetch_user_thunk.js
Last active October 20, 2019 13:14
使用 redux-thunk 获取 api 的例子
import { createStore, applyMiddleware } from 'redux'
import thunk from 'redux-thunk'
import axios from 'axios'
// 建立一个 local state 负责 loading
const state = {
loading: false
}
// 这个 action 用于在下面的 fetchUser 里面 dispatch
@hacker0limbo
hacker0limbo / redux-promise-middleware整理.md
Created August 24, 2019 10:33
redux 与异步, 关于 redux-thunk 和 redux-promise-middleware 的整理

redux-promise-middleware 与异步

使用 redux-thunk 时候由于一个请求需要写三个 action, 比较麻烦. redux-promise-middleware 可以在根据 type 自动生成对应的 action, 一个例子如下

action 只需写一个基本的, 对应会生成: FETCH_DATA_PENDING, FETCH_DATA_SUCCESS, FETCH_DATA_REJECTED 三种形式

// action

export const getData = () => {
@hacker0limbo
hacker0limbo / 闭包.md
Created August 24, 2019 05:20
一些概念的总结(前端)

重点:

  • 可以返回一个对象, 或者一个函数
  • 闭包是一个有状态(不消失的私有数据)的函数
  • 闭包是一个有记忆的函数
  • 闭包相当于一个只有一个方法的紧凑对象

示例 1, 非闭包:

// 无论调用多少次 fakeCounter(), 永远返回的是 0 
const fakeCounter = function() {
@hacker0limbo
hacker0limbo / cookie和session小节.md
Created August 22, 2019 12:22
session 和 cookie 模拟
@hacker0limbo
hacker0limbo / readmore_useState.js
Last active August 22, 2019 13:03
使用 useState 实现 readmore 效果
import React, { useState } from 'react'
import ReactDOM from 'react-dom'
const text = 'To see the answers, we need to take a step back. The goal of this article isn’t to give you a list of bullet point recipes. It’s to help you truly “grok” useEffect. There won’t be much to learn. In fact, we’ll spend most of our time unlearning.'
const RevealText = props => {
const { text, maxLength } = props
const [hidden, setHidden] = useState(true)
if (text.length <= maxLength) {
@hacker0limbo
hacker0limbo / quote.md
Last active October 13, 2019 15:47
一些语录

1

面向对象编程的问题是,每个对象都有自己的状态,开发程序时,必须记住当前所有对象的状态。

为了让我们的生活更轻松,最好只有一小部分代码库处理状态,其他代码都是无状态和纯的。实际上,这就是前端的 Redux 库取得巨大成功的主要原因。

-- 《面向对象编程:一万亿美元的错误》

2 React 应该尽量遵守 "有状态的组件没有渲染, 有渲染的组件没有状态" 这一原则, 这句话的意思是:

@hacker0limbo
hacker0limbo / mongodb.md
Last active August 22, 2019 12:33
软件安装的一些操作

mongodb

安装

使用homebrew安装, 安装以后需要配置环境变量, 在.bash_profile.zshrc里面加上export PATH=/usr/local/Cellar/mongodb/4.0.3_1/bin:$PATH, 然后source使文件生效. 同时需要在 root 目录下新建数据目录, 如下:

mkdir -p /data/db
@hacker0limbo
hacker0limbo / useFormInput.js
Created August 17, 2019 19:29
custom hooks from Dan Abramov's speech
const useFormInput = initialValue => {
const [value, setValue] = useState(initialValue)
const handleChange = e => {
setValue(e.target.value)
}
return {
value,
onChange: handleChange
@hacker0limbo
hacker0limbo / counter_react-redux.js
Last active August 22, 2019 13:01
使用 react-redux, redux 实现的计数器
/*
使用 react-redux 实现的计数器
*/
import React from 'react'
import ReactDOM from 'react-dom'
import { connect, Provider } from 'react-redux'
import { createStore } from 'redux'
const mapStateToProps = state => {