Homebrew on MAC OS (Yosemite) Update

After installed homebrew, when you run any “brew ¬†command”, If you keep getting this error:

Homebrew requires Leopard or higher. For Tiger support, see:

Do the following step to rectify this error.

Edit the brew.rb file to get this : (Which may be at /usr/local/Library)

Find following lines

  abort <<-EOABORT.undent
    Homebrew requires Leopard or higher. For Tiger support, see:

Do following changes

if MACOS and MACOS_VERSION < 10.5 and MACOS_VERSION != 10.1
  abort <<-EOABORT.undent
    Homebrew requires Leopard or higher. For Tiger support, see:

And yeah you done. Enjoy ūüôā


How to implement system command using python

In this post I will show you that how you can exactly implemented system command using python.Here we use for example ls -l command. When I use this command in terminal it gives me following output

Harshs-MacBook-Pro:scripts harshkothari$ ls -l
total 32
-rw-r--r--  1 harshkothari  staff    13 Jul 23 02:33 demo.ini
-rw-r--r--@ 1 harshkothari  staff  1864 Jul 23 04:30 filesread.py
-rw-r--r--  1 harshkothari  staff  4121 Jul 23 04:30 langtofontmap.json

Now this command we can implement by following methods using python ūüôā

  • os.system("command with args") passes the command and arguments to your system’s shell. This is nice because you can actually run multiple commands at once in this manner and set up pipes and input/output redirection.
    os.system("command < input_file | anothercommand > output_file")
    However, while this is convenient, you have to manually handle the escaping of shell characters such as spaces, etc. On the other hand, this also lets you run commands which are simply shell commands and not actually external programs. http://docs.python.org/lib/os-process.html

    >>> import os
    >>> os.system('ls -l')
    total 32
    -rw-r--r--  1 harshkothari  staff    13 Jul 23 02:33 demo.ini
    -rw-r--r--@ 1 harshkothari  staff  1864 Jul 23 04:30 filesread.py
    -rw-r--r--  1 harshkothari  staff  4121 Jul 23 04:30 langtofontmap.json
  • stream = os.popen("command with args")¬†will do the same thing as¬†os.systemexcept that it gives you a file-like object that you can use to access standard input/output for that process. There are 3 other variants of popen that all handle the i/o slightly differently. If you pass everything as a string, then your command is passed to the shell; if you pass them as a list then you don’t need to worry about escaping anything.¬†http://docs.python.org/lib/os-newstreams.html
    >>> import os
    >>> print os.popen('ls -l').read()
    total 32
    -rw-r--r--  1 harshkothari  staff    13 Jul 23 02:33 demo.ini
    -rw-r--r--@ 1 harshkothari  staff  1864 Jul 23 04:30 filesread.py
    -rw-r--r--  1 harshkothari  staff  4121 Jul 23 04:30 langtofontmap.json
  • The¬†Popen¬†class of the¬†subprocess¬†module. This is intended as a replacement for¬†os.popenbut has the downside of being slightly more complicated by virtue of being so comprehensive. For example, you’d say
    print Popen("ls -l", stdout=PIPE, shell=True).stdout.read()
    instead of
    print os.popen("ls -l").read()
    but it is nice to have all of the options there in one unified class instead of 4 different popen functions. http://docs.python.org/lib/node528.html

    >>> from subprocess import Popen, PIPE
    >>> print Popen("ls -l", stdout=PIPE, shell=True).stdout.read()
    total 32
    -rw-r--r--  1 harshkothari  staff    13 Jul 23 02:33 demo.ini
    -rw-r--r--@ 1 harshkothari  staff  1864 Jul 23 04:30 filesread.py
    -rw-r--r--  1 harshkothari  staff  4121 Jul 23 04:30 langtofontmap.json
  • The¬†call¬†function from the¬†subprocess¬†module. This is basically just like the¬†Popen¬†class and takes all of the same arguments, but it simply wait until the command completes and gives you the return code. For example:
    call(["ls", "-l"], shell=True) http://docs.python.org/lib/node529.html

    >>> from subprocess import call
    >>> call(["ls", "-l"], shell=True)
    demo.ini                filesread.py            langtofontmap.json
  • Using command module http://docs.python.org/2/library/commands.html
    >>> import commands
    >>> commands.getstatusoutput('ls -l')
    (0, 'total 32\n-rw-r--r--  1 harshkothari  staff    13 Jul 23 02:33 demo.ini\n-rw-r--r--@ 1 harshkothari  staff  1864 Jul 23 04:30 filesread.py\n-rw-r--r--  1 harshkothari  staff  4121 Jul 23 04:30 langtofontmap.json')
    >>> commands.getoutput('ls -l')
    'total 32\n-rw-r--r--  1 harshkothari  staff    13 Jul 23 02:33 demo.ini\n-rw-r--r--@ 1 harshkothari  staff  1864 Jul 23 04:30 filesread.py\n-rw-r--r--  1 harshkothari  staff  4121 Jul 23 04:30 langtofontmap.json'
  • The os module also has all of the fork/exec/spawn functions that you’d have in a C program

