Monday, 23 October 2017

Parser for Sample Language

Creation of Parser for a Sample Language using Lex &Yacc.


Basic Version for Parsing simple c++ code

Sunday, 22 October 2017

Saturday, 21 October 2017

Concurrent Quick Sort Class in OpenMP

Q: Design a class for concurrent quicksort in C++.

Decided to use OpenMp since Pthread doesn't work well with classes, not without ton's of efforts.

Friday, 20 October 2017

Recursive & Iterative Binary Search in Scala

Scala

My very first program in Scala. And I don't find Scala close to Java. I am quite used to Java and C++ and rather find the two more close as very as programming is concerned.

Scala however is closer to Java since scala code is converted to Java Bytecode and the executed.

Program

I used 2 classes a Binary Search class & a Tester object
. An object is more like a singleton class according to my understanding. 
The BinarySearch class has constructor which accepts a sorted array.
It has 2 functions 
  1. A Recursive Binary Search
  2. An Iterative Binary Search.

Monday, 18 September 2017

Dark Conky Theme

I recently worked on a dark desktop theme for conky, the result was a super cool desktop theme. It is completely modular and consists of a number of widgets whose position can be easily configured using conky manager. I actively make additional commits to this project, add new widgets and fix any bugs that I find.

Screenshot




Saturday, 26 August 2017

Launch Applications Faster :Preload in Linux

Wanna speed up Launch time of Applications in Linux then read on.

Preload is a package that enables a service which can preload libraries required for Applications in the Ram. Obviously reading from ram is way more faster than reading from the disk. That's where your system gains up speed and can launch applications faster.


Sunday, 16 July 2017

UVa 1203 - Argus C++ map and priority queue

Question

Solution to this UVa problem by using simple data structures like map and priority queue.


Solution

Since priority queue stores data in descending order but we needed ascending order, we simply stored negative instead of positive. Alternatively we might have to write our own comparing function.

Friday, 14 July 2017

Thursday, 13 July 2017

Competitive Programing: Vowel Substring

Q: Given a string find all the number of sub-strings which contain all the five vowels at least once.


It is solved in two ways:

  1. A slightly more complicated linear scan method
  2. By generating all the sub-strings and then checking whether or not it satisfies the our requirements. (brute force)

Tuesday, 11 July 2017

UVa 00637 - Booklet Printing

This problem is an adhoc problem that asks to you to design a system to print folding booklets. The problem description and test cases can be found here.

Saturday, 8 July 2017

Record internal speaker audio in Linux

Record internal speakers in linux
Recording internal audio in Linux
The other day I came up with this brilliant idea to use my mobile phone as a bluetooth speaker for my laptop. I decided this could be easily accomplished once we had access to the whatever the audio card has, save it and stream it on tcp or udp port across a network connection to my mobile phone by piping it netcat after conversion to wav.

Sounds perfect, except the fact that it has been already implemented. Meanwhile, through numerous visits to stackoverflow and askUbuntu I finally discovered a cool new way to record audio.


Tuesday, 4 July 2017

Uva 278 - Chess

This problem  is one of the best ad-hoc problems I have come across - simple but thought provoking. It asks you to the maximum number of  rooks, queens, kings or knights you could place on n*m chess board such that no piece attack another.
Given that 4<=m,n<=10.

Uva 11586 - Train Tracks

This is a solution to this Ad Hoc Problem on uva online judge.

Monday, 3 July 2017

Summing the digits of a number in C++

Q: This is a simple ad-hoc problem which asks to sum up the digits of a number repeatedly until the sum is less than 10. We are required to stop the program when input given is 0.


Saturday, 10 June 2017

Nary Search Using OpenMP

It's been quite a while since I last posted. This post shows how conduct a nary search on an array using OpenMP.

OpenMP


Allows to create threads in C by simple pragma directives, this is one of the easiest ways to get threading done. In case you like the way threading is done here you might want to take a look at the various directives offered by OpenMP for parallel processing.


N-ary Search


You might have worked earlier with maybe ternary, or at least binary search. In this kind of a search we divide the sorted array into n parts at each stage and then perform the search.

Sunday, 2 April 2017

