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
  • 20:12 (UTC +08:00)
View GitHub Profile
@hacker0limbo
hacker0limbo / goto-sublime
Created December 25, 2021 23:13 — forked from kendellfab/goto-sublime
Add mouse click `goto definition` in sublime text 3.
Linux - create "Default (Linux).sublime-mousemap" in ~/.config/sublime-text-3/Packages/User
Mac - create "Default (OSX).sublime-mousemap" in ~/Library/Application Support/Sublime Text 3/Packages/User
Win - create "Default (Windows).sublime-mousemap" in %appdata%\Sublime Text 3\Packages\User
[
{
"button": "button1",
"count": 1,
"modifiers": ["ctrl"],
"press_command": "drag_select",
@hacker0limbo
hacker0limbo / nested-reducers.js
Created September 20, 2021 16:16 — forked from sergiodxa/nested-reducers.js
An example of how to use nested reducers in Redux
import { combineReducers, createStore } from 'redux';
function discussionsList(state = {}, { type, payload} = {}) {
if (type === 'ADD') {
return {
...state,
[payload.id]: {
id: payload.id,
author: payload.author.id,
content: payload.content,
@hacker0limbo
hacker0limbo / redux-actions.ts
Created November 1, 2020 14:55 — forked from milankorsos/redux-actions.ts
Correct TypeScript typing example for Redux Thunk actions
import {Action, ActionCreator, Dispatch} from 'redux';
import {ThunkAction} from 'redux-thunk';
// Redux action
const reduxAction: ActionCreator<Action> = (text: string) => {
return {
type: SET_TEXT,
text
};
};
@hacker0limbo
hacker0limbo / expand-collapse.user.js
Created September 27, 2020 10:53 — forked from Jaace/expand-collapse.user.js
TamperMonkey Script: Gist expand / collapse files.
// Add a button to Collapse or Expand files in a Github Gist
//
// Install Tampermonkey and add this as a script
// ==UserScript==
// @name Github Gists: Expand / Collapse Files
// @namespace https://gist.github.com/Jaace/7b70d2bb19af63e10b144ed7d867eae0
// @version 0.1
// @description Add a button to expand or collapse files in github gists
// @author Jason Boyle
[
{ "keys": ["ctrl+w"], "command": "delete_word", "args": { "forward": false, "sub_words": true } },
{ "keys": ["ctrl+u"], "command": "run_macro_file", "args": {"file": "res://Packages/Default/Delete to Hard BOL.sublime-macro"} }
]

[x] 字节

  • 京东
@hacker0limbo
hacker0limbo / emacs_hammerspoon.lua
Created June 29, 2020 02:24 — forked from justintanner/emacs_hammerspoon.lua
Emacs Hammerspoon Script
--- Emacs Hammerspoon Script
-- Author: Justin Tanner
-- Email: work@jwtanner.com
-- License: MIT
--- What does this thing do?
-- Allows you to have Emacs *like* keybindings in apps other than Emacs.
-- You can use Ctrl-Space to mark and cut text just like Emacs. Also enables Emacs prefix keys such as Ctrl-xs (save).
--- Installation
@hacker0limbo
hacker0limbo / react-redux.js
Last active February 15, 2020 05:09
react redux 模拟实现
export const name = 'react-redux'
@hacker0limbo
hacker0limbo / 闭包思考.md
Last active June 12, 2020 16:32
关于闭包的一些思考

每个函数创建的时候, 就会创建一个词法作用域, 当在运行的时候, 创建一个新的词法环境(*注意, 这个词法环境还是要从函数定义的时候开始找, 不过在这个时候函数被定义的词法环境也是有可能改变的*), 这两个作用与很有可能是不同的. 所以分析的时候一定是要看最新的作用域

词法环境包括自己内部的环境, 和引用的外部的环境. 当存在嵌套函数的时候, 外部环境可能还引用更加外部的环境, 就形成了一条作用域链. 最最里层的函数在执行的时候, 会根据这条链子, 由内而外寻找需要的变量. 然后可以对找到的变量进行修改, 修改是在该变量所在的作用域内修改, 也就是说对于闭包来讲, 修改的地方在该函数的外部环境修改, 而非克隆一份放低自己的内部环境内修改

普通(纯)函数是没有状态的, 闭包可以使得函数有状态, 有状态就意味着有记忆, 毕竟状态可以发生改变. 当然, 这里的状态, 不在函数内部, 而是在函数外部, 不过函数可以读取到

有了闭包就可以模拟类的一些效果, 闭包和类都是保存状态用的

每次调用一个函数, 如果这个函数存在闭包, 那么都会创建一个单独的闭包环境, 里面有该闭包的状态. 多次调用这个函数, 会创建多个闭包, 这些闭包内部的环境状态都是独立的. 类似于有一个类, 你可以进行多次实例化, 每次实例化出来的都是不同的对象

@hacker0limbo
hacker0limbo / hook 和 class 中 state 与 props 差异.md
Created September 25, 2019 10:22
关于 useEffect, class 组件, 函数组件里 state, props 的一些笔记

两个计数器代码:

使用 class:

import React, {Component} from "react";
import ReactDOM from "react-dom";

class Example extends Component {
  state = {
 count: 0