Custom Filter for Jinja Templates

You may have noticed, prior to this, my blog posts have looked like a wall of text. That’s because Jinja (Templating engine) was stipping newlines. To resolve this issue, use a custom filter: def BlogPostFilter(value): return value.replace(‘\n’,’\n’) app.jinja_env.filters[‘BlogPostFilter’] = BlogPostFilter {{ blogPost.body | BlogPostFilter }} … I still need to work on whitespace to get[…]

Unicode of DOOOM!!

So I have this great system to automatically update the blog from a list of files when I click a button. Of course it broke while bringing in the latest post about Hyper-V – UNICODE!!! Solution was to decode when reading in from file: with open(blogpost, ‘r’) as bp: body = bp.read().decode(‘utf-8’)

Original Timestamp: 2014-02-06 00:09:18.512687

Original Timestamp: 2014-02-06 00:09:18.512687 Get going quick – coding for MineCraft on FreeBSD10 # mkdir mineDev # cd mineDev # mkdir craftbukkit # pkg install netbeans *you can accomplish this different ways – this is the newest / easiest (instal # fetch http://dl.bukkit.org/downloads/craftbukkit/get/02389_1.6.4-R2.0/craftbuk # fetch http://apache.mirrors.tds.net/maven/maven-3/3.1.1/binaries/apache-maven- # mv craftbukkit.jar craftbukkit # tar -xf apache-maven-3.1.1.bin.tar.gz #[…]

Original Timestamp: 2014-02-18 20:48:13.659576

Original Timestamp: 2014-02-18 20:48:13.659576 From: http://stackoverflow.com/questions/7108193/frequently-repeated-try-except-in-python …The best way to abstract exception handling is with a context manager: from contextlib import contextmanager @contextmanager def common_handling(): try: yield finally: # whatever your common handling is then: with common_handling(): os.remove(‘/my/file’) with common_handling(): os.chmod(‘/other/file’, 0700)