Hashing

In the last post we talked about Maps. We learned that Maps can be referred to as dictionaries, associative arrays, etc. Sometimes you will also hear Maps or Sets being referred to as a Hash ( You will hear  the likes of HashMaps or HashSets ). These types of key/value pair collections, are “Hash-bashed Data Structures”. What is hashing? In my very first post on data structures, i mentioned that Linked Lists are faster at adding data quicker to a collection, than it is at retrieving. Hashing is a way of storing data that makes retrieval and access extremely fast (Runtime complexity of O(1) for both retrieval, access, and deletion operations). Our collection is stored in a data structure known as a hash-table. This table is what makes data retrieval and storage so fast. When we looked at Maps in the last post (or even linked lists), anytime we wanted to find data, we had to traverse the whole collection in order to find it. Given a key, we would enumerate the whole thing for its value. Therefore it would take a long time we had a huge collection. Hash tables can be used to solve this problem. When using hash tables we can find data in the shortest amount of time because we already know which position in the table the value is stored. Like an array, we can retrieve the value at position 4 instantly. But as we said in the previous post, writing a statement like state[4] does not convey meaning (number index based structure, what if we don’t know its location?). When we tried to solve this problem with maps, we looked at how to write data structures so we could retrieve them using syntax that looked more like this state[‘NY’]. The only disadvantage here is we still would have to enumerate the entire object to get its value (though the syntax was nicer). Hashing employs a technique using something called a hash function. Given a key, it is passed to a function, and a value is returned right away (the key is hashed into a value). That value is used as an array index(in the hash table to retrieve values). The value of the index can be retrieved instantly because of its array nature. Read More

WordPress VPS Permalinks 404 error

I recently moved my blog off Godaddy because i was having a whole bunch of issues when writing posts. I believe Godaddy sets a block on how many times you can publish. Perhaps their servers takes a hit from all the publishers writing content. If they are like me they save every 2 minutes! What happens is that after a few saves on your post, you begin to get server internal errors(504 Gateway Timeout Error). Go daddy claims it was my ISP but reading complaints on other forums i found out that many bloggers had this issue. So it wasn’t an ISP issue. I took action right away. I decided to host my own WordPress (and boy was it a nightmare). Found a VPS solution and installed WordPress from a backup i have made when i was using Godaddy. The only problem i had was my posts now had urls that were not so friendly. Updating permalinks to use the postname format wasn’t working. I would get a 404 error. I decided to document the steps i took to resolve this issue. Hope it works for you (worth a try if you have having similar issues). If you are using a VPS and want to install or reinstall WordPress, here are some steps that might help you. I will talk about reinstallation as well at the end of the post. I assume you are comfortable with the CLI (of course if you are using a VPS solution, that is the only way). Read More