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.
Tuesday, July 16, 2013
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
Wednesday, June 12, 2013
Disable Java web applet in Internet Explorer
Microsoft has joined the good fight to make disabling the vulnerability-ridden Java web plugin easier. They have released a fixit that blocks the Java ActiveX DLLs from loading and disables the JNLP handler, which effectively disables Java in IE.
Sunday, June 2, 2013
SQL join syntax
Jeff Atwood posted a useful memory aid for SQL join syntax, although as many commenters point out there are a number of caveats to using set theory for this task.
Subscribe to:
Posts (Atom)

