What I'm Thinking

When making use of AWS CloudFormation there is currently a file size limit of 51200 bytes on stack templates. On a reasonable size setup you can quickly hit that limit using JSON format, while YAML format will take you a while longer. A quick example of a file size comparison between the two file formats; stack.yaml - 3.3K stack.json - 5.6K If you want to convert from JSON to YAML you can do that with the following python code snippet. ... Read More

Tarfile Tip
30 November 2016

Working with tar files and attempting to create a py.test fixture of a tar file and I ran into an issue. I’m using TarFile package on python 3.5 My initial fixture was setup as; @pytest.fixture def file_tar(tmpdir, tmpdir_factory): fn = tmpdir_factory.mktemp("tar").join("test.tar") tf = tarfile.TarFile(str(fn), "w") p1 = tmpdir.mkdir("src1").join("test1.txt") p1.write("text 1 content") tf.add(p1) p2 = tmpdir.mkdir("src2").join("test2.txt") p2.write("text 2 content") tf.add(str(p2)) tf.close() return fn But I ended up with an empty file in the tar’d file fixture, and that was causing issues when attempting to extract the contents of the tar’d file. ... Read More
Came across a funky error attempting to upload a package to PyPi using Python 3.5 $ python setup.py sdist bdist_wheel upload ... Traceback (most recent call last): File "setup.py", line 45, in <module> install_requires=['django>=1.10'] File "/usr/lib64/python3.5/distutils/core.py", line 148, in setup dist.run_commands() File "/usr/lib64/python3.5/distutils/dist.py", line 955, in run_commands self.run_command(cmd) File "/usr/lib64/python3.5/distutils/dist.py", line 974, in run_command cmd_obj.run() File "/usr/lib64/python3.5/distutils/command/upload.py", line 63, in run self.upload_file(command, pyversion, filename) File "/usr/lib64/python3.5/distutils/command/upload.py", line 162, in upload_file body. ... Read More
Full templating functionality in our website. We want to be able to pass in data to the templates and determine which templates are to be used when generating our response. This is a continuation of the Golang Web Apps and the source code can be found at https://github.com/reinbach/golang-webapp-guide. To better organize the code we move all the templating functionality, the templates, and the static files into a separate directory. Which now gives us the following file layout. ... Read More

Golang - Web - Guide
3 April 2015

A multi-part article about developing a website with Golang, with each article about a specific piece of functionality that is common for a complete website. Previously I have done a large amount of development with the Django framework. I like it because it has everything and it allows one to develop a website quickly, and so there will be a lot of influence from that in these articles. The reason I made use of Golang is because I wanted to see how simple it would be to implement a lot of this functionality with mainly the Golang standard packages. ... Read More
The scenario is that we want to use formsets on a model, but the model has a foreign key, and we only want a subset of the elements referenced by the foreign key. i.e. We don’t want all of the options returned by the foreign key to be shown. I really like the Django class based views and use them as much as possible. I find that they make my life a lot easier. ... Read More

Django - Recursive Templates
23 December 2014

The scenario I had was that of a table showing a list of accounts and these accounts had subaccounts. I wanted a simple way to display these subaccounts, but indented slightly relative to their parent. And I did not know the number of levels involved. The following is the way I went about solving this in this instance was to call django templates recursively. Create a templatetag to handle the display of displaying indentation character the correct number of times; ... Read More

Golang Web Apps
5 April 2014

This is a short simple guide about using golang for web application development. The idea is that we start with the straight golang net/http package and slowly develop a more complex web application each time as our needs grow. Adding a component, or functionality to the system to solve the identified need. All code can be found at https://github.com/reinbach/golang-webapp-guide Basics Firstly we start with the absolute basics. Which is to handle a request and return a response. ... Read More

Git Reflog
15 March 2014

Git reflog just saved my bacon. Last week my commit message referenced the wrong ticket and in attempting to fix the commit message I accidentally reset our develop branch of the project to the master branch. In short, I wiped out all our changes in the project! A few months of work gone, poof! Well, Git is a distributed repo system so everyone still had the original correct repo, but to top things off I had also pushed these changes to our our central repo server. ... Read More

Block SSH Attacks
1 March 2014

Periodically one of my servers gets hit by SSH brute force attacks, and I finally got tired of manually dealing with it. Previously I would go through the following flow; Get a notification that my server load was increasing Log into the sever Check/confirm that it was the usual issue, by looking at the logs Check where the offending IP address is originating from. Add an iptables rule to block the offending IP address iptables -I INPUT -s <OFFENDING_IP> -j DROP Watch as the load returned to normal So after a little research, with the goal of not wanting anything fancy or crazy to install and/or setup. ... Read More