Skip to content

Instantly share code, notes, and snippets.

View chuangbo's full-sized avatar
🙂
Be nice

Chuangbo Li chuangbo

🙂
Be nice
View GitHub Profile
@chuangbo
chuangbo / .bash_completion
Created November 12, 2010 03:52
easy to write a bash_completion script file
_server.py()
{
local cur prev opts base
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
#
# The first options should be a yaml config
#
@chuangbo
chuangbo / funcs' decorator
Created January 11, 2011 16:39
chuangbo's decorator
#!/usr/bin/python
# -*- coding: utf8 -*-
_actions = []
def action(f):
"""Decorator to register an action."""
_actions.append(f)
return f
@chuangbo
chuangbo / README.md
Last active June 19, 2023 04:48
Python dynamic DNSPod DNS Script

替换上你的 API Token,域名ID,记录ID等参数,就可以运行了。 会在后台一直运行,每隔30秒检查一遍IP,如果修改了就更新IP。

获取 API Token 的方式

获得 domain_id 可以用 curl

curl -k https://dnsapi.cn/Domain.List -d "login_token=TOKEN"`
@chuangbo
chuangbo / 40147.md
Created June 21, 2012 01:46
/t/40147
```
$ dig +trace www.douban.com
; <<>> DiG 9.7.3-P3 <<>> +trace www.douban.com
;; global options: +cmd
. 23374 IN NS j.root-servers.net.
. 23374 IN NS f.root-servers.net.
. 23374 IN NS c.root-servers.net.
. 23374 IN NS h.root-servers.net.
. 23374 IN NS i.root-servers.net.
#include <iostream>
using namespace std;
int main() {
if ( (10 > 5 > 3) == true) {
cout << "10 > 5 > 3 = true" << endl;
} else {
cout << "10 > 5 > 3 = false" << endl;
}
return 0;
@chuangbo
chuangbo / cidr.py
Created August 13, 2012 09:45
Check if ip in cidr
#-*- coding:utf-8 -*-
# Author: @chuangbo
# For: @likexian
import socket
import struct
class CIDR:
'''Check if ip in cidr
@chuangbo
chuangbo / word-break-ii.py
Created February 13, 2014 09:29
Very pythonic version solution of leetcode word break ii http://oj.leetcode.com/problems/word-break-ii/
# from __future__ import print_function
import functools
def memoize(obj):
cache = obj.cache = {}
@functools.wraps(obj)
def memoizer(*args, **kwargs):
if args not in cache:
$ http post https://io.notie.io/ source_id:=186 secret=XXXXXX title=test action=test content=test -v
POST / HTTP/1.1
Accept: application/json
Accept-Encoding: gzip, deflate, compress
Content-Length: 97
Content-Type: application/json; charset=utf-8
Host: io.notie.io
User-Agent: HTTPie/0.7.2
{
@chuangbo
chuangbo / importcn.py
Created April 3, 2014 05:54
Tool for import one domain from dnspod.cn to dnspod.com. Just import records which record_line is 默认
#!/usr/bin/env python
#-*- coding:utf-8 -*-
"""Tool for import one domain from dnspod.cn to dnspod.com. Just import records which record_line is 默认
usage: %s DOMAIN [DOMAIN2] [DOMAIN3] ...
Modify this script first, enter both cn & com account infomation.
If DOMAIN not exists in your dnspod.com account, will add it first.
"""
import httplib, urllib
@chuangbo
chuangbo / netdata.2s.py
Created April 6, 2016 04:20
Bitbar plugin for netdata
#!/bin/env python
import requests
url = 'http://YOUR_HOST_NAME/api/v1/data'
def netdata(chart):
r = requests.get(url, params={
'chart': chart,
'points': 1,