Skip to content

Instantly share code, notes, and snippets.

View cgallemore's full-sized avatar

Chad Gallemore cgallemore

View GitHub Profile
@cgallemore
cgallemore / rails_vagrant.rb
Created February 21, 2014 01:04
Rails template to get up and running quickly with vagrant, to install run 'rails new project_name -m /path/to/rails_vagrant.rb'
file 'gitignore', <<-CODE
/.bundle
/.idea
/.vagrant
# Ignore the default SQLite database.
/db/*.sqlite3
/db/*.sqlite3-journal
# Ignore all logfiles and tempfiles.
@cgallemore
cgallemore / mock_input.py
Created August 11, 2013 13:04
mock raw_input
In [1]: import mock
In [2]: mock_input = mock.MagicMock()
In [3]: with mock.patch('__builtin__.raw_input', mock_input):
...: mock_input.return_value = 'foobar'
...: foo = raw_input()
...:
In [4]: foo
Out[4]: 'foobar'
def get_data_from_request(request):
"""
Convenience function to create data from a webapp2 request object.
:param request:
:return: dict
"""
# request.params combines the GET and POST data, this would give us some
# extra info to this particular request.
params = dict(request.params)
@cgallemore
cgallemore / gist:4277553
Created December 13, 2012 16:16
Work around for appengine dev_appserver restart with virutalenv and python 2.7
For those on python27, looks like py27_optional is not being passed in (dev_appserver_import_hook.py:591)
if not FakeFile.IsFileAccessible(filename)
Simplest workaround is to change the method defaults from:
def IsFileAccessible(filename, normcase=os.path.normcase, py27_optional=False)
to:
def IsFileAccessible(filename, normcase=os.path.normcase, py27_optional=True)
# File is located at:
@cgallemore
cgallemore / ramdisk.bash
Created August 20, 2012 12:26
Script to setup MySQL on ramdisk after restart
#!/bin/bash
# This is a script I use to setup MySQL on ramdisk
# after I need to reboot. This assumes that you already
# have MySQL installed and have previously moved your
# MySQL files to a backup location, e.g.:
# mv /var/lib/mysql /home/cgallemore/workspace/mysql
stop mysql
@cgallemore
cgallemore / sample_csrf_enabled.py
Created February 27, 2012 18:49
Potential Solution for testing with CSRF enabled
#In looking into the issue with being able to test with CSRF enabled,
#I've come up with a way to mock this out and wanted to see what you
#guys think before I move on. Here is a sample test of what this
#would look like:
@mock.patch.object(SessionStore, 'get_secure_cookie')
def test_can_add_order(self, mock_session):
mock_session.return_value = {'csrf_token': str(uuid4())}
self.login('[email protected]', admin = True)