Validating arguments using decorators

Hey there!

I’d love it if you could have a look at my Generic argument validation decorator if you’ve got some time. It’s already got four to five tests and serves my needs pretty well, but I’d like to know if this needs to be generalized more or it’s enough for others as well.

Cheers!

 

Advertisements

Digital Signature on Outlook ( Comodo )

Today a friend of mine had to send an Email and the requirement was for the Email to have a digital signature.
He’s on Windows 10 so we used Outlook and got through it after a couple of tries.
This post is on how to set a digital signature using Outlook.

    • Create a backup of your certificate, and store it in a path you’d like to keep your certificate in and make sure you remember the password too
    • If you want to sign all your mail using your digital signature whenever the recipients also have a signature:
      • From the file menu of your Outlook, click on Options
      • Click on Trust Center
      • Click on Trust Center Settings
      • Click on Email Security
      • Tick the option saying “Add digital signature to all outgoing messages”
      • Tick the option saying “Add digital signature to all outgoing messages”
      • Tick the option saying “Send clear text signed messages when sending signed messages”. This will enable users without a digital signature to be still able to see your messages
      • Tick the option saying “Request S/MIME signed messages”
      • Click on Import/ Export digital ID
      • Import existing digital ID from a file
      • Browse and find the file you’d backed up when you installed the certificate using Firefox, and the password is the one you’d entered while exporting it
      • You’re done!
    • If you only want the current message to be signed and not all messages:
        • Create a new message, and click on options
        • Click on more options
        • Find the security settings, and click on it
        • Tick the option saying “Add digital signature to all outgoing messages”
        • Tick the option saying “Add digital signature to all outgoing messages”
        • Tick the option saying “Send clear text signed messages when sending signed messages”. This will enable users without a digital signature to be still able to see your messages
        • Change settings, and import your certificate here

So from now on, your messages will have a small certificate icon next to them, and on click, they’ll look like the image below.

Comodo Digital Signature

Pretty cool, huh? Anyway, I really don’t know why the university he’s applying to had this as a requirement, but I guess learning things, even as silly as this one, is worth it!

List comprehension and appending None values

Hey there,

So this is my favorite mistake, unfortunately not mine this time, but whenever I’m conducting code review I’ll always make sure to look for it ( yeah, I’m in QC and I’m evil)

Here’s a simple example of what can go wrong:

 

myList = []

for i in range(3):
internalList = []
for j in range(3):
internalList.append(j)
myList.append(internalList)

print(myList)

So we somehow mustered up the courage to go for list comprehensions ( again, we’re headbanging and can’t really decide why we do what we do! )


>>myList1 = []
>>myList = []
>>myList1.append([myList.append([j for j in range(3)]) for i in range(3)]) >>print(myList1)
[[None, None, None]]
>>print(myList)
[[0, 1, 2], [0, 1, 2], [0, 1, 2]]

Should’ve stopped with myList, eh?
So the last append is trying to append something thinking it’s a list or has a return value where’s there’s nothing. I’ve seen the same mistake in other scenarios as well, e.g. when doing regression testing the inputs cause the function to enter into branches which do not have a return value where’s they should.

A mistake with Python’s map function

This is just a short note on today’s mistake which caused me to go back and write about 7 unit tests just to find out where I’d made a mistake.
so, here’s a simplified version of my mistake:

upper_case_strings = map(lambda x: x.upper(), lower_case_strings)

see the problem? YUP, I needed to return a list whereas I’m just returning a map object.

upper_case_strings = list(map(lambda x: x.upper(), lower_case_strings))

I’ve noticed I do this sort of mistakes a lot. Thinking again, it might be a good idea for me, and all other metal-heads who are headbanging while coding, to go for TDD and also think about the return values while coding.

Testing C++ code using GoogleTest on Eclipse (MinGW ToolChain)

I’ve been trying to test a very simple piece of code using googleTest, and it took me 3 days to get it done. The main issue was for me to be able to set the environment. This post is on how to set the environment, followed by the list of mistakes I’d done.
Basically what I wanted to do was to keep my project separate from my tests, so that the tests would go into a separate project.

  1. Go to GoogleTest on GitHub where you can find documentation, code, and a couple of examples on how to use it. You can clone it into your local or download it.
  2. Open Eclipse. Let’s say we are testing a project called base_project, now you need to create another project called unit_test maybe.
  3. In your test project you need below to be created.One folder to hold googletest libraries, let’s call it googleTestLib, and a folder to hold your unit tests, let’s call it tests
  4. Using your command prompt, cd into where you have googleTest stored. In this path \googletest\googletest\scripts, there should be a file called fuse_gtest_files.py. Run the script, as usual, using .\ fuse_gtest_files.py {the project location}\ googleTestLib . Refreshing your unit_test project, googleTestLib should now have a folder called gtest with a gtest.h and gtest-all.cc file inside it.5- Right click on googleTestLib folder, go to resource configuration, and exclude it from “release”
  5. Right click on googleTestLib folder, go to properties, under C/C++ Build click on settings, find the include link under GCC C++ Compiler and click on it. Now add the folder (googleTestLib) as an include path
    Continue reading “Testing C++ code using GoogleTest on Eclipse (MinGW ToolChain)”