In the coming semester it is likely that I will T.A. a course in Python. Lately I've been researching the language and using it for my pet projects that never get finished, interviews, etc...
One thing I found interesting is writing a swap in function. For some sorting algorithms we often have to swap the values at two indices in an array, so this does come up fairly often. What I found especially interesting was that you could do this in one line using Python. Where in most programming languages you have to write something like...
In Python, this can be written as...
This is because Python evaluates assignments right to left. When the right hand side gets evaluated, Python creates a tuple (val_i, val_j) then assigns the variables in the left their corresponding tuple values.
Most experienced Python programmers already knew this, but I found it pretty cool. All credit for the knowledge goes to this stack overflow post.
Friday, December 2, 2016
Wednesday, November 23, 2016
Researching Encryption in Windows and C# .NET
I was recently tasked with researching different methods of encryption for a license management module within my company and thought it might be useful to write down some of my findings.
Cryptography has been around for a long time. Some of the more famous forms of old cryptography are in the Roman army, which used the "Caesar Cypher" to shift all letters to the left by three. "A" would become "X", "B" would become "Y", etc.
These days there are many more forms of data, and different ways to intercept it. Specifically we have data in-transit, and data at-rest.
For data-in-transit we use a public key private key method. The actual encryption of this method involves factoring extremely large numbers into their primes. If you're interested, this is a great video to watch.
With data-at-rest we use more complicated algorithms. In the Microsoft .NET library, these encryption methods are very well documented and held within the System.Security.Cryptography namespace. This includes methods for both in-transit and at-rest cryptography.
Within the namespace there are two main encryption methods, Rijndael and Aes. The Microsoft Recommended method of encrypting data-at-rest is the AES method because Rijndael will not work when the FIPS-compliant security setting is enabled on a windows operating system.
In conclusion, if you are encrypting a file, database, or some data on disk in a windows environment you should be using either the AesManaged, or AesCryptoServiceProvider classes from the System.Security.Cryptography namespaces.
Cryptography has been around for a long time. Some of the more famous forms of old cryptography are in the Roman army, which used the "Caesar Cypher" to shift all letters to the left by three. "A" would become "X", "B" would become "Y", etc.
These days there are many more forms of data, and different ways to intercept it. Specifically we have data in-transit, and data at-rest.
For data-in-transit we use a public key private key method. The actual encryption of this method involves factoring extremely large numbers into their primes. If you're interested, this is a great video to watch.
With data-at-rest we use more complicated algorithms. In the Microsoft .NET library, these encryption methods are very well documented and held within the System.Security.Cryptography namespace. This includes methods for both in-transit and at-rest cryptography.
Within the namespace there are two main encryption methods, Rijndael and Aes. The Microsoft Recommended method of encrypting data-at-rest is the AES method because Rijndael will not work when the FIPS-compliant security setting is enabled on a windows operating system.
In conclusion, if you are encrypting a file, database, or some data on disk in a windows environment you should be using either the AesManaged, or AesCryptoServiceProvider classes from the System.Security.Cryptography namespaces.
Tuesday, September 27, 2016
Fermat's Near Miss
A lot of people have heard about Fermat's last theorem. Originally proposed in the 1600s, the theorem was finally solved in the 20th century by a mathematician named Andrew WIles.
Fermat's theorem says that there are no solutions (x,y,z) to the equation x^n + y^n = z^n for n > 2. If you've studied math or physics at a university or in some cases high school level you have likely heard of it. Today I was reminded of an example from the Simpsons which is purported to show a solution where x^n + y^n = z^n. Specifically...
There we see 3987^12 + 4365^12 = 4472^12. And if you were to plug this into a handheld calculator, it would be correct!
So what is going on? How could Homer Simpson have a counter-example to Andrew Wiles proof? In fact, these numbers are so large that most calculators round the error off and they appear to be the same! X, y, z combinations like this that "solve" Fermat's last theorem are known as near misses. I was reminded of this interesting example by this video, but have also read it in this book.
Also of note, in the holy doughnut to filled in doughnut progression along the bottom of the chalkboard, Homer is "solving" a question in topology! Unfortunately, in topology, a doughnut and a sphere do not equate...
Fermat's theorem says that there are no solutions (x,y,z) to the equation x^n + y^n = z^n for n > 2. If you've studied math or physics at a university or in some cases high school level you have likely heard of it. Today I was reminded of an example from the Simpsons which is purported to show a solution where x^n + y^n = z^n. Specifically...
There we see 3987^12 + 4365^12 = 4472^12. And if you were to plug this into a handheld calculator, it would be correct!
So what is going on? How could Homer Simpson have a counter-example to Andrew Wiles proof? In fact, these numbers are so large that most calculators round the error off and they appear to be the same! X, y, z combinations like this that "solve" Fermat's last theorem are known as near misses. I was reminded of this interesting example by this video, but have also read it in this book.
Also of note, in the holy doughnut to filled in doughnut progression along the bottom of the chalkboard, Homer is "solving" a question in topology! Unfortunately, in topology, a doughnut and a sphere do not equate...
Monday, August 15, 2016
C# .Net Utility in WPF
I very recently had the opportunity to develop a simple tool in wpf and C# .Net to execute some procedural actions necessary to quickly make copies of our application. Surely there is an "easier" way to do this with windows system scripting, but for the sake of education and usability (we don't want our clients running windows scripts) we chose to write an executable.
Several things surprised me during the development. First, wpf has become much easier. The most useful resource I found was WPF MVVM In Depth by Brian Noyes. In his tutorial he builds WPF up from code-behinds and simple applications that take inputs and generate outputs. The most essential parts for me were the building blocks of implementing INotifyPropertyChanged and ICommand. This was good enough for my current application, but more complex applications meant to display and manipulate data will probably go into using ObservableCollections and defining sql server data sources.
This project, along with other personal things kept me very busy the last few weeks, though I hope to return to posting more frequently. I've now changed the blog name from "Daily Blog" to simply "Blog".
Several things surprised me during the development. First, wpf has become much easier. The most useful resource I found was WPF MVVM In Depth by Brian Noyes. In his tutorial he builds WPF up from code-behinds and simple applications that take inputs and generate outputs. The most essential parts for me were the building blocks of implementing INotifyPropertyChanged and ICommand. This was good enough for my current application, but more complex applications meant to display and manipulate data will probably go into using ObservableCollections and defining sql server data sources.
This project, along with other personal things kept me very busy the last few weeks, though I hope to return to posting more frequently. I've now changed the blog name from "Daily Blog" to simply "Blog".
Thursday, July 7, 2016
C# .NET and WPF
I recently had a terribly boring project in which I had to go through 27 pdf documents and compare copies word for word. That means reading a total of 54 documents and comparing for exact word for word copies. And no, they could not be done with pdf comparison tools, it was required that human eyes search through each document at some point.
In order not to burn out, I started a project in C#.NET and WPF on the side. What I found was that C# is one of the easiest languages there is. I was able to create classes and structures using the .NET toolset to model my data in about two hours. Then I tried to connect it to a WPF interface.
WPF is ridiculously difficult to "jump into". I found it really hard to get resources online, then half the resources said you need to use the prism library to do WPF correctly and encountered similar difficulty in finding prism examples. All the examples I found used code-behinds to bind data, which, from the Microsoft examples, are an antipattern. I really felt like there were more contradictory and dated examples of WPF and C#.NET code than there are of javascript (though I'm sure that isn't true).
In order not to burn out, I started a project in C#.NET and WPF on the side. What I found was that C# is one of the easiest languages there is. I was able to create classes and structures using the .NET toolset to model my data in about two hours. Then I tried to connect it to a WPF interface.
WPF is ridiculously difficult to "jump into". I found it really hard to get resources online, then half the resources said you need to use the prism library to do WPF correctly and encountered similar difficulty in finding prism examples. All the examples I found used code-behinds to bind data, which, from the Microsoft examples, are an antipattern. I really felt like there were more contradictory and dated examples of WPF and C#.NET code than there are of javascript (though I'm sure that isn't true).
Sunday, May 15, 2016
Friday, May 13, 2016
Simple Python Server
This is how you make a simple python server. It'll server index.html if you request the root, or whatever html file you request.
Subscribe to:
Posts (Atom)