Skip to content

Instantly share code, notes, and snippets.

View chemzqm's full-sized avatar
🇨🇳
Focusing

Qiming zhao chemzqm

🇨🇳
Focusing
View GitHub Profile
@chemzqm
chemzqm / defineProperty.js
Created November 3, 2015 08:37
Object.defineProperty
// ES 15.2.3.6 Object.defineProperty ( O, P, Attributes )
// Partial support for most common case - getters, setters, and values
!(function() {
if (!Object.defineProperty ||
!(function () { try { Object.defineProperty({}, 'x', {}); return true; } catch (e) { return false; } } ())) {
var orig = Object.defineProperty;
Object.defineProperty = function (o, prop, desc) {
// In IE8 try built-in implementation for defining properties on DOM prototypes.
if (orig) { try { return orig(o, prop, desc); } catch (e) {} }
@chemzqm
chemzqm / _doc.fish
Last active December 7, 2015 06:33
快速编辑 npm 模块, 支持 browser 属性
function doc
set folder (moduledir $argv[1])
if test $status != 0
return $status
end
if test -f $folder/Readme.md
open $folder/Readme.md
else if test -f $folder/readme.md
open $folder/readme.md
else if test -f $folder/README.md
@chemzqm
chemzqm / .vimrc
Last active December 11, 2015 04:01
function! PreviewModule(name, ...)
if empty(a:name) | echo "need module name" | return | endif
if empty(a:000)
let res = system("findmodule ".a:name)
let file = res
else
let type = a:000[0]
let res = system("moduledir ".a:name)
if type ==? 'doc'
let file = res . "/readme.md"
@chemzqm
chemzqm / dependencies
Last active December 11, 2015 06:58
配置 unite-js-func 这些配置实现了通过 :F(a/t/r/e/m) name 快速查找函数的功能
#!/usr/bin/env node
var fs = require('fs')
var path = require('path')
var moduleName = process.argv[2]
var dir = process.cwd()
function exit(msg, code) {
console.error(msg)
process.exit(1)
@chemzqm
chemzqm / comment.vim
Created December 16, 2015 10:25
A perfect comment vim plugin
" ============================================================================
" Description: An easy comment plugin
" Author: Qiming Zhao <chemzqm@gmail.com>
" Licence: Vim licence
" Version: 0.1
" ============================================================================
"let g:comment_debug = 1
if exists("g:comment_loaded") && !exists("g:comment_debug")
finish
endif
" toggle unite, quickfix list and location list
if exists("g:loaded_toggle_list")
finish
endif
let g:loaded_toggle_list = 1
function! s:GetBufferList()
redir =>buflist
silent! ls
" Jump previous/next according to existence of unite, quickfix list, location list
" make sure only one list is opening
function! s:Filter(name)
return a:name =~# '\v\[(Location List|Quickfix List)\]'
endfunction
function! s:GetBuffer()
redir =>buflist
silent! ls
@chemzqm
chemzqm / quickfix.vim
Created December 19, 2015 10:58
Unite quickfix
scriptencoding utf-8
function! unite#sources#quickfix#define()
return s:source
endfunction
let s:source = {
\ "name" : "quickfix",
\ "description" : "output quickfix",
\ "syntax" : "uniteSource__Quickfix",
@chemzqm
chemzqm / location_list.vim
Last active December 19, 2015 15:51
location_list for unite
scriptencoding utf-8
function! unite#sources#location_list#define()
return s:source
endfunction
let s:source = {
\ "name" : "location_list",
\ "description" : "output location_list",
\ "syntax" : "uniteSource__LocationList",
@chemzqm
chemzqm / grepprg.sh
Created December 20, 2015 10:13
git grep with column and new files
#! /bin/bash
git --no-pager grep --no-color --no-index --exclude-standard -n $1 | while read git_grep; do
file_and_line=$(echo "$git_grep" | cut -d : -f 1,2)
match=$(echo "$git_grep" | sed 's/[^:]*:[^:]*:\(.*\)/\1/')
column=$(echo "$match" | awk "{print index(\$0, \"$1\")}")
echo "$file_and_line:$column:$match"
done