This file contains 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
# http://stackoverflow.com/questions/600268/mkdir-p-functionality-in-python | |
import os, errno | |
def mkdir_p(path): | |
try: | |
os.makedirs(path) | |
except OSError as exc: # Python >2.5 | |
if exc.errno == errno.EEXIST and os.path.isdir(path): | |
pass | |
else: raise |
This file contains 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
@app.route("/random") | |
def randomimg(): | |
data = [i for i in db.fs.files.find().sort("_id", 1)][-20:] | |
response = make_response(json.dumps({'results': data}, | |
default=json_util.default, | |
indent=4)) | |
response.headers['Content-Type'] = 'application/json' | |
response.headers['mimetype'] = 'application/json' | |
return response |
This file contains 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
# filters.py | |
import re | |
def boldrepl(matchobj): | |
return '<b>' + matchobj.group(0) + '</b>' | |
def bolder(text, term): | |
return re.sub(term.replace("-", '|'), boldrepl, text, flags=re.I) | |
# views.py |
This file contains 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
# views.py | |
from dateutil import parser | |
# strftime and strftime_single are the name of the function | |
@app.template_filter('strftime') | |
def _jinja2_filter_datetime(date, fmt=None): | |
date = parser.parser(date) | |
native = date.info.replace(tzinfo=None) | |
format='%m-%d-%Y %H:%M %p' | |
return native.strftime(format) |
This file contains 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
""" | |
Secara default, mongodb ID sudah include datetime, sehingga tidak perlu menambahkan lagi dalam document. | |
""" | |
# filters.py | |
def get_date_from_mongoid(oid): | |
"""Get timestamp from mongodb id""" | |
return oid.generation_time | |
# in views.py |
This file contains 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 logging | |
# config | |
logging.basicConfig(filename="log.log", | |
level=logging.DEBUG, | |
format='%(asctime)s %(message)s', | |
datefmt='%m/%d/%Y %H:%M:%S %p') | |
logging.debug("hello from debug") | |
logging.info("hello from info") |
This file contains 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
# source http://stackoverflow.com/questions/7293978/repeat-an-iteration-of-for-loop | |
for eachId in listOfIds: | |
successful = False | |
while not successful: | |
response = makeRequest(eachId) | |
if response == 'market is closed': | |
time.sleep(24*60*60) #sleep for one day | |
else: | |
successful = True |
This file contains 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 urllib2 | |
if urllib2.urlopen("http://www.bing.com/webmaster/ping.aspx?siteMap=http://www.example.com/sitemap.xml").getcode() == 200: | |
print "ping bing sukses" | |
if urllib2.urlopen("http://www.google.com/webmasters/sitemaps/ping?sitemap=http://www.example.com/sitemap.xml").getcode() == 200: | |
print "ping google sukses" |
This file contains 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
# project dependencies | |
""" | |
flask_wtf | |
flask_uploads | |
""" | |
# project tree | |
""" | |
app/ | |
├── filters.py |
This file contains 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
# konfigurasi ini hanya akan meng-enable sub1 dan sub2 | |
# request ke selain 2 itu, akan diredirect ke sub1 | |
server { | |
listen 80; | |
server_name www.example.com; | |
rewrite ^ $scheme://sub1.example.com$request_uri? permanent; | |
} | |
server { |
OlderNewer