Queue in Python - Part 2

Double ended queues with deque The deque class in the collections module makes it easy to create deques or double ended queues. Deques allow you to append and delete elements from both ends more efficiently than in lists. Import the module: from collections import deque Instantiate deque: d = deque() Append to right and left: d.append("b") d.appendleft("a") print(d) # output is: deque(['a', 'b']) In the same fashion, elements can be deleted (popped) :...

November 2, 2016 · 1 min · Rezha Julio

Queue in Python - Part 1

Best way to implement a simple queue A simple list can be easily used and implemented as a queue abstract data structure. A queue implies the first-in, first-out principle. However, this approach will prove inefficient because inserts and pops from the beginning of a list are slow (all elements need shifting by one). It’s recommended to implement queues using the collections.deque module as it was designed with fast appends and pops from both ends....

November 2, 2016 · 1 min · Rezha Julio

Fix Java Unsupported major.minor version 52.0 on Ubuntu

Today when I run gradle test, I hit Unsupported major.minor version 52.0 error. It comes when you are trying to run a class compiled using Java 1.8 compiler into a lower JRE version e.g. JRE 1.7 or JRE 1.6. Simplest way to fix this error is install the latest Java release i.e. Java 8 and run your program. The Ubuntu archives have multiple versions of OpenJDK available. One of these is designated as the default and this has the package names default-jdk and default-jre....

July 12, 2016 · 1 min · Rezha Julio

Enable Spark Context on Your Ipython Notebook

When you’re trying spark with its python repl, it’s really easy to write stuff using simple function or lambda. However, it will be a pain in the ass when you’re starting to try some complex stuff because you could easily miss something like indentation, etc. Try running your pyspark with this command IPYTHON_OPTS="notebook" path/to/your/pyspark It will start an IPython Notebook in your browser with Spark Context as sc variable. You could start using it like this:...

June 25, 2016 · 1 min · Rezha Julio

Fix GDM Service Can't be Enabled on Arch Linux

Today I just changing my desktop environtment from XFCE to Gnome 3. However GDM service always failed to be enabled. Everytime I ran sudo systemctl enable gdm, it always return Failed to execute operation: File exists. This caused by another display manager still enabled, but I don’t know which one. Fortunately, running sudo systemctl enable gdm -f will force GDM to be enabled and another display manager will be disabled....

February 11, 2016 · 1 min · Rezha Julio