Generating Permutation in Python

This is the best way to generate permutations in python.

from itertools import permutations

j="1234"
for i in permutations(j):
    print "".join(i)


Saturday, 1 April 2017

Ditch Ubuntu Software Centre

Most noobies to Linux love Ubuntu Software. It one of the best things of Ubuntu, a preinstalled GUI package manager.

The Other thing that most guys love is the Software Updater it is extremely fast and efficient when compared to its Windows Counter Part.

Experts

However experts should not be using Ubuntu Software. One of the biggest and main reason is the fact that it is buggy and it hangs even on modern hardware.
It is extremely slow compared to its terminal alternative. I have used GUI package managers on various Arch Distros, they are far more efficient then Ubuntu's Software Centre.

Secondly it has a tendency to acquire a lock and then never release. Software center was taught by canonical lock n key, however turns out it learned from its distant friend Windows lock n hang. 

Usually when it decides to play this game of lock n hang. You need to use ps -aux | grep apt. To find out the process and kill it with kill -9 pid. Finally you need to ensure that the database is not corrupt by use sudo dpkg --configure -a. Failure to do so can have disastrous consequences. So why not ditch it all together ?



Thursday, 30 March 2017

A request to Stop Blocking Adds

I have lately noticed that there has been considerable loss of revenue due to UC Browsers ADD Blocking.

Being a technology blog I expect users to be tech-savy and block adds. However killing revenue for a blog barely showing three adds per page is not justified. Please switch to better browser that doesn't block adds.

UC Browser has been know to be unsecure and compromises user data. This is another reason for you to make the switch. If you still decide to use UC Browser do disable the add-blocker.

Its a race of Add-blockers and Anti-Add-Blockers. The day Add-blockers win, you will lose. No revenue to bloggers, means no more posts. No more posts and no more free knowledge.

UC Browser is no longer supported by Programing Wonders!.

FAD-Facial Age Determinator

FAD - Facial Age Determinator is a Python based software to determine the age of people using skin texture. It determines the age group of people and classifies them into 4 groups, kids(1-10), young(10-25),adults(25-50),seniors(51+).

Applications

  • Vending Machines for cigarettes and beer
  • Age Appropriate Advertisements
  • Targeted Advertisements on Bill Boards
  • Age Restricted Entry Zones(Bars, Adult Cinema)
  • As a filter in other Facial Processing Systems
  • Human Robot Interactions
  • Smart Car System Adaptive Behavior(Determining whether to apply brakes based on age group of pedestrian crossing.)
  • Elderly Assistance Systems
  • Enhanced Security for Kids Only Zones etc 

Implementation Details

Sunday, 26 March 2017

The Fastest and Easiest Way to Install OpenCv for Python on Ubuntu

Python burning gif
When I first installed OpenCV I used an article on which installed opencv from source. However this is unnecessary and time consuming.

The entire process is too complicated. You will need to use that process only if
  1. You are using the latest OpenCV features
  2. You need Python 3 bindings
Before building from the source I highly recommend you trying the method described in this post. It is quick and simple.

Saturday, 25 March 2017

Persistance in Python

Recently I was training a dataset for Facial Age Determination. A considerable amount was spent each time I launched my script.

The Reason: It was retraining the whole dataset at each launch.

Solution : Saving the dataset into a file loading it back.


Serialization in Python


Serialization allows you to save objects to a file and reload them. I have worked with Java and Python Serialization, and with python its a piece of cake.

There are two options

  1. Pickle
  2. CPickle
You usually would want to use cpickle as its faster. It can be over a thousand times faster.

I would be thus demonstration cpickle store and load through this post. The steps for pickle are the same. Just import pickle instead of cpickle and you are good to go.


Thursday, 23 March 2017

Feret Database PreProcessing Script

I am currently working with the Feret Database on Age Determination using Frontal Facial Images using KNN and LBP in Python 3 and OpenCV.

However the Feret Database comes in a tar which when extracted contains a large number of ppm files in bz2 archives which need to be converted into jpegs before any further processing can take place.

I wrote this script in case. I am sure it will be useful to other people working with the Feret Database.

Tuesday, 21 February 2017