Hope this will help you ūüôā

Pass Random variable to shell script rather then $1 or $2 using php

Here I am showing you how can you pass the random variable to shell script. ( i.e like $uname ūüôā )

You can receive data using $1 or $2 variable but you can’t directly receive data into $uname or any random variable.
Here is my bash file demo.sh

echo $uname

Now I have to pass $uname variable so directly using this php function you cant do this

exec("sh demo.sh harshkothari",$output);

You have to send it via environment variable . This is simple code snippet how you can you pass this. php file name is shell.php

$uname = 'harshkothari';
putenv('uname='. $uname); //put environment variable uname 
exec("sh demo.sh",$output); //execute command
echo($output[0]. "\n"); //print return value

$output will return the last line of output and it will show like this

Harshs-MacBook-Pro:lcmapiuse harshkothari$ php shell.php 
Harshs-MacBook-Pro:lcmapiuse harshkothari$ 

Here is snapshot of terminal output

Output of php script, passing random variable to shell script

Output of php script, passing random variable to shell script

OpenCV on your MAC – Easy to install and Configure



OpenCV¬†(Open Source Computer Vision Library) is a¬†library of programming functions¬†mainly aimed at real-time¬†computer vision, developed by¬†Intel, and now supported by¬†Willow Garage¬†and Itseez. It is free for use under the¬†open source¬†BSD license. The library is¬†cross-platform. It focuses mainly on real-time image processing. If the library finds Intel’s¬†Integrated Performance Primitives¬†on the system, it will use these proprietary optimized routines to accelerate itself.

Here in this BlogPost I will explain you to install OpenCV(version 2.3, 2.4) on your MAC ūüôā

There are two way to build openCV on your MAC.

1. You can use MacPorts

For this first you have to install MacPorts.¬†The easiest way to install MacPorts on a Mac OS X system is by downloading the dmg for¬†Mountain Lion,¬†Lion,¬†Snow Leopard¬†orLeopard¬†and running the system’s Installer by double-clicking on the pkg contained therein, following the on-screen instructions until completion. Installation package is here.

After installing MacPort you have to update it to latest version.

$ sudo port selfupdate

Now you can install OpenCV by running following command

$ sudo port install opencv

If you want to install python building

$ sudo port install opencv +python27

or with python 2.6

$ sudo port install opencv +python26

or with QT

$ sudo port install opencv +qt4

So by this way you can install OpenCV in your MAC OS.

2. You can use CMake

By using CMAKE you can also install OpenCV on  your mac. For that first you should have to install CMake, which thankfully comes with Mac binaries Рso that was easy. You can download .dmg file here.

After installing CMake you have to download the OpenSource Package that you can download by clicking here.  Now you have OpenCV-2.4.3 ter.bz2 and unzip to folder. Now open terminal and go to that folder and write following commands in Terminal.

$ mkdir build

$ cd build

$ cmake -G "Unix Makefiles" ..

$ make -j8

$ sudo make install

Now You have done. Congrats you have installed OpenCV on your MAC ūüôā

Now you can check by doing following thing.

GO to TerminalType Python

Now type

>>> import cv

Now if it run without any error then \m/ but if you encountered with following error

>>> import cv
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
ImportError: No module named cv

Then close python by pressing ctrl + D key and now you have to run following command

 $ export PYTHONPATH=/usr/local/lib/python2.7/site-packages/

after running this command restart the Terminal and then open python and import cv this will work ūüôā

If you have any doubt or problem then you can comment here. Thanks.

CoffeeScript – The Awesome way to write JavaScript

