Bit manipulation (twidling) is a popular subject in many interviews.This one tries to find the most significant bit set (i.e. equal to 1) in a number.We will present the obvious solution, one that works in O(n).It is always a good approach to present a first-solution, and then be able to … Continue reading
The following code demonstrates an operation on lists.It accepts 2 lists, and prints the values of items present in the first list, but not in the other.It uses Javascript built-in hash table implementation (built into all objects).The code includes other functions to function listDiff(list1, list2){ var hash={}; // This is … Continue reading
Consider the following line: printf(“%d\n”, (3,4,5)); The value of the expression looks strange: 3 numbers with comma separating them. The Comma Operator We tend to skip it as we learn the language, but it’s there – the comma operator.The value of (3,4,5) is the rightmost expression, which is 5.So, what … Continue reading
(Makefile (make) tutorial – part 1 based on the GNU make manual) When we have a large project, compiling all modules can take a lot of time.From the manual:“The make utility automatically determines which pieces of a large program need to be recompiled, and issues commands to recompile them.” Make … Continue reading
What linux type am I running? What is my host name? In systems that use systemd, it is easy. Just use the hostnamectl command: linux> hostname yuval-Lenovo-G510 linux> hostnamectl Static hostname: yuval-Lenovo-G510 Icon name: computer-laptop Chassis: laptop Machine ID: c811090bea744c87969c773662753a37 Boot ID: 245ac2c4a50442b6af159e2329c06fa3 Operating System: Ubuntu 18.10 Kernel: Linux 4.18.0-25-generic … Continue reading
You can use the nload command (you’ll have to install it first). Run nload, then use the arrow keys and you can choose the network device to view current traffic: … Continue reading
View the top %cpu process monitor network traffic running now What is my linux system and hostname? … Continue reading
How would you view the top cpu/memory consuming process? linux> ps -eo uid,pid,%cpu,%mem,comm | sort -nrk 3,3 | head -n 3 1000 19380 3.0 4.0 Web Content 1000 19132 2.3 2.4 firefox 1000 18202 2.3 6.8 java linux> Explanation: We use 3 commands pipelined to each other ps command … Continue reading
The following questions are all based in Python 3. Explanations are short, so you may have to read further if you don’t understand the answer. 1.What will the following code print ? Explain your answer. x=100 def outer(): def inner(): global x x=9 print(“inner x: “, x) x=15 inner() print(“outer … Continue reading
(* there is no such thing) Python is a language for many people. This is why my Python students come from various background environments. On the one side, I meet students with very little experience in programming. These guys need to learn the basics of algorithmic thinking (e.g: how do … Continue reading