In this post I’ll provide an example of using session management in Flask. This is useful when you need to recover persistent data across different endpoints in your application. In this example, we set the permanent
attribute of the session
object to True
in order to ensure that the session data lasts indefinitely until it is cleared when the user accesses the root endpoint again. The best practice is to have a timeout on the session data.
Scraping Yahoo! Finance Data with BeautifulSoup
This weekend I wanted to work on collecting and plotting historical option contract prices. I used the following API call to pull option contract data from Yahoo!
curl -X GET "http://finance.yahoo.com/q/op?s=AAPL&m=2016-01" | cat > aapl
Continue reading Scraping Yahoo! Finance Data with BeautifulSoup
Using SVGs in IPython Notebooks
Sometimes I like working directly with SVGs in order to generate images from code. I like using the IPython Notebook for this because of the instant feedback. Here is an example for creating and viewing a small SVG within the IPython Notebook.
Swift Optimization
I learned a hard lesson today: to make Swift really fast you have to know what you’re doing. You can’t just slap some code together and expect it to be zippy without understanding some of how Swift was designed and how it works. There is a very good presentation by some of the team members that built Swift here. My initial takeaway was that it was important to finalize any classes you didn’t plan on subclassing, incrementally check the timing analyzer, and finally, employ whole module optimization.
Running Nosetests with Multiple Versions of Python
This is a short post–just a TIL sort of thing. I had an issue today where the system Python was 2.6, but I needed to run a test on some code that used Python 2.7. After some jiggering I figured out how to test my Python 2.7 code. Rather that simply running,
nosetests tests.py
I ran, instead,
/usr/local/bin/python2.7 /usr/bin/nosetests tests.py
Boom. Now we’re testing.
Cocoa REST Client
Here’s an awesome thing: an easy-to-use, free, open-source, native OS X app for testing HTTP/REST endpoints. You can even save common calls for future reference. Check out mmattozzi‘s cocoa-rest-client right now. (Seriously, stop what you’re doing.)
Pretty-printing JSON in the Terminal
I use cURL quite a bit when debugging APIs and I found this neat trick for pretty-printing JSON output. Add the following line to your .bashrc
or .zshrc
file,
alias json="python -m json.tool"
Then you can pipe your cURL output through your new json
tool and print everything nicely,
curl -g http://some.domain/api/call | json
Using MapKit in an XCode Playground
I saw some outdated material about using MapKit in an XCode Playground, so I thought I’d post an example for XCode 7.1.1 and Swift 2.1. Being able to access and manipulate a map this easily if freaking amazing. This code allows you to view the map in the timeline on the right-hand pane. You can press the diagonal Venn diagram at the top right-hand corner to toggle the timeline.
Solving Linear Equations with Swift and Accelerate
In this post we’ll cover solving a system of linear equations using Swift and Accelerate. It get’s a little bit hairy, but it’s not so bad once you get the hang of it.
Continue reading Solving Linear Equations with Swift and Accelerate
Sandi Metz on OO Best Practices
I found a post about a talk by Sandi Metz that I liked a lot, and I thought I’d post here for my personal reference. The long and short of it is that good design saves you more time and face eggs than just banging something out and hoping for the best.