Do you struggle with Braces and semicolon in writing code of JavaScript. There is a solution of this problem and that is – CoffeeScript. ¬†In this post I’ll explore ¬†CoffeeScript¬†– a minimalistic language that compiles to JavaScript.

CoffeeScript – The Awesome way to write JavaScript



CoffeeScript is a little language that compiles into JavaScript. Underneath all those awkward braces and semicolons, JavaScript has always had a gorgeous object model at its heart. CoffeeScript is an attempt to expose the good parts of JavaScript in a simple way.

The golden rule of CoffeeScript is:¬†It’s just JavaScript. The code compiles one-to-one into the equivalent JS, and there is no interpretation at runtime. You can use any existing JavaScript library seamlessly from CoffeeScript (and vice-versa). The compiled output is readable and pretty-printed, passes through¬†JavaScript Lint¬†without warnings, will work in every JavaScript runtime, and tends to run as fast or faster than the equivalent handwritten JavaScript.

The language adds¬†syntactic sugar¬†inspired by¬†Ruby,Python¬†and¬†Haskell. NO¬†braces and semicolons.¬†Since March 16, 2011, CoffeeScript has been on¬†GitHub‘s list of most-watched projects,¬†and as of 29 August 2012 is the eleventh most popular language on GitHub.¬†CoffeeScript compiles predictably to JavaScript and programs can be written with less code, typically 1/3 fewer lines, with no effect on runtime performance

Syntax of CoffeeScript – Easy to use – Easy to Read

Here I am showing some example.

1. Assignment

str = "CoffeeScript"

2. Function

square = (x) -> x * x

3. Condition

string = "Passed" if  condition

4. Multiply numbers with 2

[1..10].map (i) -> i*2 

5. Object

math =
  root:   Math.sqrt
  square: square
  cube:   (x) -> x * square x

6. Loop

eat food for food in ['toast', 'cheese', 'wine']

CoffeScript vs JavaScript Code

CoffeScript vs JavaScript


The CoffeeScript compiler is itself written in CoffeeScript, using the Jison parser generator. The command-line version of coffee is available as a Node.js utility. The core compiler however, does not depend on Node, and can be run in any JavaScript environment, or in the browser.

To install, first make sure you have a working copy of the latest stable version of Node.js, and npm(the Node Package Manager). You can then install CoffeeScript with npm:

npm install -g coffee-script

(Leave off the¬†-g¬†if you don’t wish to install globally.)

If you’d prefer to install the latest¬†master¬†version of CoffeeScript, you can clone the CoffeeScriptsource repository¬†from GitHub, or download¬†the source¬†directly. To install the lastest master CoffeeScript compiler with npm:

npm install -g http://github.com/jashkenas/coffee-script/tarball/master

Or, if you want to install to¬†/usr/local, and don’t want to use npm to manage it, open the¬†coffee-script¬†directory and run:

sudo bin/cake install

For More Information and learning

What makes C++ so good?

Answer by Harsh Kothari:

1: Stronger Type Checking – the use of classes, inheritance &amp; automatic type conversions mostly eliminates the need for the abominable void* of C.

2: Type safe linkage – you can’t accidentally call a routine from another
module with the wrong type and/or number of arguments – even if your header files get out of date.

3: A complex data type is provided. It includes all the standard arithmetic operations, implemented as operators, not function calls.

4: User-defined operators and function overloading are supported. When you design a data type you can specify which operators &amp; functions are provided.

5: You can use class libraries to provide robust new data types which can be made exceptionally easy to use.

For example, the Rogue Wave ‘math.h++’ class library implements general multi-dimensional arrays which can be manipulated with high-level operations
and an intuitive syntax:

DComplexArray a(10,10); // Construct a 10×10 complex array
cin >> a; // read it in from standard input
DComplexArray b = inverse(a); // Calculate the inverse
cout << b; // write out the inverse
cout << variance(b.diagonal()); // write out the variance of the diagonal
elements of b

6: You can define automatic type conversions to convert between data types.
For example, the Rogue Wave library provides a conversion from a double array
to a complex array.

DoubleVec a(10, 0.0, 1.0); // Construct a double vector in initialised to
DComplexVec z = a; // Construct a complex vector initialised to
cout << a; // write them out
cout << z;
cout << cos(z)*exp(DComplex(0,1)*a);

7: Provides inline functions which combine the efficiency of using macros
with the safety of using functions – simply prepend the word ‘inline’ in
front of the function – if the compiler can inline it, it will.

