Tuesday, March 22, 2016

Python - function chaining

Implementing chaining of functions. This is reverse of python inbuilt map() function.

map() function works on each element of an iterable by applying the given function and returns the resultant list.

>>> map(int, ['1', '2', '3'])
[1, 2, 3]

In contrast the below implemented function would execute a chain of functions on a given argument.

function implementation:-
>>> fchain = lambda fnlist, argument: reduce( lambda x, fn: fn(x), [ argument ] + fnlist )

Example for running this:-

>>> def double(x):  
...   return x*2
...
>>> def triple(x):
...   return x*3

>>> fchain([double, triple, double, double], 10)

240






Friday, November 2, 2012

Tuesday, August 14, 2012

E-mail configuration for outlook express



Share on emai

iguration for outlook express

Share on favorite
Share on pShare on facebooShare on twitteShare on dig

To set up your Outlook Express client to work with G E-mail configuration for outlook Gmail:

  1. Enable POP in your email account. Don't forget to click Save Changes when you're done.
  2. Open Outlook or Outlook Express.
  3. Click the Tools menu, and select Accounts...
  4. Click Add, and then click Mail...
  5. Add mail account
  6. Enter your name in the Display name: field, and click Next.
  7. Enter your full Gmail email address (username@gmail.com) in the Email address: field, and clickNext. Google Apps users, enter your full address in the format 'username@your_domain.com.'
  8. Enter username
  9. Enter pop.gmail.com in the Incoming mail (POP3, IMAP or HTTP) server: field. Enter smtp.gmail.com in the Outgoing mail (SMTP) server: field. Google Apps users, enter the server names provided; don't add your domain name in this step.
  10. Enter server names
  11. Click Next.
  12. Enter your full email address (including '@gmail.com' or '@your_domain.com') in the Account name: field. Enter your email password in the Password: field, and click Next.
  13. Enter account name and password
  14. Click Finish.
  15. Highlight pop.gmail.com under Account, and click Properties.
  16. Highlight account
  17. Click the Advanced tab.
  18. Fill in the following information:*
    • Check the box next to This server requires a secure connection (SSL) underOutgoing Mail (SMTP).
    • Enter 465 in the Outgoing mail (SMTP): field.
    • Under Outgoing Mail (SMTP), check the box next to This server requires a secure connection (SSL).
    • Under Incoming mail (POP3), check the box next to This server requires a secure connection (SSL). The port will change to 995.
    • Highlight account
    *The order of Outgoing and Incoming mail server fields varies by version. Make sure you enter the correct information in each field.
  19. Return to the Servers tab, and check the box next to My server requires authentication.
  20. Highlight account
  21. Click OK.

Friday, June 8, 2012

svn propedit

After going through many useless posts to edit externals for a repo, google finally helped me to reach atsome useful point. I thought this may help many.

propedit to change externals on a repo.

~Checkout the repo on your machine.
>>>svn co svn+ssh://.....

~go to the directory which contains sub directories coming through external links.
>>>cd dir_containing_external_dirs/

~execute the command that will edit external links
>>>svn propedit svn:externals .
don't miss dot at the end.

~checkin your code.
>>>svn ci -m ""

~update your code with new external links.
>>>svn up

Monday, May 14, 2012

Include variables to a shell script from an external script

file1 include.sh

#!/bin/bash
var1="Hello there"

file2 includetest.sh

#!/bin/bash
. include.sh
echo $var1
#file2 has access to all variables defined in file1


>>>>Run file2 and you see the required output.
>>chmod +x includetest.sh
>>./includetest.sh

Mount a LAN resource in cmd

My need led me to think about this problem. I had to run an application from sources when I had the source code on a machine connected to my network(LAN). Due to some problem I didn't want to copy the source code on my machine. I took the following steps:-

 1)mount the LAN resource:-
 >>>net use z: \\192.168.x.x\shared_folder
 Now z drive is a virtual drive on your machine.

 2)Set all your environment variables referring z drive.

 The above two steps makes you all set to run the application from sources that is present on a LAN resource.
There are many other such utilities with "net" command. Check them, You may find them beneficial too.

Monday, October 10, 2011

something u must know if u r using DOCOMO(know ur call logs)

Recently I was really surprised to dat 1 of ma frnds had access to all my account details, my recent call logs n muh more. After some research I got to know some facts...

1)Docomo has an online support desk(link-Online Support). Many of the advanced queries which customer support guys at 121 cannot answer are all answered there.

2)Docomo has a "my accounts" page (link- My Account), where you can see all your account details.The details include...
a)Ur account info like ur name n address on which ur no. is registered.
b)Ur recent call logs.
c)Ur recharge information.
d)U can activate/deactivate DND. And some more information.

Hope u would like the post.Remember not to disclose ur passwd :)

~barun

Monday, August 8, 2011

Increase your PC's RAM!!

Use Ready Boost to use your USB as a temporary memory to increase your RAM.
Do chek this link...

http://www.sevenforums.com/tutorials/33289-readyboost-setup-use.html