Speed up your Make

How to speed up your make process on a multi core machine.

The Make Process


Whenever you are using make without arguments just a single core of your machine is used. A single process is created, which runs on one core.

No matter what kind of insanely awesome working computer you might have you are simply going to get the performance of a single core unless you create multiple process.

The make command allows you to specify the number of processes using the -j argument


Tuesday, 14 February 2017

Write a C++ program to read the HTTP header and analyze the parameters.

Q: Write a C++ program to read the HTTP header and analyze the parameters.


Test Environment


Dependencies: Libcrafter
OS: Fedora 20
Testing Environment : Switched Lan with Promiscuous Mode On for NIC


Code

Friday, 10 February 2017

FireFox Shortcuts Essentials

While There are tons of post or cheatsheets on firefox shortcuts, this post will just cover the essentials. These are the shortcuts that you actually need to know to increase your productivity. We will explore some of the less known tools like

  • Caret Browsing
  • Page Info
  • Open Address Bar Link in New Tab
  • Tab Navigation using KeyBoard


Note:This article has been written for linux. So if you are using windows just note that super means start button. And not all the shortcuts might be applicable to you. I would still suggest you read it since most of them would be applicable. You will definitely learn a new thing or two.

Let's get going with firstly the File Menu

File Menu

  1. New Window: Ctrl + N
  2. Private Window: Ctrl+ Shift + P
  3. Save a Page : Ctrl +S
  4. Print a Page : Ctrl + P
Most of the people should be familiar with New Tab , New Window and Printing a Page. In case, you are not, no worries, just go ahead and press the shortcut keys to get an idea. We will look a bit into the Private Window and Saving a Page.

Private Window

This opens a window similar to the New Window option but with one major difference. It doesn't remember your history. This particularly great when logging in accounts for one-time access. No browsing history , cookies and sessions are stored. Also FireFox comes with this legendary Do Not Track Me features, which means while you are using Private Browsing all tracking by websites should be rendered useless. 

Note: Private Browsing does not increase security in any way. You are still vulnerable to security threats.

Save a Page

This allows you to save a page to view it offline. You can carry it on your pendrive. Whenever you want to open it just open it by double clicking it. You can use another browser to open the website. All images and css files or script files are stored in a separate folder called website_name_files. This is almost as good as making a page rip.

Thursday, 9 February 2017

Multi-Threaded Echo Server in Java

Implement a Multi-threading application for echo server using socket programming in JAVA.

Implementation


Server Side

  1. Create a Server Class implementing the Runnable interface
  2. In the run method, create a data input and output stream with a client.
  3. In the main method write code to create a ServerSocket at a give port.
  4. Create a infinite loop, to accept server connection from clients and launch a thread.
  5. In the thread, when we catch an IOException we use return to quit. IOException occurs when the pipe is broken, that is, the client leaves.
  6. Additionally we have give id's to identify when a client joined and left.
Client Side
  1. Establish connection with server
  2. Create Input and output streams for interacting with the server
  3. Create a infinite loop to send messages to echo server
  4. Quit the loop on get quit as an input.

Monday, 6 February 2017

MultiThreaded Calculator in Lisp

Implement an calculator (64 bit Binary Multiplication) application using concurrent lisp.

Before we get to the Implementation of the Program, get your Lisp Programing Environment Setup. In case you haven't yet set it up , here's an article about the same.

Implementation


We have created a text based interface for the calculator which accepts two numbers. The result of addition , subtraction , multiplication and division in calculated.

Input: Accepted in binary
Output: Displayed in binary

Functions
4 Lamda Function to compute each of the operations
btd: This function is for binary to decimal. Converts a binary to decimal


Code


Wednesday, 1 February 2017

Finding Java Home in Ubuntu

Often Ubuntu Users struggle with setting up of Apache Tomcat, Hadoop and other Java Technologies.

The reason being Java Home Error.

It is Either not set or incorrectly set due to mismatch in the java variant.

Java Variants

The java installation in Ubuntu comes in two ways

  1. Open Jdk
  2. Sun/Oracle Jdk
Always use the second one if you are working with android.

The Fix



The easiest way to fix this is to use the update-java-alternatives command

