Skip to content

Instantly share code, notes, and snippets.

View Ivlyth's full-sized avatar
🎯
Focusing

Ivlyth Ivlyth

🎯
Focusing
View GitHub Profile
@Ivlyth
Ivlyth / mysort.md
Created November 10, 2017 02:25
sored iterable object by multi keys in different order, python2/3 compatible
  1. sort list object with tuple item
In [1]: import functools

In [2]: s = [('a', 10), ('c', 9), ('b', 10), ('c', 10), ('a', 7), ('a', 11), ('b', 11), ('c', 11)]

In [3]: def mysort(a, b):
@Ivlyth
Ivlyth / find_clickable_element.js
Last active May 26, 2022 09:44
find clickable element in page
// https://stackoverflow.com/questions/9238119/find-clickable-elements
$.each($('.container').find("*").andSelf().data("events"), function(i, event) {
$.each(event, function(j, h) {
if(j === 'click')
{
//Do stuff to $(this)
alert(j);
alert(h.handler); //Gets the actual handler for each event ( inject code >=] )
}
});
@Ivlyth
Ivlyth / Makefile
Created June 28, 2017 01:34
使用Makefile 在 centos 6.x 系统上一键安装 python2.7 并安装 virtualenvwrapper
env ?=upy
PYTHON_VENV := $(env)
version ?=2.7.10
PYTHON_VERSION := $(version)
PYTHON_DIR := Python-$(PYTHON_VERSION)
all: task-install-venv-wrapper
@ echo 'All done ...'
@Ivlyth
Ivlyth / seconds_to_human_readable.py
Last active February 1, 2018 08:24
将秒数转化为可读性更强的秒数方式
'''
将秒数转换为可读性更强的表述方式
eg:
```
In [4]: print seconds_to_human_readable(33)
33 秒
In [5]: print seconds_to_human_readable(60 * 3 + 2)
3 分钟, 2 秒
@Ivlyth
Ivlyth / commit_time_in_seconds.py
Last active November 25, 2016 10:44
从git commit中提取时间相关信息计算其距离现在的秒数
'''
例子:
1. '*********** - 1 year, 4 months ago - someone do something1' => 1*365*24*60*60 + 4*30*24*60*60
2. '*********** - 3 months, 7days ago - someone do something2' => 3*30*24*60*60 + 7*24*60*60
3. '*********** - 5 hours ago - someone do something3' => 5*60*60
'''
unit_map = {
'years': 365 * 24 * 60 * 60,
'year': 365 * 24 * 60 * 60,
@Ivlyth
Ivlyth / hproxy.conf
Created November 18, 2016 17:11
使用 SSH 隧道将内网服务暴露在公网上(主要用于临时调试等目的, 不推荐长时间的内网服务暴露)
# 使用了 lua 模块的 nginx 配置文件
# 推荐使用 openresty 或者自行编译 nginx with lua
lua_shared_dict proxy_ports 5m;
server {
listen 80;
server_name *.hproxy.yourdomain.com;
set $real_host $http_host;
if ($http_host ~* "(.*).hproxy.yourdomain.com") {
@Ivlyth
Ivlyth / ssh-keygen.sh
Last active November 14, 2016 02:47
使用ssh-keygen生成私钥对
ssh-keygen -t rsa -b 2048 -C 'your-email-address' -N '<leave blank for NO passphrase>' -f 'out-put-file'
@Ivlyth
Ivlyth / README.md
Last active March 28, 2016 08:08
always get file path relative to my current file path
-- ~/root
    |--module1
        |--sub_dir1
              |--source.0.ext
        |--source.1.ext
        |--m1.py
    |--module2
        |--source.2.ext
 |--m2.py
@Ivlyth
Ivlyth / README.md
Created March 17, 2016 08:03
learn docker

run a image

docker run IMAGE_NAME COMMAND[s]

list running containers

docker ps

If you list the running containers, you will see that none are running.

That’s because as soon as the container did its job (echoing hello world) it stopped.

@Ivlyth
Ivlyth / install_ngx_with_lua.sh
Created January 25, 2016 07:27
compile nginx with Luajit2.0
mkdir ngx-with-lua
cd ngx-with-lua
current_dir=`pwd`
# download luajit
wget http://luajit.org/download/LuaJIT-2.0.4.tar.gz
tar -xf LuaJIT-2.0.4.tar.gz
cd LuaJIT-2.0.4
make && make install