Skip to content

Instantly share code, notes, and snippets.

View houming818's full-sized avatar

houming818 houming818

View GitHub Profile
@houming818
houming818 / models.py
Created August 9, 2017 03:23
add ManyToMany field in serializer of django rest_framework.
class LvsHostSerializer(HyperlinkedModelSerializer):
ipaddress = LvsIpaddressSerializer(read_only=True, many=True)
class Meta:
model = LvsHost
fields = '__all__'
class LvsClusterSerializer(HyperlinkedModelSerializer):
hosts = LvsHostSerializer(many=True)
@houming818
houming818 / view.py
Created August 13, 2017 13:36
a dynamic view set for generating a restful API by django rest framework
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from __future__ import print_function
from django.conf import settings
from django_mysql.models import fields
from rest_framework.compat import is_authenticated
from rest_framework.filters import DjangoObjectPermissionsFilter
from rest_framework.metadata import SimpleMetadata
from rest_framework.permissions import DjangoObjectPermissions
@houming818
houming818 / cVim.conf
Last active August 26, 2017 06:27
cVim.conf
" Settings
let barposition = "bottom"
set noautofocus
let searchengine instapaper = "https://www.instapaper.com/search?q=%s"
let searchengine pinboard = "https://www.pinboard.in/search/u:ironfish?query=%s"
let completionengines = ["google", "amazon", "instapaper", "pinboard"]
@houming818
houming818 / ddns.sh
Last active March 20, 2019 11:36
auto update the public IP for the record in dnspod. 自动更新dnspod解析记录的脚本
#!/bin/sh
# HOST STATUS
hostname=""
public_ip=""
# RECORD STATUS
code=""
value=""
message=""
@houming818
houming818 / summary.md
Last active September 6, 2017 13:49
summary for the inodes out of usage.

this is the xfs_info out_put:

[root@localhost home]# xfs_info /home
meta-data=/dev/mapper/centos-home isize=256    agcount=4, agsize=28938752 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0        finobt=0
data     =                       bsize=4096   blocks=115755008, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
log      =internal               bsize=4096   blocks=56521, version=2
@houming818
houming818 / gist:36269351bb41cc6e477e1c54faffaed1
Created September 8, 2017 09:06
[example][tutorial] openresty insert data into MySQL with MySQL connection pool.
lua_package_path '/usr/local/openresty/lualib/?.lua;;';
lua_package_cpath '/usr/local/openresety/lualib/?.so;;';
server {
listen 7020;
access_log logs/tredis.access.log main;
lua_need_request_body on;
@houming818
houming818 / file_pipe_socket.py
Last active September 30, 2017 08:02
pipe a file to a tcp socket and send to other host.
def __runner(server_id, host, port, filename):
LOGGER.debug('start %s', os.getpid())
LOGGER.debug('start ppid %s', os.getppid())
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(1.0)
server_address = (host, port)
try:
sock.connect(server_address)
except socket.error as err:
return {'retcode': err.errno, 'stdout': '', 'stderr': str(err)}
@houming818
houming818 / dbrouter.py
Created September 30, 2017 05:53
DBRouter class for django
class DBRouter(object):
"""
A router to control all database operations on models in the auth application.
"""
def db_for_read(self, model, **hints):
"""
Attempts to read auth models go to auth_db.
"""
if model._meta.app_label in settings.DATABASES.keys():
return model._meta.app_label
@houming818
houming818 / $HOME\.ssh\config
Last active November 15, 2017 06:16
由$HOME/.ssh/config配置,优化github.com下git协议的可靠性.简称:git翻墙
Host github.com
Hostname ssh.github.com
Port 443
@houming818
houming818 / nginx-websocket-proxy.conf
Created November 15, 2017 07:15 — forked from uorat/nginx-websocket-proxy.conf
Nginx Reverse Proxy for WebSocket
upstream websocket {
server localhost:3000;
}
server {
listen 80;
server_name localhost;
access_log /var/log/nginx/websocket.access.log main;