Solving the SC1:Math Bot Capture the Flag Challenge with Python

Summary

The MSP Tech Club puts on an annual CTF, available here. After stumbling upon the channel on IRC (#alexctf on Freenode) I felt compelled to compete in order to test the lessons that I’ve been learning throughout my OSCP course, the summary of which is below.

Continue reading

WordPress Security Basics

So, you’re using WordPress! What you might not yet realize is that WordPress currently powers approximately 26% of the internet powering sites for The New York Times, National Geographic, and Forbes (McGee, 2016) (ManageWP, 2016). Certainly, the reigning king of content management WordPress and its security is a continual target for security researchers, both good and bad.

Continue reading

A concise guide to effectively designing donation pages

It is very rare that people will google and come to a website with the specific intent to donate which means you’re typically trying to convert a user that is visiting your website for an alternative purpose – so keep things simple!

Continue reading

Updating a pre-existing Microsoft SQL table to have an identity column without losing data

You’ve created a Microsoft SQL Server table, added some data and then realised that integer column you created would be much better off as an identity column. You go to alter the table but SQL Server won’t allow you to change your integer column into an identity one without re-creating the table and losing the data… How to proceed?

The following is my regular workaround to the problem.

Continue reading

How to add an “Attachments” button on a SharePoint form without using Infopath

Why traditional SharePoint form design and not InfoPath?

For a very long time Infopath has been hailed as one of the better ways to develop SharePoint forms. It’s undeniable that InfoPath is fast, in many ways flexible and easy for more technical business users to maintain.

All of that said in 2014 Microsoft dropped the following bombshell:

The InfoPath 2013 application remains the last version to be released and will work with SharePoint Server 2016.

Source: Official MSDN blog entry.

As it appears InfoPath is nearing the end of its life we’ve begun developing SharePoint forms in a more traditional manner. We’ve used SharePoint 2013’s web compatibility to its fullest by using JavaScript for most of our interactions and ASP where needed. The outcomes have been very, very surprising. We’ve found we can do far more than we ever could with InfoPath. Forms are responsive making them mobile compatible (using our own CSS), adaptive to what the user enters and they look amazing.

One thing we have found is that users are still used to having an attachments button on their forms and haven’t adapted well to having to go to the ribbon to add attachments. As a reminder, this is the field that InfoPath would add to your SharePoint forms to allow users to easily add attachments:

SharePoint and InfoPath Attach file button

How do I add an attachments button to a traditional SharePoint form?

To add the attachments button to a traditional SharePoint form first open the library in SharePoint designer. For whatever reason SharePoint locks down the default ASPX form (typically titled NewForm.aspx) and creating a new one (and making it the default) will allow you to customize your form as you desire.

Once you have created a new form add the following to the page to add an equivalent button that duplicates the functionality of InfoPath:

This will present a basic button to attach files to your form. If you wish to further customize this to also list the attached files below it, the following should be used:

The final outcome will look something like the following (depending on how you adapt it for your own forms):

SharePoint Attach File Form Button

How to download files from a SharePoint Online Document Library

As SharePoint Online captures more and more market share people are going to start doing more and more with it.

One of the core challenges that I’m noticing is the struggle for developers in transitioning from server side code to using the client side object model (CSOM). There are a lot of ways to accomplish and this is just one example in many. This example assumes that the source document library has a column called Status. It will download files from that document library where the Status is equal to New and after download all of these files it will then update the status of those files to Downloaded.

Reversing a string in Python with Performance Benchmarking

Recently I’ve been putting a lot of time into brushing up my Python knowledge for big data projects and operations. For a task that’s so simple I’ve found reversing a string can be quite enlightening for how to better “think in Python”.

As an example, here’s how I would have previously reversed a string before really digging into the Python language:

Quite less than ideal!

After digging a bit further I learnt about slice notation in Python – and it’s amazing. This StackOverflow question serves as a good primer, here’s the core answer from that question for future reference as well:

There is also the step value, which can be used with any of the above:

The key point to remember is that the :end value represents the first value that is not in the selected slice. So, the difference beween end and start is the number of elements selected (if step is 1, the default).

The other feature is that start or end may be a negative number, which means it counts from the end of the array instead of the beginning. So:

So what does this mean for reversing a string? Actually, quite a lot – that means we can now take our original statement above and re-write it simply as:

But how about performance? Python is commonly used on big data after all. Let’s introduce a couple of other ways to accomplish this task in Python and then benchmark them against each other:

Another Python specific approach for this task would be the reversed() function

We could also use a generator function, one of the more friendly ways of writing this as it reads as it performs – join all the i-th-s elements of the string where i goes from the len of the string to zero.

We could also use a deque object:

But what about performance? Using timeit let’s quickly benchmark these against each other:

Original function

In [250]: %timeit reverse_codingo(“reverse”)
100000 loops, best of 3: 3.61 µs per loop

Slice Operator

In [243]: %timeit “reverse”[::-1]
1000000 loops, best of 3: 310 ns per loop

Reverse Function

In [241]: %timeit reverse(“reverse”)
100000 loops, best of 3: 3.98 µs per loop

Deque Reverse Function

In [244]: %timeit reverse_deque(“reverse”)
100000 loops, best of 3: 2.61 µs per loop

The clear performance winner in speed appears to be the slice operator, also the one which is syntactically the most simple once you’re familiar with it. Definitely an operator worth learning more about and including in the toolkit!

© 2017 Codingo

Theme by Anders NorénUp ↑