Bloody windows: Create conda environments

Bloody windows

One of my collegue at office really really hates windows, every time he is forced to use windiwos, I have heard him mutter “bloody windows”

Sometime back I had the same desire.

This is the batch script, which works perfectly fine if I use the command in the cmd window but it failes in batch mode.

Old batch file

rem Create conda environment
echo Creating conda environment
conda deactivate
conda env create --file environment.yml --force --quiet

After a lot of head scratching, trying to figure out what is happening, found that I have to use call.

New batch file

rem Create conda environment
echo Creating conda environment
call conda deactivate
call conda env create --file environment.yml --force --quiet

Turns out call is needed.

call activate %name%

I’m assuming that activate is a batch file. If you call it, processing will return after that batch is finished. Without the call, execution is transferred to activate and ends when activate ends

Kill Tasks in Windows

Linux, Mac users have it easy. Top and kill are two commands that can help one take control of the system.

For windows user, until recently I was stuck with the task manager. Like all manager this one demands too much attention and is not batch able.

Summoned Google Gennie and discovered.

Tasklist and Taskkill commands in CMD.

Neat. Where were these commands hiding?

Here is two gifs for how they work

A Mac App for Your Windows

Dictionary App

I am using Mac OS for more than 10 months now and every day I am loving it more… It’s the little tweaks and apps that make using it such a pleasure.

One of them is the quick Dictionary available at finger tips across all apps. Select a word, press the shortcut key and the meaning pops up. (Shown in image above). Made reading of ebooks on Mac so much fun.

Missed this feature so much when working on windows, created a similar app in windows. Uses, Oxford online dictionary and google to get the meaning of the selected word.

Here’s the fruit of two days of intermittent work.
Download the App as Zip file

No installation. Unzip. Click on the executable.

How to use:
1. Select the word.
2. Click F10

Use F11 to use google and use F12 for online Oxford dictionary.

Unlike the Mac app, this app needs online access to work!!

Windows, Mac and Linux


Before I say anything read this…

The analogy between cars and operating systems is not half bad, and so let me run with it for a moment, as a way of giving an executive summary of our situation today.

Imagine a crossroads where four competing auto dealerships are situated. One of them (Microsoft) is much, much bigger than the others. It started out years ago selling three-speed bicycles (MS-DOS); these were not perfect, but they worked, and when they broke you could easily fix them.

There was a competing bicycle dealership next door (Apple) that one day began selling motorized vehicles–expensive but attractively styled cars with their innards hermetically sealed, so that how they worked was something of a mystery.

The big dealership responded by rushing a moped upgrade kit (the original Windows) onto the market. This was a Rube Goldberg contraption that, when bolted onto a three-speed bicycle, enabled it to keep up, just barely, with Apple-cars. The users had to wear goggles and were always picking bugs out of their teeth while Apple owners sped along in hermetically sealed comfort, sneering out the windows. But the Micro-mopeds were cheap, and easy to fix compared with the Apple-cars, and their market share waxed.

Eventually the big dealership came out with a full-fledged car: a colossal station wagon (Windows 95). It had all the aesthetic appeal of a Soviet worker housing block, it leaked oil and blew gaskets, and it was an enormous success. A little later, they also came out with a hulking off-road vehicle intended for industrial users (Windows NT) which was no more beautiful than the station wagon, and only a little more reliable.

Since then there has been a lot of noise and shouting, but little has changed. The smaller dealership continues to sell sleek Euro-styled sedans and to spend a lot of money on advertising campaigns. They have had GOING OUT OF BUSINESS! signs taped up in their windows for so long that they have gotten all yellow and curly. The big one keeps making bigger and bigger station wagons and ORVs.

On the other side of the road are two competitors that have come along more recently.

One of them (Be, Inc.) is selling fully operational Batmobiles (the BeOS). They are more beautiful and stylish even than the Euro-sedans, better designed, more technologically advanced, and at least as reliable as anything else on the market–and yet cheaper than the others.

With one exception, that is: Linux, which is right next door, and which is not a business at all. It’s a bunch of RVs, yurts, tepees, and geodesic domes set up in a field and organized by consensus. The people who live there are making tanks. These are not old-fashioned, cast-iron Soviet tanks; these are more like the M1 tanks of the U.S. Army, made of space-age materials and jammed with sophisticated technology from one end to the other. But they are better than Army tanks. They’ve been modified in such a way that they never, ever break down, are light and maneuverable enough to use on ordinary streets, and use no more fuel than a subcompact car. These tanks are being cranked out, on the spot, at a terrific pace, and a vast number of them are lined up along the edge of the road with keys in the ignition. Anyone who wants can simply climb into one and drive it away for free.

