Slaptijack Title

Archive for the ‘Programming’ Category

Two Column for Loop in bash

I had this interesting question the other day. Someone had a file with two columns of data in it. They wanted to assign each column to a different variable and then take action using those two variables. Here's the example I wrote for them: IFS=$'n'; for LINE in $(cat data_file); do V...

Read More →

Categories: Programming

Interleave Two Lists of Variable Length (Python)

I was recently asked to take two lists and interleave them. Although I can not think of a scenario off the top of my head where this might be useful, it doesn't strike me as a completely silly thing to do. StackOverflow's top answer for this problem uses itertools.chain.from_iterable() and iterto...

Read More →

Categories: Programming

Socket Timeouts in urllib2

One of my scripts that makes an API call has been failing silently lately. It appears that the connection is timing out, but I am not catching that particular error. So, I fixed that. @@ -8,6 +8,7 @@ import os import random import shelve +import socket import sys import time import urllib2 ...

Read More →

Categories: Programming

Working Around EVE-KILL + Cloudflare Block

I've got some code that generates loss reports for EVE Online. It uses the EVE-KILL API and Python's urllib2 library. Near the end of October 2015, I noticed that my calls to the API were returning a 403: Forbidden error from the server. I didn't realize it at the time, but EVE-KILL uses Cloudfla...

Read More →

Categories: Programming

UnicodeDecodeError: 'ascii' codec can't decode byte

Although I was getting this output in relation to one of my Jinja2 templates, it really isn't a Jinja2 problem. UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 69: ordinal not in range(128) The bit of code here should be doing nothing more than printing a float: '{:,.2f}'.for...

Read More →

Categories: Programming