Here I like to give a simple run-down to install all requirements to make Selenium available on a Raspi. Basically, we install first Firefox, then Geckodriver and finally Selenium and we are ready to go.
Before start, better to note that ChromeDriver does not support ARM processors anymore, therefore it is not possible to use Chromium with Selenium on Raspberry.
First, install system requirements. Update the system, install Firefox and xvfb (display server implementing X11);
sudo apt-get update
sudo apt-get install iceweasel
sudo apt-get install xvfb
Then, install python requirements. Selenium, PyVirtualDisplay that you can use for running Selenium with hidden browser display and xvfbwrapper.
sudo pip install selenium
sudo pip install PyVirtualDisplay
sudo pip install xvfbwrapper
Hope everything run well and now you can test the installation.
from pyvirtualdisplay import Display
from selenium import webdriver
display = Display(visible=0, size=(1024, 768))
driver = webdriver.Firefox()
Decorators are handy sugars for Python programmers to shorten things and provides more concise programming.
For instance you can use decorators for user authentication for your REST API servers. Assume that, you need to auth. the user for before each REST calls. Instead of appending the same procedure to each call function, it is better to define decorator and tagging it onto your call functions.
Let's see the small example below. I hope it is self-descriptive.
How to use Decorators:
Decorators are functions called by annotations
Annotations are the tags prefixed by @
### Decorator functions ###
print "Hello Space!"
print "Hello Cosmos!"
@helloCosmos # annotation
@helloSpace # annotation
print "Hello World!"
### Above code is equivalent to these lines
# hello = helloSpace(hello)
# hello = helloCosmos(hello)
### Let's Try
Especially, with the advent of many different and intricate Machine Learning algorithms, it is very hard to come up with your code to any problem. Therefore, the use of a library and its choice is imperative provision before you start the project. However, there are many different libraries having different quirks and rigs in different languages, even in multiple languages so that choice is not very straight forward as it seems.
Before you start, I strongly recommend you to experiment the library of your interest so as not to say " Ohh Buda!" at the end. For being a simple guide, I will point some possible libraries and signify some of them as my choices with the reason behind.
Python is a very bright language that is used by variety of users and mitigates many of pain.
One of the core functionality of Python that I frequently use is multiprocessing module. It is very efficient way of distribute your computation embarrassingly.
If you read about the module and got used, at some point you will realize, there is no way proposed to pass multiple arguments to parallelized function. Now, I will present a way to achieve in a very Pythonized way.
For our instance, we have two lists with same number of arguments but they need to be fed into the function which is pooling.
Here we have self cover code:
At that post, I try to illustrate one of the use case of comparison overriding for std::sort on top of a simple problem. Our problem is as follows:
Write a method to sort an array of strings so that all the anagrams are next to each other.
Continue reading Sorting strings and Overriding std::sort comparison
Suppose you have a vector array at C++ and you want to extract a sub-vector given some range. There is a simple illustration one of the possible way to do.
As a rusty researcher at coding, I spend some to revise my algorithm knowledge. At some part, I coded basic sorting algorithms in Python as a good and concise practice (even the result is not very efficient as C or C++). However you would like to check the code and clean up your memory or edit the code in some efficient manner. Continue reading Fundamental Sort Algorithms in Python
Here is one again a very intricate problem from Project Euler. It has no solution sheet as oppose to the other problems at the site. Therefore there is no consensus on the best solution.
Below is the problem: (I really suggest you to observe some of the example sequences. It has really interesting behaviours. 🙂 )
The following iterative sequence is defined for the set of positive integers:
n n/2 (n is even)
n 3n + 1 (n is odd)
Using the rule above and starting with 13, we generate the following sequence: Continue reading Project Euler - Problem 14
Here we have another qualified problem from Project Euler. You might want to work out the problem before see my solution.
The basic idea of my solution is to not use all the digits of the given numbers, instead extract the part of the each number that is necessary to sum up to conclude the first 10 digits of the result. I try to explain my approach at the top of the source code with my lacking MATH english. If you have any problem for that part please leave me a comment. Continue reading Project Euler - Problem 13