Skip to content

Instantly share code, notes, and snippets.

class UserSerializer(serializers.ModelSerializer):
profile = ProfileSerializer()
class Meta:
model = User
fields = ('username', 'email', 'profile')
def create(self, validated_data):
profile_data = validated_data.pop('profile')
user = User.objects.create(**validated_data)
package main
import (
"log"
"github.com/gorilla/websocket"
)
type Message struct {
Action string `json:"action"`
@syfun
syfun / mongodb.py
Last active June 12, 2018 04:06 — forked from mattrobenolt/mongodb.py
Wrapper for pymongo to integrate nicer into Django with failover stuff, forked for python3
"""
MONGODB = {
'default': {
'NAME': env('MONGODB_DEFAULT_DATABASE', default='scanvis'), # Default database to connect to
'URI': env('MONGODB_URI', default='mongodb://localhost:27017/')
}
}
"""
from django.conf import settings
from pymongo import MongoClient
@syfun
syfun / pyenv_install.sh
Created February 10, 2018 05:57
pyenv install加速
#!/usr/bin/env bash
version=$1
if [ ! -d "~/.pyenv/cache" ]; then
mkdir -p ~/.pyenv/cache
fi
wget http://mirrors.sohu.com/python/$version/Python-$version.tar.xz -P ~/.pyenv/cache
pyenv install -v $version
@syfun
syfun / .editorconfig
Created January 30, 2018 10:24
editorconfig-sample
# http://editorconfig.org
root = true
[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
@syfun
syfun / SS-README.md
Last active October 13, 2017 02:16 — forked from zhiguangwang/README.md
Installing and running shadowsocks on Ubuntu Server

Installing and running shadowsocks on Ubuntu Server

16.10 yakkety and above

  1. Install the the shadowsocks-libev package from apt repository.

     sudo apt update
     sudo apt install shadowsocks-libev
    
  2. Save ss.json as /etc/shadowsocks-libev/config.json.

@syfun
syfun / async-mysql.py
Created July 1, 2017 04:17
python async mysql redis http
import asyncio
import aiomysql
from aiomysql.cursors import DictCursor
class MysqlWrapper:
def __init__(self, host, port, user, password, db):
self.host = host
self.port = port
@syfun
syfun / flask-config.py
Created June 26, 2017 02:29
flask config from envrioment
from flask import Flask
class Config:
DEBUG = True
def __getattribute__(self, item):
if item in os.environ:
return os.environ[item]
return object.__getattribute__(self, item)
@syfun
syfun / run_forever.py
Last active August 4, 2018 03:39
python3 asyncio correctry interrupt.
import asyncio
async def task():
while True:
print('Do something.')
await asyncio.sleep(1)
async def run(lp):
@syfun
syfun / fabfile.py
Created June 23, 2017 01:17
fabric env sample
from fabric.api import env, cd, sudo, run
env.user = 'user'
env.hosts = ['192.168.0.2']
env.password = '123456'
env.prompts = {
'continue connecting (yes/no)? ': 'yes',
'password: ': env.password
}