Blog Posts

A List of All Python Assert Methods

04 Aug 2017 - I am constantly looking up assert methods on the Python 2 Unit Test Documentation and it's driving me crazy because that page is super long and hard to mentally parse. The lists of assert methods available are broken up in different sections on the page and I'm done searching around it. So here's a compiled list of all of them for my reference, but maybe this is useful for someone else out there too. Method... Read more...

Convert a Javascript Dictionary To GET URL Parameters

09 May 2017 - I've had serveral instances in the recent past where I needed to take a javascript dictionary and convert it into a set of GET parameters to be used in a URI. Usually this happens when I'm building an AJAX request. Anyway, since I've used this function over and over I thought I'd post it incase it helps any of you Googling for something similar. Here's the function... function dictToURI(dict) { var str = []; for(var... Read more...

Invalidate All Cloudfront Files

01 May 2017 - As I mentioned before, this website is built using Jekyll which generates static html which is then hosted on AWS S3. This works great for me because it allows me to take advantage of the enormous capacity S3 offers while paying pennies per month for hosting and bandwidth. All the while I get to skip worrying about spinning up web servers, virtual machines, etc. I do love doing all that but not for a simple... Read more...

Checking if a variable is set in Jekyll

28 Apr 2017 - This site is built using Jekyll which allows me to generate the entire thing as static html which can then be hosted on AWS S3. Working through the Jekyll documentation I couldn't find a way to check if a variable was set when coding in Jekyll's templating language Liquid. This is easy in python and javascript but after some digging I found this Github issue thread which (after a lengthy discussion) came up with the... Read more...

Query an NTP server from Python

09 Jun 2014 - I came across a need to query an NTP server to get the current time from a python script. There are some great python modules you can install which will take care of the heavy lifting (one great one is ntplib), but I wanted to be able to do these NTP queries without requiring the host to install 3rd party python packages. As it turns out, it wasn't too difficult after checking out a few... Read more...

Move Vim .swp files

19 May 2014 - Vim has this annoying habit of creating .swp files in your current working directory when you're editing a file. I found a better way (inspired by this stackoverflow thread). To change this, create three new folders to house all your .swp files... mkdir -p ~/.vim/{backup_files,swap_files,undo_files} Then add the following lines to your .vimrc fileā€¦ set backupdir=~/.vim/backup_files// set directory=~/.vim/swap_files// set undodir=~/.vim/undo_files// See the docs for more info. Using double trailing slashes in the path tells vim... Read more...

JS Error using X-Editable?

03 Nov 2013 - If you're trying to use X-Editable and getting a JS error similar to this... TypeError: $.fn.popover.defaults is undefined It may be because you're using Bootstrap 3 and using their CDN urls for including their JS and CSS. Their CDN currently only hosts their Bootstrap 2 code. To use it with Bootstrap 3, you need to download their repository and host it locally. Read more...

Manage WIFI using The OSX Command Line

15 Oct 2013 - The OSX terminal has several command line tools that allow you to manage your WIFI settings. Connecting, disconnecting and scanning for available WIFI networks is easy once you know which command does what. Turn off wifi on your macbook from the Mac OSX terminal command line: networksetup -setairportpower en0 off Turn on wifi on your macbook from the Mac OSX terminal command line: networksetup -setairportpower en0 on List available wifi networks from the Mac OSX... Read more...

Force VIM to stop overwriting your default buffer when pasting

25 Sep 2012 - I use VIM all the time for development, one thing that always bugs me is when I yank a chunk of code into my default buffer, and then paste if over something else, VIM will take whatever was pasted over and overwrite my default buffer with it. So the next time I try to paste, it will paste the previously pasted over text instead of the original stuff I yanked. Stick the following line into... Read more...

Fixing "Viewport argument value" error in webkit's console

16 Sep 2012 - I've been doing a lot of web development for mobile devices lately, and while I've been using chrome's developer tools, I keep getting annoying error messages in the console like this... Viewport argument value "1;" for key "initial-scale" was truncated to its numeric prefix. The culprit here is my viewport meta tag. Mine looked like this... <meta name="viewport" content="width=device-width; height=device-height; initial-scale=1; maximum-scale=1; user-scalable=0;"> Which looks correct at first glance, I probably copy and pasted it... Read more...

Copying a directory in linux while preserving permissions

11 Sep 2012 - Continuing on with my attempts to blog code and command snippets that I've found useful, Here's a trick if you need to copy a directory recursively, but retain all the permissions set on the first one. I needed this to back up a web app tree that had custom permissions set through out that I didn't want to mess up... cp -a /source_dir /destin_dir Read more...

Fixing position:fixed elements stuck in the middle of the page on iPhone Safari

10 Sep 2012 - We ran into an annoying bug over at Gigwalk while building a mobile webapp running inside Phonegap. We have a toolbar at the top of all our pages which is set to position:fixed, but every once in a while it would get stuck in the middle of the page. We tried several different proposed solutions, but this one worked for us. Run the following function after the page loads and it will force Safari to... Read more...

Iterating over a dict in a jinja template

09 Sep 2012 - At the time of this posting, iterating over dictionaries inside a Jinja template is poorly documented, and it's something I end up doing alot. Here's how you do it, nice and simple... <dl> {% for key, value in _dict.iteritems() %} <dt>{{ key }}</dt> <dd>{{ value }}</dd> {% endfor %} </dl> Easy after you know. See the full API: http://jinja.pocoo.org/docs/api/ Read more...