Skip to content

Instantly share code, notes, and snippets.

View wwj718's full-sized avatar

wwj718

View GitHub Profile
@wwj718
wwj718 / easy_django.py
Created May 8, 2014 02:28
简单清晰的Django
#coding=utf-8
import sys
from django.conf import settings
from django.conf.urls import patterns
from django.http import HttpResponse
from django.core.management import execute_from_command_line
settings.configure(
@wwj718
wwj718 / bootstrap2-begin.html
Created May 31, 2014 11:57
bootstrap2-begin
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" >
<link href="http://libs.baidu.com/bootstrap/2.3.2/css/bootstrap.min.css" rel="stylesheet">
<link href="http://cdn.bootcss.com/bootstrap/2.3.2/css/bootstrap-responsive.min.css" rel="stylesheet">
<script src="http://libs.baidu.com/jquery/1.8.2/jquery.min.js"></script>
<script src="http://libs.baidu.com/bootstrap/2.3.2/js/bootstrap.min.js"></script>
</head>
@wwj718
wwj718 / 提示用户更.py
Created September 15, 2014 05:45
代码版本更新提示
UpdateTime = urllib2.urlopen(u"http://zhihuhelpbyyzy-zhihu.stor.sinaapp.com/ZhihuHelpUpdateTime.txt",timeout=10) #线上总部
import webbrowser
webbrowser.open_new_tab(url) #调用浏览器
#coding:utf-8
#django test 中模拟登录的request
from django.contrib.sessions.middleware import SessionMiddleware
from django.test.client import RequestFactory
def add_session_to_request(request):
"""Annotate a request object with a session"""
middleware = SessionMiddleware()
# Settings that can be used when running inside of a docker container
[hive]
release = apache
database = default
warehouse_path = hdfs://hadoop:9000/edx-analytics-pipeline/warehouse/
[database-export]
database = analytics
#credentials = hdfs://hadoop:9000/edx-analytics-pipeline/output/local.json
@wwj718
wwj718 / _update_with_kwargs.py
Created July 7, 2015 03:24
update_with_kwargs.py
def _update_with_kwargs(data_dict, **kwargs):
"""Updates a dict from kwargs only if it modifies a top-level value."""
for key, value in kwargs.iteritems():
if key in data_dict:
data_dict[key] = value
#views.py
from opaque_keys.edx.locations import SlashSeparatedCourseKey
from courseware.courses import get_course_by_id
from .models import Addition
from rest_framework.response import Response
from rest_framework.decorators import api_view,permission_classes,authentication_classes
from rest_framework.authentication import SessionAuthentication,OAuth2Authentication
from django.core.exceptions import ObjectDoesNotExist
from django.conf import settings
from student.models import CourseEnrollment
@wwj718
wwj718 / logging.py
Last active September 1, 2015 05:53
日志
#!/usr/bin/env python
# encoding: utf-8
import logging
LOG_FILE = "log_file.log"
#logging.basicConfig(filename=LOG_FILE,level=logging.DEBUG)
logger = logging.getLogger(__name__)
handler=logging.FileHandler(LOG_FILE)
logger.addHandler(handler)
logger.setLevel(logging.DEBUG)
logger.debug("this is an debug message")
@wwj718
wwj718 / grab-sessionid.py
Last active September 21, 2015 09:19 — forked from cgoldberg/grab-sessionid.py
grab session id from edX cookie
def login(email, password, base_url='https://courses.edx.org'):
"""Login via HTTP and parse sessionid from the cookie."""
r = requests.get('{}/login'.format(base_url))
csrf = r.cookies['csrftoken']
payload = {'email': email, 'password': password}
cookies = {'csrftoken': csrf}
headers = {'referer': '{}/login'.format(base_url), 'X-CSRFToken': csrf}
r = requests.post('{}/user_api/v1/account/login_session/'.format(base_url),
data=payload, cookies=cookies, headers=headers)
try:
@wwj718
wwj718 / missing_profiles.py
Last active September 21, 2015 09:21 — forked from bdero/missing_profiles.py
edX: Get users without student profiles
from django.contrib.auth.models import User
from student.models import UserProfile
profileless = [user for user in User.objects.all() if not UserProfile.objects.filter(user=user).count()]