Customers come to this crossroads in throngs, day and night. Ninety percent of them go straight to the biggest dealership and buy station wagons or off-road vehicles. They do not even look at the other dealerships.

Of the remaining ten percent, most go and buy a sleek Euro-sedan, pausing only to turn up their noses at the philistines going to buy the station wagons and ORVs. If they even notice the people on the opposite side of the road, selling the cheaper, technically superior vehicles, these customers deride them cranks and half-wits.

The Batmobile outlet sells a few vehicles to the occasional car nut who wants a second vehicle to go with his station wagon, but seems to accept, at least for now, that it’s a fringe player.

The group giving away the free tanks only stays alive because it is staffed by volunteers, who are lined up at the edge of the street with bullhorns, trying to draw customers’ attention to this incredible situation.

This extract is from In the Beginning was the Command Line by Neal Stephenson. Loved the analogy. And if the car analogy isn’t enough read the updated commented version here to know about the monkeys!!

A neat trick to use notepad as logger


Here’s a simple trick in notepad that I have been using ever since I remember. I am surprised how few know about this.

Use notepad to log anything in 3 steps

  1. Open notepad.
  2. In the very first line input this .LOG Yes ‘dot’ followed by the word ‘log’ without a space.
  3. Save and close the file.

That’s it. You can choose whatever name you want.

Now whenever this file is opened, it gives you a convenient time and date. Just write your log entry after the date and time stamp and close.

Convenient isn’t it!!

Know any other trick similar to this, Would love to know about it. Share it here.

Plants Become Weeds when they…..

FortranDLL in visual studio

How to Create Fortran DLL in Visual Studio? – The simple way

Plants become weeds when they obstruct our plans or our tidy maps of the world. Fortran is also perceived in the same way. Although still a formidable programming language, many now treat it as weeds.

They encounter it and they go back to fortran 66 mindset. Fortran’s new capabilities are discounted and people look past the new features of the language to talk about the horrible “go to” mess!! They might want to look at this Myths Of Fortran post!

There’s so much legacy code in fortran, but no one wants to touch it. The easiest solution commonly used is to convert it into a dll or some library and use with new languages. This explains the popularity of the post how to create fortran dll in visual studio on this blog.

This brings me to today’s post. Here’s an even more convenient animated gif to explain the process of converting a fortran program to a dll in visual studio with intel fortran compiler!



We were taught “Never take shorts cuts” but in excel and other software program, shortcuts make you productive.

Here are my two most used shortcuts in Microsoft excel. They save a ton of clicking and touching the mouse.

1. Use F4. It repeats the previous action. Automate any single action instantly.

2. Control+1 quick formatting

What are your most used shortcuts?

Meshing Fortran and Matlab together with Mex

matlab fortran A few days back colleague of mine needed a help in calling Fortran from matlab. At that time I knew about the call system command.

But as we tried solving his problem, I learnt about Mex. I knew Mex was matlab executable but had never explored them or used or created them.

My colleague’s problem was solved once we got matlab and the c compiler. That day and few days after, I continued exploring the dark alleys of Mex.

Learnt a lot.  Here’s the list of links that were great at explaining the meshing of fortran and c with matlab with Mex.

Perhaps someday I will use them in some project, but till then let them be kept here.

A Stochastic Encounter

I use gfortran fortran compiler at home and intel fortran compiler in office.

Its by random chance I found a vital difference in gfortran and intel compiler’s interpretation of using the intrinsic subroutine Random_number.

In gg95 fortran forum, someone posted this query.

I have the following code to generate a random number in between 0 and 1.

program random
implicit none
real :: R
call random_seed()

call random_number(R)
end program

But it always returns a same number. Why this happens, can any body suggest me?

I checked this in gfortran and I got the same result. Everytime it returned the same random number.

With Intel compiler the result was as expected. In sun solaris it was as expected. The program gave different random number on each call.

But gfortran was different. I thought it was a bug in gfortran.

But then Tobius Burnus explained this

No, it’s actually a bug in the Fortran standard: The standard does not
specify whether calling “random_number()” should produce by default the same sequence or every time a different sequence.

There are proponents for both.

One group argues that having a random_number() function should produce random results. Others argue that when running, e.g., an Monte Carlo algorithm, by default the results should be reproducible. As the standard does not mandate either choice, one has to live with having compiles in both groups. (I heard that the person responsible for adding the intrinsic believed that he had
written down the choice – but obviously he hasn’t.)

I think its worth keeping in mind. This can help solve lot of pain if you are using gfortran and intel compilers for your stochastic programs.