Windows boots up Slow..Cool Solution??

1)goto run-->msconfig...and remove the items from startup which eat up your memory while startup but you don't need them as such.

2)Delete all temporary files from your Windows machine..
goto run-->%temp% and delete all temporary files.

I hope your computer is not infected else you need an antivirus first!! :)

Monday, May 16, 2011

Know your System

Method 1

~type "systeminfo" in a dos.

Method 2

~Start->Run(Windows key+R)

~type "winmsd" and click "OK".

Windows Keyboard Shortcuts

~goto start->Run

~type "C:\WINDOWS\Help\keyshort.chm"

~click "OK"

~click Print

Changing MAC address

I hope you will not use it for illegal things...but it's sometimes really important for security reasons...

The steps are as follows...

Windows 2000/XP

~Go to start>my network places.Right click and go to Properties.

~Under "General" tab, click on the "Properties" button


~Under "General" tab, click on the "Configure" button

~Click on "Advanced" tab

~Under "Property section" select "Network Address" or "Locally Administered Address".

~On the right side, under "Value", type in the new MAC address you want to assign to your NIC. Do not use "-" between the MAC address numbers.

~Goto command prompt and type in "ipconfig /all" or "net config rdr" to verify the changes.

~If successful, reboot your system.

Get MAC addresses of all computers connected to your network(LAN)


~In command prompt execute "arp -a".(arp is for Address Resolution Protocol)

What is PUK code of a sim?

PUK code is a sim specific code assigned by your service provider. Its not possible to crack it on your own. So, whenever your cell asks for the PUK code, don't play(you may be in trouble), get the PUK code from your service provider.

Many people use a pin no. to get access to their cell phones.But, sometimes this may be a great cause of problem.

Suppose mistakenly someone enters 3 wrong trials.This results in blocking of your sim card and cell will now ask for PUK no. If the tragedy is to happen,you again give 3 wrong trials for PUK code.And the unfortunate result is that your sim gets blocked permanently.Now there is only 1 solution,go to the customer care center and ask for a replacement sim or simply throw this one and buy a new sim.

Sunday, May 15, 2011

show hidden files and folders

Windows registry(winreg) to show the hidden files and folders.

1)type "regedit" in Run.
2)Make the following entry...

User Key: [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\
Advanced]
Value Name: Hidden
Data Type: REG_DWORD (DWORD Value)
Value Data: (1 = show hidden, 2 = do not show)

Best SMS site

smsze.com is the best sms site I have ever used.It sends sms without ads,as if you were sending it from your cellphone.you will definitely like it.

Friday, April 15, 2011

Search Algorithms

Linear Search

It is the easiest search algorithm.The algorithm intends so check each and every element and stops when the required element is found.

Implementation

int getindex(int a[], int n, int target)
{
for(int i = 0; i < n ; i++)
if (a[i] == target) { return i; }
return -1;
}

void main()
{
int a[]={3,4,5,2,6,8,10};
int n=7; //no. of elements in the array
int index=getindex(a,n,6);
printf("index of 6 in array "a" is::%d",index);
}

explaination::The above code returns the index of element to be found...


Binary Search

Binary Search use Divide and rule algorithm to find the reqd. element in an already sorted list. The algorithm is deceptively simple. Pretend I was thinking of a number between 1 and 100. Every guess you take, I'll say higher or lower. The most efficient way to discover my number is to first guess 50. Higher. 75. Lower. 62. Higher 68. Yes!

Implementation

int findIndex(int a[],int n, int target) {
return binarySearch(a, target, 0, n);
};

int binarySearch(int a, int target,int start,int end) {
if (start > end) { return -1; } //does not exist

int middle = (start + end) / 2;
int value = a[middle];

if (value > target) { return binarySearch(a, target, start, middle-1); }
if (value < target) { return binarySearch(a, target, middle+1, end); }
return middle; //found!
}

int a[]={1, 4,6,8,9,12,32,45,56,58,78};
int n=11;
findIndex(a,n,12);

Monday, April 4, 2011

Microsoft Placement Paper

My experience....MICROSOFT....conducted on 22nd Dec 2010

First round was a written test of an hour. There were 6 questions(4 programming and 2 test cases) 10 marks each.

1)find output of following code??

void main()

{

void *ptr;

char *a='A';

char *b="TAN";

int i=50;

ptr=a;

ptr=(*char)malloc(sizeof(a));

printf("%c",*ptr);

ptr=i;

ptr=(*int)malloc(sizeof(i));

printf("%d",++(*ptr));

ptr=b;

ptr=(*char)malloc(sizeof(b));

printf("%c",++(*ptr));

}

ans: A51AN

2) Write a program that takes a no. from user and prints the no. subtracting 5 each time from the no. till the no. doesn’t crosses/reaches 0.And again prints the nos. now increasing 5 each time till the no. doesn’t reaches/crosses original no.

don't use any loops or goto stmnt.And don't declare any local variables.

ans: use recursion.

3)convert a no. from string to integer.

eg: str:"1234"