inline Double
(const DoubleVec&amp; v)
Double theSum = 0;
for (int i = 0; i < v.length(); i++) {
if (v[i] > 0) {
theSum += v[i];
return theSum;

8: C++ Compiles most ANSI C code directly and can call compiled C code
directly, so you don’t even have to learn anything new at all!

9: You don’t have to put all of your declarations at the top of each block
in C++.
This means
that you can organise your code into logically related ‘paragraphs’ complete
with their necessary declarations. This makes code much more maintainable –
you can easily move sections of code around, taking the necessary
declarations along at the same time. If you use the const modifier you can
also ensure that variables whose value should not change after it is first
calculated do not do so.

Double x,y; // Declare two variables
cin >> x >> y; // read in their values
const Double sqrtX = sqrt(x); // Calculate the square roots
const Double sqrtY = sqrt(y);
cout << sqrt(sqrtX+sqrtY);
sqrtX = 42; // Will give an error…

10: Classes provide extensible types, promoting code reuse. This can
result in major savings in the amount of code written. I saw a recent
article which stated that the new Taligent operating system, which is written
in C++, consists of 250,000 lines of code, whereas WindowsNT, written in C,
was said to consist of 4,000,000 lines of code.

View Answer on Quora

Various Electronics Development Boards

A Development Board is an amalgamation of hardware and software. It is nothing but a printed circuit board containing a microcontroller or microprocessor with other peripherals as hardware and support packages in the form of toolchains , operating system to make up the software part.

Here I introduce you various Development Boards. So decide your needs, choose appropriate system and start making some good stuff and become Electronic Geek. Most important thing for final year engineering student, if you are planning to do project on embedded system, micro controllers , microprocessors this things are very helpful to you. It is also useful when some other project is needed microprocessor or micro controller. If you have any suggestion or query comment below the post. 

1. Arduino


Arduino is an open-source electronics prototyping platform based on flexible, easy-to-use hardware and software. It’s intended for artists, designers, hobbyists, and anyone interested in creating interactive objects or environments.

The hardware consists of a simple open hardware design for the Arduino board with an Atmel AVR processor and on-board input/output support. The software consists of a standard programming language compiler and the boot loader that runs on the board.  The microcontroller on the board is programmed using the Arduino programming language (based on Wiring) and the Arduino development environment (based on Processing). Arduino projects can be stand-alone or they can communicate with software running on a computer (e.g. Flash, Processing, MaxMSP).

The boards can be built by hand or purchased pre assembled; the software can be downloaded for free. The hardware reference designs (CAD files) are available under an open-source license, you are free to adapt them to your needs. The Arduino project received an honorary mention in the Digital Communities category at the 2006 Prix Ars Electronica. 

2. Teensy

The Teensy is a complete USB-based microcontoller development system, in a very small footprint! All programming is done via the USB port. No special programmer is needed, only a standard “Mini-B” USB cable and a PC or Macintosh with a USB port. This is the latest version, 2.0.

  • USB can be any type of device
  • AVR processor, 16 MHz
  • Single pushbutton programming
  • Easy to use Teensy Loader application
  • Free software development tools
  • Works with Mac OS X, Linux & Windows
  • Tiny size, perfect for many projects
  • Available with pins for solder less breadboard

3. MSP430 Launchpad

TI’s Launchpad board is definitely a bargain. For your money, you get a set of 16-bit MSP430 processors, a mini-USB debugger and programming interface, and a set of Windows IDEs to choose from  and cost just $ 4.30.

The LaunchPad is an easy-to-use, affordable, and scalable introduction to the world of microcontrollers and the MSP430 family.

  • Easy-to-use ‚Äď LaunchPad includes all of the hardware and software needed to get started. Open source projects and code examples help users get up and running quickly.
  • Affordable ‚Äď For $4.30, the LaunchPad includes a development board, 2 programmable MSP430 microcontrollers, mini-USB cable, PCB connectors for expandability, external crystal for increased clock accuracy, and free & downloadable software integrated development environments (IDEs) ‚Äď everything you need to get started today.
  • Scalable ‚Äď The LaunchPad is a simple introduction to the MSP430 microcontroller family. As application requirements change, programs developed on the LaunchPad can be migrated to higher end MSP430 devices.

4. STM32

The¬†STMicroelectronics STM32 Value line Discovery Kit¬†is a quick and inexpensive way to discover¬†STM32 32-bit microcontrollers¬†(MCUs). The¬†STMicroelectronics STM32 Value Line Discovery Kit¬†is based on the¬†STM32 Value line¬†and includes a quick-start evaluation board with ST-LINK debugger / programmer that is delivered with IDE from Keil, IAR, and Atollic. The debugger can debug¬†Discovery kit¬†applications or other target board applications. This low-cost¬†STMicroelectronics evaluation kit¬†will satisfy hobbyists, first-time developers, and students.¬†¬†This is even capable of running an RTOS if you’re trying to do a lot of things at once. Cost of this board is just $ 12.

The unparalleled and large range of STM32 devices, based on an industry-standard core and accompanied by a vast choice of tools and software, makes this family of products the ideal choice, both for small projects and for entire platform decisions.

5. Raspberry Pi

Raspberry Pi model B

The Raspberry Pi is a credit-card sized computer that plugs into your TV and a keyboard. It’s a capable little PC which can be used for many of the things that your desktop PC does, like spreadsheets, word-processing and games. It also plays high-definition video. We want to see it being used by kids all over the world to learn programming.

The¬†Raspberry Pi¬†is a¬†single-board computer¬†developed in the¬†UK¬†by the¬†Raspberry Pi Foundation¬†with the intention of stimulating the teaching of basic computer science in schools.¬†The design is based on a¬†Broadcom¬†BCM2835¬†system on a chip¬†(SoC),¬†which includes an¬†ARM1176JZF-S¬†700 MHzprocessor,¬†VideoCore¬†IV GPU,¬†and 256 megabytes of¬†RAM. The design does not include a built-in¬†hard disk¬†or¬†solid-state drive, instead relying on an¬†SD card¬†for booting and long-term storage.¬†The Foundation’s goal is to offer two versions, priced at US$ 25 and US$ 35 (plus local taxes). The Foundation started accepting orders for the higher priced model on 29 February 2012.

6. BeagleBoard

The¬†BeagleBoard¬†is a low-power¬†open source hardware¬†single-board computer¬†produced by¬†Texas Instruments¬†in association with¬†Digi-Key. The BeagleBoard was also designed with¬†open source software¬†development in mind, and as a way of demonstrating the Texas Instrument’s¬†OMAP3530¬†system-on-a-chip.¬†The board was developed by a small team of engineers as an educational board that could be used in colleges around the world to teach open source hardware and open source software capabilities. It is also sold to the public under the¬†Creative Commons¬†share-alike¬†license.

The OMAP3530 includes an ARM Cortex-A8 CPU, a TMS320C64x+ DSP for accelerated video and audio decoding, and an Imagination Technologies PowerVR SGX530 GPU to provide accelerated 2D and 3D rendering that supports OpenGL ES 2.0.

A single SD/MMC card slot supporting SDIO, a USB On-The-Go port, an RS-232 serial connection, a JTAG connection, and two stereo 3.5 mm jacks for audio in/out are provided. Android, Ubuntu, Symbion capability, 256 Mb Flash Memory and 256 Mb RAM.

7. PandaBoard

The PandaBoard is a low-power, low-cost single-board computer development platform based on the Texas Instruments OMAP4430 system on a chip (SoC). The board has been available to the public at the subsidized price of US $174 since 27 October 2010. It is a community supported development platform.

The PandaBoard ES is a newer version based on the OMAP4460 SoC, with the CPU and GPU running at higher clock rates. The board has been available to the public at the subsidized price of US $182 since 16 November 2011. Like its predecessor, it is a community supported development platform.

The OMAP4430 SoC on the PandaBoard features a dual-core 1 GHz ARM Cortex-A9 MPCore CPU, a 304 MHz PowerVR SGX540 GPU, a C64x DSP, and 1 GB of DDR2 SDRAM. The PandaBoard ES uses a newer SoC, with a dual-core 1.2 GHz CPU and 384 MHz GPU. Primary persistent storage is via an SD Card slot allowing SDHC cards up to 32 GB to be used. Linux kernel , Android, Ubuntu compatibility, integrated SGX540 graphics processor and provides 1080p HDMI output are features of this PandaBoard.


This are amazing things to work on. It also saves time. No need for tedious soldering work and also come with guarantee warrantee features. Very easy to implement and very easy to make some cool stuff and projects. So start using it and don’t forget to do comment.¬†