Thursday, August 15, 2013
Account authentication for pushing to code.google.com: what password?
It's not immediately obvious that you shouldn't just use your gmail account password when submitting code to code.google.com. While you can change your google code settings to do that, the default is to use the auto-generated password available at https://code.google.com/hosting/settings. If you're using google two-factor authentication the auto-generated password is probably your only option.
Saturday, August 3, 2013
HOWTO tar, zip, and encrypt a directory tree
Use this command to tar, zip and encrypt a directory:
tar cvz --to-stdout src_dir | gpg --cipher-algo AES256 --symmetric > out.tar.gz.gpgOR you can use gpg-zip, which is a thin shell wrapper around tar and gpg for exactly this purpose, but it turns out getting the arguments passed correctly to tar and gpg for what I want to do was more complex than the above.
Tuesday, July 16, 2013
Human readable sharing links for files in Google Drive
If you follow the instructions for sharing links to google drive files, you end up with horrible links that are mostly just long random strings, which violate Google's own advice about URLs, but are necessary to avoid namespace conflicts.
To get a more human readable link, right click on a file in drive, click Details, then use the link under 'Hosting'. It still has a random string, but the string is the same for all files within each Drive folder and the end of the URL is the same as the name of the file in Drive, which is a significant improvement.
To get a more human readable link, right click on a file in drive, click Details, then use the link under 'Hosting'. It still has a random string, but the string is the same for all files within each Drive folder and the end of the URL is the same as the name of the file in Drive, which is a significant improvement.
Friday, July 12, 2013
How not to do incident response
The OIG has a great write-up of an incident response at the Economic Development Administration that cost them $2.7m and included them physically destroying $170k of computer equipment: right down to keyboards and mice because they believed malware had firmware persistence capabilities. There were huge mis-communications with the Department Of Commerce CIRT, and a series of bad assumptions that led to this scenario. Great case study.
Thursday, July 11, 2013
Python: skip a unittest with unittest.skipTest
There's a neat way to skip python tests built into unittest. You can use decorators for the test or whole class of tests that will skip a test unconditionally or based on a condition.
In my case there was significant setup to do before I knew whether or not this test should be skipped, in which case you can call unittest.TestCase.skipTest, which just raises a unittest.SkipTest exception that is handled by the test runner. It looks like this:
In my case there was significant setup to do before I knew whether or not this test should be skipped, in which case you can call unittest.TestCase.skipTest, which just raises a unittest.SkipTest exception that is handled by the test runner. It looks like this:
In [40]: runner = unittest.TextTestRunner()
In [41]: class testing(unittest.TestCase):
def testblah(self):
pass
def setUp(self):
self.skipTest('asdfasdf')
def runTest(self):
pass
....:
In [42]: thistestclass=testing()
In [43]: runner.run(thistestclass)
s
----------------------------------------------------------------------
Ran 1 test in 0.000s
OK (skipped=1)
Out[43]:
Friday, June 28, 2013
Python assertRaises exception inside generator
So I have a generator and I want to make sure it throws an exception after a certain number of calls. So expected behaviour is this:
def generate():
yield 1
yield 2
raise Exception()
How do you check that in a test? You can't do this:
class testExample(unittest.TestCase):
def test_generatorExample(self):
self.assertRaises(Exception, a)
since a generator isn't callable. Turns out that assertRaises is a context manager as of python 2.7, which is very cool:
class testExample(unittest.TestCase):
def test_generatorExample(self):
with self.assertRaises(Exception):
list(a)
Or for earlier versions of python you could use a lambda:
self.assertRaises(Exception, lambda: list(a))
Thursday, June 27, 2013
Continuously loop (cycle) through a list in python
Thank you itertools:
In [7]: a=[1,2,3] In [8]: licycle = itertools.cycle(a) In [9]: licycle.next() Out[9]: 1 In [10]: licycle.next() Out[10]: 2 In [11]: licycle.next() Out[11]: 3 In [12]: licycle.next() Out[12]: 1 In [13]: licycle.next() Out[13]: 2 In [14]: licycle.next() Out[14]: 3 In [15]: licycle.next() Out[15]: 1 In [16]: licycle.next() Out[16]: 2 In [17]: licycle.next() Out[17]: 3
Subscribe to:
Posts (Atom)

