Friday 18 March 2016

Mac OS X - Hidden Gems : Part 1

Guys, presenting a mind blowing Mac OS X hidden gem that I just stumbled onto.

Type the following in Terminal to read some Apple supplied Jokes :)

open /usr/share/emacs/22.1/etc/JOKES

Thursday 17 March 2016

How to change Bash History Size on Mac OS X

Guys, I hope you must be aware, that the commands that you type in terminal get saved in the history. On Mac OS X, the default size of commands history is 500 i.e it saves the most recent 500 commands that you typed in terminal in a special file named "bash_history".

Open Terminal and check for yourself.

vi ~/.bash_history

Hit escape and type this to see the history limit
:set number


Now to change this default limit of 500 to something else, lets do the following in Terminal.

sudo vi ~/.bash_profile

Enter your password.

Add this line to the file :

#history
HISTFILESIZE=1000

That's it. It means from now on, it will save upto 1000 latest commands that you typed in history. Ciao!

Wednesday 16 March 2016

GRE GMAT CAT Wordlist - TurboPack 2

Guys, in our previous TurboPack, we saw the first set of wordlist for your reference. From this post onwards, lets rename the "Set" of words to something more appealing - "TurboPack". The random non-alphabetical sequence of words in the pack is intended for stronger and better memory retention.

TurboPack 2

uncanny : strange, mysterious
recluse : loner, someone living a solitary life
penchant : strong inclination or liking to do something
palate : sense of taste
visage : face, facial appearance
occult : mysterious, supernatural, mystical
medley : mixture, motley
jaunt : short trip, short excursion
indolent : lazy
torque : force producing rotation

Courtesy : Barron's and Google

Cheers!

Monday 14 March 2016

How to find size of Hashes in Perl

Hashes as you know are basically key-value pairs. So in Perl, if you want to find the size of hashes, check this out.

Consider a simple practical real-time Perl script for storing stock quotes of various companies.

#!/usr/bin/perl

use strict;
use warnings;

my %stock_quotes;
my @keys;
my $size_of_hash;

%stock_quotes=(
Apple => 102,
Google => 720,
Microsoft => 53,
Yahoo => 34,
Walmart => 67
        );

@keys = keys %stock_quotes;

$size_of_hash = @keys;


print "Stock hash size : $size_of_hash \n";

You see the %stock_quotes is the hash which has key value pairs i.e stock quote values in this case. Now, we store all the keys of the pairs in an array @keys. Note am not storing the values here, just the keys and we then find the size of this array @keys holding all the keys. Thus basically showing the size of the hash with $size_of_hash.

The resultant output is as expected :

Stock hash size : 5

Cheers!

Remove all Whitespaces from a file in Mac OS X

Lets look into a simple task today - remove all whitespaces from a file in Unix / Mac OS X from the command line.

To do so, let's consider a small example.

Let's have simple text file named Space_File.txt withe the below content. You see it's a regular text file with words separated with spaces.

1.Here is a cute little tutorial for
2.trying out different things using
3.the Stream Editor or Sed in Unix.
4.The author of this tutorial is
5.none other than IroncladWriter
6.himself. The tutorial aims to
7.teach folks and educate how
8.they could unlock the power
9.of Unix to the fullest. Am posting
10.this on the blog IronCladZone
11.The best blog on the whole of
12.internet, where you can learn
13.technical stuff as well enjoy 
14.entertaining tidbits like movies,
15.music, television, fashion, food,
16.shopping, travel, trends etc.
17.Just sit back, relax and

18.ENJOY THE RIDE :)

Now, we want to remove all the whitespace between the words. So let's use the following command.

tr -d ' \d' <Space_File.txt >NoSpace_File.txt

In this we pass the Space_Text.txt as input and redirect the output to a new file - NoSpace_File.txt. Note the space before \d. Do not miss this space. I repeat, DO NOT miss this space. It has to be ' \d' and not '\d'. Got it? All rite so the resultant output is as expected with no spaces:

1.Hereisacutelittletutorialfor
2.tryingoutifferentthingsusing
3.theStreamEitororSeinUnix.
4.Theauthorofthistutorialis
5.noneotherthanIronclaWriter
6.himself.Thetutorialaimsto
7.teachfolksaneucatehow
8.theycoulunlockthepower
9.ofUnixtothefullest.Amposting
10.thisontheblogIronClaZone
11.Thebestblogonthewholeof
12.internet,whereyoucanlearn
13.technicalstuffaswellenjoy
14.entertainingtibitslikemovies,
15.music,television,fashion,foo,
16.shopping,travel,trensetc.
17.Justsitback,relaxan

18.ENJOYTHERIDE:)

Monday 7 March 2016

Show line numbers in vi editor on Mac OS X

Guys in vi editor in order to show the line numbers, do the following :

Open vi editor to create or open a script
Click escape (esc) key and type colon.
Now enter set number and Enter

Check out the screenshot for reference :

Cheers!

Sunday 6 March 2016

User Input example in Python

Every programming language has a way to accept user input. Like in Perl, you accept using STDIN. Similarly, Python interpreter has 2 inbuilt functions to read user input :

raw_input()
input()

Let's look into a simple python script which accepts user input and prints a statement.
Create a simple script - vi python_input.py

#!/usr/bin/python

name = raw_input('Please enter your name, visitor : ');

print ('Welcome to IroncladZone ' + name);

You see the variable "name" stores the input entered by the user. Accordingly we make use of this value in the next print statement.

Output :

./python_input.py

Please enter your name, visitor : Johnny

Welcome to IroncladZone Johnny
Related Posts Plugin for WordPress, Blogger...
eXTReMe Tracker