Skip to content

Instantly share code, notes, and snippets.

View ahonn's full-sized avatar
🐵
Happy Hacking

Yuexun ahonn

🐵
Happy Hacking
View GitHub Profile
@ahonn
ahonn / clean_weibo.js
Last active September 11, 2017 08:32
Tampermonke script for clean all weibo
// ==UserScript==
// @name clean weibo
// @namespace http://www.ahonn.me/
// @version 1.0
// @description Tampermonke script for clean all weibo
// @author ahonn
// @match http://weibo.com/p/*
// @grant none
// ==/UserScript==
@ahonn
ahonn / reagent-ref-functions.clj
Created September 30, 2017 15:57 — forked from pesterhazy/reagent-ref-functions.clj
Using ref functions with reagent
;; React supports "refs" as a way for a component to get a
;; handle to its children. Classically, refs were string-based.
;; Recent versions of React support callback attributes as a
;; more elegant variant of accessing DOM notes or components.
;;
;; This example uses a Form-3 component as per
;; https://github.com/Day8/re-frame/wiki/Creating-Reagent-Components
;;
;; For callback refs, see React's documentation
;; https://facebook.github.io/react/docs/more-about-refs.html
for i in range(65,90) + range(97,122)
let c = nr2char(i)
exec "map \e".c." <M-".c.">"
exec "map! \e".c." <M-".c.">"
endfor
let g:ale_sign_error = '✖'
hi! ALEErrorSign guifg=#DF8C8C ctermfg=167
let g:ale_sign_warning = '⚠'
hi! ALEWarningSign guifg=#F2C38F ctermfg=221
@ahonn
ahonn / neovim-term.vim
Created March 20, 2019 02:24
neovim term
if has('nvim')
augroup vimrc_term
autocmd!
autocmd WinEnter term://* nohlsearch
autocmd WinEnter term://* startinsert
autocmd TermOpen * tnoremap <buffer> <C-h> <C-\><C-n><C-w>h
autocmd TermOpen * tnoremap <buffer> <C-j> <C-\><C-n><C-w>j
autocmd TermOpen * tnoremap <buffer> <C-k> <C-\><C-n><C-w>k
autocmd TermOpen * tnoremap <buffer> <C-l> <C-\><C-n><C-w>l
clipboard = hs.chooser.new(function (choice)
if choice then
hs.pasteboard.setContents(choice.content)
hs.eventtap.keyStroke({ "cmd" }, "v")
end
end)
local history = {}
function addHistoryFromPasteboard()
local contentTypes = hs.pasteboard.contentTypes()
@ahonn
ahonn / JavScript new.js
Last active September 25, 2019 10:09
implement the `new` keyword
function myNew(constructor, ...args) {
const self = {};
self.__proto__ = constructor.prototype;
const obj = constructor.apply(self, args);
// 构造函数返回对象或者函数时,直接返回
if (typeof obj === 'object' || typeof obj === 'function') {
return obj;
}
return self;
}
@ahonn
ahonn / JavaScript deepClone.js
Last active September 25, 2019 10:09
implement object deep clone
function deepClone(source, hash = new WeakMap()) {
if (source === null || typeof source !== 'object') {
return source;
}
if (source instanceof Date) {
return new Date(source);
}
if (source instanceof RegExp) {
return new RegExp(source);
}
Function.prototype.bind = function (ctx) {
var self = this;
var nativeSlice = Array.prototype.slice;
var args = nativeSlice.call(arguments, 1);
return function () {
var bindArgs = args.concat(nativeSlice.call(arguments));
return self.apply(ctx, bindArgs);
}
}
const onPlotClick = (event) => {
const { data } = event;
if (data) {
const { category } = data.point;
if (category !== query.category) {
setTimeout(() => {
const geom = _.first(chartRef.current.get('geoms'));
const item = geom.get('data').find(_.propEq('category', category));
geom.setSelected(item);