Skip to content

Instantly share code, notes, and snippets.

View dyng's full-sized avatar
🤔
I think

Ye Ding dyng

🤔
I think
  • Shanghai
  • 09:19 (UTC +08:00)
View GitHub Profile
@dyng
dyng / gist:3904747
Created October 17, 2012 09:53
create file from script with inline content
cat > path/to/outfile <<DELIM # DELIM can be any delimiter
hello line 1
hello line 2
bye
DELIM
@dyng
dyng / sprymap.html
Created November 12, 2012 09:15
Click and Drag
<div class="mappy" style="overflow: hidden; width: 800px; height: 400px; position: relative; cursor: auto;">
<img id="worldMap" alt="A map of the world." src="map.jpg" style="position: absolute; left: -141px; top: -272px;">
</div>
@dyng
dyng / gist:4199450
Created December 4, 2012 00:42
vim光标位置的备份和恢复
(line_bak, col_bak) = (vim.eval("line('.')"), vim.eval("col('.')"))
"""
do something
"""
vim.command("call cursor('{0}', '{1}')".format(line_bak, col_bak))
@dyng
dyng / gist:4215016
Created December 5, 2012 12:03
通过绝对路径import模块
def import_path(fullpath):
"""
Import a file with full path specification. Allows one to
import from anywhere, something __import__ does not do.
"""
path, filename = os.path.split(fullpath)
filename, ext = os.path.splitext(filename)
sys.path.append(path)
module = __import__(filename)
reload(module) # Might be out of date
@dyng
dyng / gist:4233046
Created December 7, 2012 12:48
把多个input框的内容拼接成一条字符串
var serial_code = $("#serial-code-input>input").map(function(){
return this.value;
}).get().join('');
@dyng
dyng / gist:4265896
Created December 12, 2012 07:49
比较两个json是否等价(perl版)
#! /usr/bin/env perl
use warnings;
use strict;
use utf8;
use JSON::XS;
use Data::Compare;
use Path::Class;
my ($a_json, $b_json) = @ARGV;
@dyng
dyng / gist:4593916
Created January 22, 2013 11:21
编写插件时常用的打开窗口的命令
" 保持轮换文件不变,在左上角垂直打开宽度为20的窗口,打开文件__BufName__
silent keepalt topleft vertical 20split __BufName__
@dyng
dyng / gist:5299251
Last active December 15, 2015 17:49
Inner Join 中使用 AS 的例子
SELECT me.id, him.nickname, me.user_id, transaction_id, purchase_at FROM payment AS me INNER JOIN user AS him ON me.user_id = him.id WHERE him.nickname = 'tama';
@dyng
dyng / n2N2n
Last active December 21, 2015 04:09
"n" 固定正向搜索,"N" 固定逆向搜索。
noremap <silent><expr>n v:searchforward ? "n" : "N"
noremap <silent><expr>N v:searchforward ? "N" : "n"
@dyng
dyng / gist:8993654
Created February 14, 2014 01:18
测试包含LWP::UserAgent的模块
use Test::More;
use Test::MockModule;
use HTTP::Request;
our $request_count = 0;
my $mock_ua = Test::MockModule->new('LWP::UserAgent');
$mock_ua->mock('request', sub {
$request_count++;
HTTP::Response->new(200);
});