This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # | |
| import httplib2 | |
| from json import loads, dumps | |
| header = {'Content-Type': 'application/json; charset=UTF-8'} | |
| pem_path = "/path/to/domainname.pem" | |
| h = httplib2.Http(ca_certs=pem_path, disable_ssl_certificate_validation=True) | |
| req_dict = { | |
| "url": "url", | |
| "method": "method", | |
| "body": dumps({"key": "value"}), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import urls | |
| def show_urls(urllist, depth=0): | |
| for entry in urllist: | |
| print " " * depth, entry.regex.pattern | |
| if hasattr(entry, 'url_patterns'): | |
| show_urls(entry.url_patterns, depth + 1) | |
| show_urls(urls.urlpatterns) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import timeit | |
| a={u'is_public': [u'True']} | |
| b={'name': u'', 'devie_type': u'', 'is_public': True, 'serial_num': u'', 'is_online': False, 'operation_system': u''} | |
| def test1(): | |
| map(lambda (k,v): (k, b[k]), a.items()) | |
| def test2(): | |
| {k: b[k] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from threading import Thread | |
| def example(a,b): | |
| for i in range(1000): | |
| pass | |
| return a+b | |
| thr = Thread(target=example, args=[1, 2]) | |
| print thr.start() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 1.server安裝 Postfix (for smtp) | |
| # apt-get install mailutils postfix | |
| server configuration type : Internet Site | |
| # vim /etc/postfix/main.cf | |
| inet_interfaces = localhost |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <title></title> | |
| </head> | |
| <body> | |
| <a target="_self" href="https://s1.yimg.com/rz/d/yahoo_frontpage_zh-Hant-TW_s_f_p_bestfit_frontpage_2x.png" download="picture">picture</a> | |
| </body> | |
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import string | |
| s = string.ascii_uppercase | |
| def convert_string_to_index(word): | |
| word = word.upper() | |
| s_expression = '+'.join([ letter for letter in word]) | |
| n_expression = '+'.join([ str(s.index(letter)+1) for letter in word]) | |
| total = sum([s.index(letter)+1 for letter in word]) | |
| print s_expression |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class SignUpSerializer(serializers.ModelSerializer): | |
| class Meta: | |
| model = User | |
| fields = ('username', 'email', 'password', 'first_name', 'last_name') | |
| def save(self, *args, **kwargs): | |
| """create user | |
| """ | |
| User.objects.create_user(**self.validated_data) | |
| ''' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Queue | |
| import threading | |
| import urllib2 | |
| # called by each thread | |
| def get_url(q, url): | |
| q.put(urllib2.urlopen(url).read()) | |
| theurls = ["http://google.com", "http://yahoo.com"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| upstream $repo_name { | |
| server unix://$service_deployment_filename/websock.sock; | |
| } | |
| # configuration of the server | |
| server { | |
| # the port your site will be served on | |
| listen 80; | |
| # the domain name it will serve for | |
| server_name localhost; |
OlderNewer