convert to int a=1234;

ans:while(*ptr!=NULL)

{

a=(a*10)+(*ptr-48);

}

4) Find the subarray of an array that has the greatest sum? Array contains both +ve as well as -ve nos.

ans:I did it using 3 loops but when I went for the 2nd technical round the interviewer told me a very simple and optimal program for the same.

sumtillnow=0;

sum=0;

for(i=0;i

{

sumtillnow+=a[i];

if(sumtillnow>sum)

sum=sumtillnow;

if(sumtillnow<=0)

sumtillnow=0;

}

5) Write test cases for a student regestration form.

6) Write test cases for a web search engine.

--------------------------------------

20 students were shortlisted after the written test.

1st technical round...

First he saw my resume and asked me few ques about my BE Project and the TE Project.

Then I was asked many questions from OOP concepts...mainly about virtual functions,pure virtual functions(application based) and v-table etc.

Then he asked me some ques from OS...

1) Critical section

2) Semaphores

3) Processes

4) Threads

5) Reader Writers problem

Then there were a few questions from Logic Gates

1) Half adder....circuit and functionality

2) Full adder....circuit and functionality

Then he asked me 2 puzzles...

1) There are 3 buckets full of oranges, apples and mixture of both. Buckets are labeled with orange, apple and mixture. And it is known that all labels are false. Now just pick up 1 fruit from any 1 of the buckets and label all of them correctly.

Ans ::hint: pick the fruit from mixed labeled basket.

2) There are 5 bags containing marbles. All are identical.4 of them weight 9g one of them is 10g.you have a weighing balance. In one go can u tell which is the bag with 10g.

ans::i was blank.min I could produce was in 3 chances.

-------------------------------------------------

In 1st round other students were also asked ques. from DBMS (Normalization, few queries and ER diagrams).

And ques from TOC (Finite automata machine)..... Draw a finite automata to accept a binary no. that is divisible by 5.

-------------------------------------------------

2nd Round

He asked me some test cases.

Then the interviewer asked me to optimize certain codes...

1)4th ques of the written exam. (Subarry sum)

2) An array of n elements contains elements 1-(n-1) in random order and 1 entry is duplicated. Find the duplicate entry???

ans::I told him to take one more array. Now pick the elements from 1st array and put them into respective index of the 2nd array. If duplicate occur then report and end the loop.

he asked me to optimize the code. Then I suggested a BST. He asked me to optimize more and more and more and more......this ques fucked me..

But somehow I was advanced for the 3rd round..I was very excited.

---------------------------------------------------

3rd Round

HR...Some test cases and Why should I take you in Microsoft.

---------------------------------------------------

But unfortunately I wasn’t able to make it :( But may be these questions will help you for your placements. Best of Luck to all...

Sunday, November 7, 2010

Recursive Quick Sort

import java.io.*;
import java.util.*;

public class quick
{
private static double[] arr;
public static void main(String[] args)
{
int i;
Scanner in=new Scanner(System.in);
System.out.print("Enter n::");
int n=in.nextInt();
arr=new double[n+1];
for(i=0;i arr[i]=in.nextDouble();
for(i=0;i System.out.print(" "+arr[i]);
quick(0,n-1);
System.out.println("\n\n**************After Sorting****************\n");
for(i=0;i System.out.print(" "+arr[i]);
}

public static void quick(int low,int high)
{
if(low {
int j=partition(low,high);
quick(low,j-1);
quick(j+1,high);
}
}

public static int partition(int low,int high)
{
double pivot = arr[low];
int i = low;
int j = high;
double temp;
do
{
do
{
i++;
}while(arr[i]
while(arr[j]>pivot)
j--;

if(i {
temp = arr[i];
arr[i]= arr[j];
arr[j]= temp;
}
}while(i
//swap pivot n a[j];
arr[low] = arr[j];
arr[j] = pivot;
return j;
}
}

Recursive Merge Sort

import java.io.*;

public class merge
{
public static void main(String a[])
{
int i;
int array[] = {12,9,4,99,120,1,3,10};
System.out.println(" Selection Sort\n\n");
System.out.println("Values Before the sort:\n");
for(i = 0; i < array.length; i++)
System.out.print( array[i]+" ");
System.out.println();
mergeSort_srt(array,0, array.length-1);
System.out.print("Values after the sort:\n");
for(i = 0; i System.out.print(array[i]+" ");
System.out.println();
System.out.println("PAUSE");
}

public static void mergeSort_srt(int array[],int low, int high)
{
if (low >= high)
{
return;
}

int middle = (low + high) / 2;
mergeSort_srt(array, low, middle);
mergeSort_srt(array, middle + 1, high);
int end_low = middle;
int start_high = middle + 1;
while(low<=end_low && start_high<=high)
{
if(array[low] < array[start_high])
low++;
else
{
int temp=array[start_high];
int k;
for(k=start_high;k>low;k--)
array[k]=array[k-1];
array[k]=temp;
end_low++;
low++;
end_low++;
start_high++;
}
}
}
}