Skip to content

Instantly share code, notes, and snippets.

View lu911's full-sized avatar
🎯
Focusing

Seungchan Yuk lu911

🎯
Focusing
View GitHub Profile
@lu911
lu911 / gist:7885671
Created December 10, 2013 04:18 — forked from evildmp/gist:3094281

This document has now been incorporated into the uWSGI documentation:

http://uwsgi-docs.readthedocs.org/en/latest/tutorials/Django_and_nginx.html

Set up Django, nginx and uwsgi

Steps with explanations to set up a server using:

@lu911
lu911 / snippet.py
Created March 10, 2014 17:40
Class based SnippetList
from snippets.models import Snippet
from snippets.serializers import SnippetSerializer
from django.http import Http404
from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework import status
class SnippetList(APIView):
"""
public String POST(String addr, String post){
StringBuffer sb = null;
String type = "application/x-www-form-urlencoded";
HttpURLConnection urlCon = null;
BufferedReader br = null;
OutputStreamWriter wr = null;
String line = null;
try {
sb = new StringBuffer();
URL url = new URL(addr);
@lu911
lu911 / models.py
Last active August 29, 2015 14:00
Category Model
class Category(IdMixin, CRUDMixin, db.Model):
__tablename__ = '%s_categories' % TITLE
name = db.Column(db.String(16), nullable=False)
type_code = db.Column(db.SmallInteger, default=ETC_TYPE, nullable=False)
parent_category_id = db.Column(db.Integer, db.ForeignKey('%s.id' % __tablename__))
children = db.relationship('Category', cascade='all',
backref=db.backref('parent_category', remote_side='%s.c.id' % __tablename__))
def __init__(self, name, type_code=None, parent_category_id=None):
TITLE = 'healthcare'
class Category(CRUDMixin, db.Model):
__tablename__ = '%s_categories' % TITLE
name = db.Column(db.String(16), nullable=False)
type_code = db.Column(db.SmallInteger, default=ETC_TYPE, nullable=False)
parent_category_id = db.Column(db.Integer, db.ForeignKey('%s.id' % __tablename__))
children = db.relationship('Category', cascade='all',
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/home/loup/Desktop/projects/new_kidsmamma/kidsmamma/models/mixins.py", line 14, in get_by_id
return cls.query.get(int(id))
File "/home/loup/.virtualenvs/new-kidsmamma/local/lib/python2.7/site-packages/flask_sqlalchemy/__init__.py", line 426, in __get__
mapper = orm.class_mapper(type)
File "/home/loup/.virtualenvs/new-kidsmamma/local/lib/python2.7/site-packages/sqlalchemy/orm/base.py", line 378, in class_mapper
mapper = _inspect_mapped_class(class_, configure=configure)
File "/home/loup/.virtualenvs/new-kidsmamma/local/lib/python2.7/site-packages/sqlalchemy/orm/base.py", line 355, in _inspect_mapped_class
mapper._configure_all()
# -*- coding: utf-8 -*-
from flask import Flask, request
from config import DefaultConfig
from extensions import db
def create_app(_config=DefaultConfig()):
app = Flask(__name__)
app.config.from_object(_config)
SELECT items.id AS items_id, items.created_at AS items_created_at, items.updated_at AS items_updated_at, items.origin_id AS items_origin_id, items.origin_category_id AS items_origin_category_id, items.origin_photo_url AS items_origin_photo_url, items.name AS items_name, items.price AS items_price, items.sale_price AS items_sale_price, items.description AS items_description, items.redirect_url AS items_redirect_url, items.view_count AS items_view_count, items.category_id AS items_category_id, items.mall_id AS items_mall_id
FROM items INNER JOIN categories ON categories.id = items.category_id
WHERE categories.id = 10000 OR categories.id = 10100 OR categories.id = 10200 OR categories.id = 10300 OR categories.id = 10400 OR categories.id = 10500 OR categories.id = 10501 OR categories.id = 10502 OR categories.id = 10503 OR categories.id = 10504 OR categories.id = 10505 OR categories.id = 10500 OR categories.id = 10600 OR categories.id = 10700 OR categories.id = 10701 OR categories.id = 10702 OR categories.id = 1070
query = query.with_entities(Item.id).paginate(page, 60, False)
_items = []
for item in query.items:
item = Item.get_by_id(int(item[0]))
if item:
_items.append(item.serialize())
import ssl
import socket
ssl_sock = ssl.wrap_socket(
socket.socket(socket.AF_INET, socket.SOCK_STREAM),
ssl_version=ssl.PROTOCOL_SSLv3,
certfile=CERT_FILE
)
ssl_sock.connect(APNS_SERVER)