sudo update-java-alternatives -l

This will give you the java home.

Use this to java home in your config File.

Whenever updating apend a /jre at the end.

Screenshot


how to find java home ubuntu
update-java-alternatives
Example in this case value for Java_Home will be
/usr/lib/jvm/java-8-oracle/jre

Thursday, 26 January 2017

PrgWonders Android App

PrgWonders proudly releases a new Android App.

A more efficient and faster way to view our blog.
Whether you are travelling or at the examination centre.
Whether or not you have a computer to access our blog.
You can now Learn from the Experts on the Go!

  • Get notified on Updates
  • Data Saving Features
  • Allows to Bookmark Articles
  • Remember your read and unread Articles.
  • Quick Links to quickly browse our Blog
  • Continuously Updated 
  • In-app Browser for faster & efficient Browsing
  • A cool Dark Theme for Nocturnals
  • Switch Layouts as per Choice
  • Automatic Sync
  • View Saved Rss Streams Offline
  • Fully Customisable Settings
Give it a try !

Links



Our Android App Dedicated Page:
https://prgwonders.blogspot.in/p/android-app.html


Spread the Word !

Wednesday, 18 January 2017

Schedule a Shutdown in Linux

Scheduling a Shutdown in Linux, unlike Windows is a piece of cake.

The Windows Way

  1. Create a bat file executing run/win32/shutdown.exe.
  2. Schedule this using Windows Schedule Manger

Linux Way

Linux offers you tons of ways, forget at command or even cron. You can achieve this in one single command.

Read-only file system Error In Pendrive

The Dreaded Issue


Often you come across errors in linux with storage devices and the one of the most common and dreaded one is the following one
Read-only file system

Here are a few google search suggestions that pop up the moment you begin typing read-only filesystem.

  1. Fedora pen drive read-only
  2. pen drive read-only Ubuntu
  3. pen drive read-only Problem



I have seen people using several distros constantly complaining due to this issue.
Some of the most reputed forums offer horrible fixes to this issue. The solutions offered by these forums are often over complicated.

We will look into two simple approaches to this problem.


  1. The Naive Method
  2. And Geek Method


The Geek Method is hell lot a faster and looks really cool , or rather should I say geeky.

Sunday, 15 January 2017

Adds & Changes

Adds Suck

Programing Wonders knows that adds suck. Adds are however a good way to encourage content providers to provide content. Unfortunately Programing Wonders is no different. Meanwhile we are looking at other means to monetise the blog, without affecting user experience.

Friday, 13 January 2017

Creating a Bootable Usb for Ubuntu 16.04 using Ubuntu

After a recent failure of system due to bad sectors in hard disk. I decided to upgrade my system to next LTS. Welcome 16.04.

If you are using Ubuntu Os to create the bootable usb here are your options.

  1. Startup Disk Creator
  2. Unetbootin
  3. mkusb

Thursday, 12 January 2017

Simulation of Lift Using Led, Switches and Beagle Bone Black

Introduction

This is a simulation of working of lift using beagle bone black and python. The position of lift will be indicated using led. Switches will be used as lift buttons.

Wednesday, 11 January 2017

Accessing Python interpreter in Beagle Bone Black

  • Ensure that you have properly connected the Beagle Bone Black to computer using USB cable.
  • From terminal escalate your privilege level to administrator/root.Use the switch user command. Type the root password when prompted.
       user@comp:~$ su
  • Now to gain access to Beagle Bone Black use ssh command. The ip address is 192.168.7.2.
      admin@comp:/home/user# ssh 192.168.7.2

Note:In case of any issues during while using secure shell clear the contents of known_hosts files used for ssh.
Location: /root/.ssh/

  • Once you gain access to Beagle Bone Black. Fire up the python interpreter by  typing in the following command
       root@beaglebone:~# python

  • You will get a python prompt and you are good to go.

Monday, 2 January 2017

Lisp Programing Environment Setup in Ubuntu

Package Installation

Packages for Lisp
Lisp Package Required

If you are new to Lisp programing , here's the packages that you need to install.

  • emacs
  • slime
  • sbcl
Installation commands for the same are