This post is all about BrainFuck, Programming Language. For starters, you can get details about this from wikipedia .
Since this is an esoteric programming language, it is well know for its complexity that make programmers amuse and yeah the name says it all :-P
I had looked into this as a part of Shaastra 2008 IITM . Luckily i was among the 15 finalists.

At first a brief introduction on BrainFuck. This language supports only eight commands and each consisting of only one character. The brainfuck language uses a simple machine model consisting of the program and instruction pointer, as well as an array of at least 30,000 byte cells initialized to zero; a movable data pointer (initialized to point to the leftmost byte of the array); and two streams of bytes for input and output (most often connected to a keyboard and a monitor respectively, and using the ASCII character encoding).

  • .               Output the Byte in the Data Pointer
  • ,               Accept one Byte of Data in the current data pointer
  • >             Move the data pointer to right
  • <             Move the data pointer to left
  • -              decrement the data byte at the pointer by one
  • +             Increment the data byte at the pointer by one
  • [              if the byte at the data pointer is zero, then instead of moving the pointer forward to the next command, jump it forward to the       command after the matching ]
  • ]              if the byte at the data pointer is nonzero, then instead of moving the instruction pointer forward to the next command, jump it back to the command after the matching [

Since the language supports only these 8 characters, rest are ignored.
Below you can find the sample questions and the corresponding programs.

  • Given any number (less than or equal to 64), print it in the binary format. Also, give the output(in decimal format) when the number is multiplied by 3.

Input:  15

Output: 1111

45
,
>
,
>
++++++++++++++++++++++++++++++++++++++++++++++++
[
<
-
< - >>-
]
<<
[
-
<++++++++++ >
]
>
[
-
<<+ >>
]
;p0 equals number in one pointer
<< ;p0 for example [- >+ ;p1
<<+ ;p255 > ;p0
]
< ;p255
[<<+>>[-
<+>]]
<< ++++++++++++++++++++++++++++++++++++++++++++++++. ------------------------------------------------ [-] >
[
->+
<] >>
;p0 copied to p1 and p255
> ;p1
[ ;p1
[
-
>>>+<<< [ - >+
>>+
<<
< [- >>+
<< ] ] >>
[-<<+>>
]
<< ] ;p1 p2 will be half p1 > ;p2
[->>>>+<<<++<] >>[->+<<<<+>>>]
<
[-<>]
<<+ >>>>> ;p6
]
<<<<<<<<<<
[
-
++++++++++++++++++++++++++++++++++++++++++++++++.
<<<<< ] ; ++++++++++. ---------- >>>>>[-]
>[-]
>[-]
>[-]
<<<<< ;p255
[
-
<+++ ;p254
<+++ ;p253 >>
]
< ;p254 [[-[-[-[-[-[-[-[-[-[- >+ ;p255
< ;p254
[-<<+>>] ;p252
]]]]]]]]]]
<< ;p252 [- >>+ ;p254
<< ;p252 ] >> ;p254
]
> ;p255
[-
>++++++++++ ;p0
>+ ;p1
>+ ;p2
<<< ;p255 ] > ;p0
[-<<>>] ;p253
;p253 is the last diit
>
[->>>+<<<[->>>+<<<[->>>+<<<[->>>+<<<[->>>+<<<[->>>+<<<[->>>+<<<[->>>+<<<[->>>+<<<[->>>+<<< >>+[>[-]] ;p3
<<<[->>>+<<<] ]]]]]]]]]] >>
++++++++++++++++++++++++++++++++++++++++++++++++.
------------------------------------------------
>
++++++++++++++++++++++++++++++++++++++++++++++++.
------------------------------------------------
<<<<<<<
++++++++++++++++++++++++++++++++++++++++++++++++.
------------------------------------------------

  • Given a string input, rotate it (last to first) by a specific amount.Input format: first two places will be for amount of rotation.

Input: 04abcdefghij
Output (rotated by 4): ghijabcdef


,
> ;p2
,
> ;p3
++++++++++++++++++++++++++++++++++++++++++++++++
[
< ;p2
-
< ;p1 - >>- ;p3
]
<< ;p1
[
-
<++++++++++ ;p0 > ;p1
]
> ;p2
[
-
<<+ >>
]
>,----------
[
++++++++++>
>,
----------
]
<<
[
<<
]
;at the end this will be p1 for example
< ;p0 mainloopbeGins [ ->>+ ;p2
-
>[>>] ;this end with p11 for example
<<<< ;p7 if non zero loop beGins [ >> ;p9
[
-
>+ ;p10
<
]
<< ;p7to p9 [->>+<<] >>> ;p10
[-<<<+>>>]
<<<<<
] ;p5
;this ends with p1 which is zero
< ;p0 ] >>> ;p3
[
.
>> ;p5
]

  • Geometric Progressions.Given the values of 'a' (first term of the G.P.) and 'r' (the common ratio), print the G.P. till 100.Input format: two places for value of 'a' followed by two places for value of 'r'.

Input: 1502

Output: 15
30
Input: 0502

Output: 5
10
20
40
80
>>>>>>>>> ;p10
,
> ;p11
,
> ;p12
,
> ;p13
,
> ;p14
++++++++++++++++++++++++++++++++++++++++++++++++ ;p348
[-
<-
<-
<-
>>>
]
<<<<
[
-
<<<<<<<<<++++++++++ ;p1 >>>>>>>>>
]
>
[
-
<<<<<<<<<<+ >>>>>>>>>>
]
>
[
-
<<<<<<<<<<++++++++++ >>>>>>>>>>
]
>
[
-
<<<<<<<<<<<+ >>>>>>>>>>>
]
<<<<<<<<<<< ;asci conversion true
< [ ;p1 main loop begins only if the number is not zero [ - >>+ ;p3
<< ;p1to0 ] >> ;p3
[
- ;p3
>>+ ;p5
>+ ;p6
>>+ ;p8
<<<<< ;p3 ] >>
[ ;p5 to minus 10 in steps of 1
[>[-]< ;p6
[-<<+>> ;p3 to p5
[-<<+>>
[-<<+>>
[-<<+>>
[-<<+>>
[-<<+>>
[-<<+>>
[-<<+>>
[-<<+>>
[-<<+>>
<+ ;p4 >
[
-
>+ ;p6
< ;p5 ] ]] ]] ]] ]] ] ] >[-<+>]<
]
< ++++++++++++++++++++++++++++++++++++++++++++++++. ------------------------------------------------ > ;p5
]
;up to displaying the fistdigits varified
;now to display second digit
<;p4 [ - >++++++++++ ;p5
< ;p4 ] > ;p5
[
-
<> ;p5
]
<< ;p3
++++++++++++++++++++++++++++++++++++++++++++++++.
[-]
<< ++++++++++. ---------- ;varified for 2 digit ;now to copy common ratio > ;p2
[
-
>+ ;p3
< ;p2 ] > ;p3
[
-
>>+ ;p5
<<<+ ;p2
<+ ;p1
<<<<<<<<<+ ;p248 >>>>>>>>>>> ;p3
]
;common ratio copied succesfully
;to find the corresponding next terms in gp
>>>>>
[
-
<<< ;p5 [ - >>+ ;p7
[-<+>[-<+>[-<+>[-<+>[-<+>[-<+>[-<+>[-<+>[-<+>[-<+>
[-<+>[-<+>[-<+>[-<+>[-<+>[-<+>[-<+>[-<+>[-<+>[-<+>
[-<+>[-<+>[-<+>[-<+>[-<+>[-<+>[-<+>[-<+>[-<+>[-<+>
[-<+>[-<+>[-<+>[-<+>[-<+>[-<+>[-<+>[-<+>[-<+>[-<+>
[-<+>[-<+>[-<+>[-<+>[-<+>[-<+>[-<+>[-<+>[-<+>[-<+>
[-<+>[-<+>[-<+>[-<+>[-<+>[-<+>[-<+>[-<+>[-<+>[-<+>
[-<+>[-<+>[-<+>[-<+>[-<+>[-<+>[-<+>[-<+>[-<+>[-<+>
[-<+>[-<+>[-<+>[-<+>[-<+>[-<+>[-<+>[-<+>[-<+>[-<+>
[-<+>[-<+>[-<+>[-<+>[-<+>[-<+>[-<+>[-<+>[-<+>[-<+>
[-<+>[-<+>[-<+>[-<+>[-<+>[-<+>[-<+>[-<+>[-<+>[-<+>
<<<<-
+++++++++++++++++++++++++++++++++++++++++++++++++.
-------------------------------------------------
>- ;p4
>[-] ;p5
>>>[-]
<
[
-
]
]]]]]]]]]]
]]]]]]]]]]
]]]]]]]]]]
]]]]]]]]]]
]]]]]]]]]]
]]]]]]]]]]
]]]]]]]]]]
]]]]]]]]]]
]]]]]]]]]]
]]]]]]]]]]
<<<+ ;p4
<<+ >+ ;p3
[
-
>>>
[
-
>+
<
]
<<< ] >> ;p5
]
< ;p4 [ - >+ ;p5
< ] >>>> ;p8
]
<<<<<<+ [- >>>>>
[
-
<<<<<<<<<<<<<<<<+ ;p247 >>>>>>>>>>>>>>>>
]
<<<<<[-]
]
<<<<<<<<<<<
]

  • Sort the given string alphabetically.

Input : harshalpatil
Output: aaahhillprst
>, ;p2
----------
[++++++++++
>>>>, ;p5
----------> ;p6
]
<
[++++++++++
<<
[<]
<< [ ;if nonzero >>>
[>]
>>+
[
[-]
<<<
[<]
<< [>+>>
[>]
>>>+
<<<<
[<]
<
[<+ >-
] ;checkin and restorinG
>>
[>]
>
[>
+>>
+<<
[<+>-]
>>
[->
+>+
<<] >
[-
<
]
>>>
[< [>>>-
<<< [-] ] >>
]
<< ] >>>+
[
-
<<<<<< [-] + >>>>>>
]
<
[-]
<
[-]
<
[-]
<[-]
<[-]
< [ [>+
<-
]
<<<
[<]
<< [>>+
<<-
]
< [ [>+
>>
[>]
>>>+
<<<<
[<]
<< ] >
[<+>-]
>>
[>]
>>
]
>
[-
[
<+ >-]
]
<
]]
<
[
<<
[<]
<+>>
[>]
>-
]
<<
[<] >
[
[
<+ >-
]
>
]
>>,
----------]
<<<<
[<] >
[.
>
]
++++++++++. ;printin in alphabetical order

That's it. These were the four programs that helped me to get in to the finals :-)

This is a simple app that i made two years back.  In the below post i will be sharing simple steps to  create a twitter app using OAuth.

  • So What is OAUTH ?

WikiPedia has a good explanation on this. We are using OAuth, because twitter moved from Basic Auth to OAuth by mid of 2010 .

Ok so lets create the app in six simple steps. In this twitter app for  dummies, we will try to find the followers of a user.

Step 1:  Follow the link and create a new App by giving  all those blah blah things required. Register your new app .

Step2 :  Go to Twitter Apps Page and find your registered app.  We will be demonstrating a simple app that requires only the access token of a single user . This is provided by twitter  as an example for Single User OAuth Example. So we need the Access token and Access token secret for the user who created the app ( Yea that’s you :-) ). So for  this go to the bottom of the page and there you can see Your Access Token.

Step3 :  Generate your access token and copy it down.  Need to copy Access Token, Access Token Secret. Also note down the Consumer key and Consumer Secret from the same page.

Step 4: Select a twitter api library in any language to make the app. I used tweepy which is a python twitter api library.

Step5: Use tweepy to authenticate using OAuth.

access_key = "replace this with the Access Token you noted down"
acess_secret = "replace this with the Access Token Secret you noted down"
consumer_key = "replace this with the Consumer Key you noted down"
consumer_secret =replace this with the Consumer Secret you noted down"
auth = tweepy.OAuthHandler(consumer_key, consumer_secret) 
auth.set_access_token(accesskey, accesssecret)

Step 6: Now that we are ready with auth. We will call the api, authenticate and do our stuff.

api = tweepy.API(auth)
 
#print the followers
for follower in tweepy.Cursor(api.followers).items():
    print follower.screen_name

Bingo!! Our App is ready

Web scraping is the easiest job you can ever find. It is quite useful because even if you don’t have access to database of the website , you can still get the data out of those sites using web scraping. For web data extraction we are creating a script that will visit the websites and extract the data you want, without any extra authentication and with these scripts its easy to get more data in less time from these websites.
I always relied on python to do tasks and in this too there is a good third party library, Beautiful Soup. The official site itself have good documentation and it is clearly understandable. For those who don’t want to read that lengthy one and just want to try something using Beautiful Soup and python, read this simple script with the explanation.
Task : Extract all U.S university name and url from University of texas website as a csv ( comma-seperated values ) format.
Dependencies : python and Beautiful Soup

Script with explanation:

from BeautifulSoup import BeautifulSoup
import urllib2

 

We have to use urllib2 to open the URL. Before we proceed further we should know these things. Web scraping will be effective only if we can find patterns used in the websites for denoting contents. For example in the university of texas website if you view the source of the page then you can see that all university names have a common format like as shown below in the screeshshot

View Source
Patterns found in the Texas university page

 

 

 

 

 

 

 

 

url="http://www.utexas.edu/world/univ/alpha/"
page=urllib2.urlopen(url)
soup = BeautifulSoup(page.read())

Here we opened the university of texas using urllib2.urlopen(url) and we create a BeautifulSoup Object using soup = BeautifulSoup(page.read()) . Now we can manipulate the webpage using the methods of the soup object.

universities=soup.findAll('a',{'class':'institution'})

Here we used the findAll method that will search through the soup object to match for text, html tags and their attributes or anything within the page. Here we know that university name and url has a pattern which has the html tag ‘a’ and that tag has css class ‘institution’.
So that’s why we used soup.findAll(‘a’,{‘class’:'institution’}). The css class institution actually filtered the search otherwise if we simple give findAll(‘a) , script could have returned all the links within the page. We could have done the same thing using regular expression but using BeautifulSoup is more better in this case compared to regexp.

for eachuniversity in universities:
print eachuniversity['href']+","+eachuniversity.string

Here we traversed thorugh the list of universities. During execution of the loop. eachuniversity['href'] will give us the link to the university because in the initial pattern we saw that the link to each university is within the ‘a’ tag’s href property and the name of the university is the string following the ‘a’ tag and that’s why we used eachuniversity.string.


from BeautifulSoup import BeautifulSoup
import urllib2
url="http://www.utexas.edu/world/univ/alpha/"
page=urllib2.urlopen(url)
soup = BeautifulSoup(page.read())
universities=soup.findAll('a',{'class':'institution'})
for eachuniversity in universities:
print eachuniversity['href']+","+eachuniversity.string

Download BeautifulSoup, install it and run this script you can see around 2128 U.S university names along with their url.

Recently there was a ranking made by Mediabistro.com about the Twitter’s all-time top 10 tweeters based on the number of submissions. Now, that was a surprising news, because during the early days of freelancing i wrote a twitter bot for a friend ( initially my client but now a good friend ), and so according to mediabistro my bot is ranked 5 among the top 10 tweeters.

The bot is notiven and its for a spanish website Notiven.com, which is one among the best news website in venezuela.

@notiven is in the one million tweet club :)
My bot is ranked 5 among the top 10 with

  • One million tweets
  • The highest number of followers ( within the club )
  • Average 695 tweets per day
  • 6,179 followers

@notiven is very simple ( as you can see its just doing retweet of other tweeples ) but it serves its purpose. Tweepy,Twitter Api library using Python, was used for developing @notiven .

Digital Signal Processing was one among the tough subjects that i studied during my B-Tech life. Finding DFT was a challange at that time (now too ). It was hard because you need to do a lot of calculations in minimum time and the worst thing,  to draw the magnitude plot after calculating all those stuffs.

So we were asked to create an online DFT calculator which will help to do things very easily. My friend fayaz did the initial python script and later i changed little bit on it to present it via Web.
I used the Google Chart api for the magnitude plot ( It is not perfect but it still works. )

You can see the live demo over here. Students of B-Tech in India may be having this as a part of their academics, so you people can try it just once (or more if you like it :) ).

The user interface is very very simple, I didn’t try to design a good one, sorry :(

The calculator is simple with just one html file and a python script.

The answer is simple use Mobile BroadBand available with the network connection manager.

These are the important points for the experienced guys in Linux.

OS : Ubuntu 9.04

APN: uninor

Dns Servers : 208.67.222.222, 208.67.220.220

For beginners, Follow these steps.

Step1: Go to the network manager Applet on the top panel and add a new mobile broadband connection.
Step2 : Connection Wizard will help you in creating a new connection. Select your country and on the networks service provider, Select any network service provider. ( I selected Country as India and provider as Airtel,  because for Ubuntu 9.04, Airtel was default service provider)

Step 3: Name the connection as Uninor ( or the name you like foo :)   ).

Step 4: Again took the network manager applet and on mobile broadband select connection named Uninor and edit it.

Step 5: Edit these informations.

APN: uninor
Dns Servers : 208.67.222.222, 208.67.220.220

Step 6: Apply and then connect, that’s it.

Mobile broadband connection ‘Uninor’ Active

Screenshots

Freelancing has become very common now a days. Large number of freelance sites are there in the WWW. I would like to mention three important sites that i feel good to work with.

I started my career as a freelancer, while i was in the second year of the BTech programme.

It has been wonderful experience after being a freelancer. I could work in the free times, after my school, When i am bored, and the result always was satisfaction + some income. I have seen lot of bids ( around thousands ) in my entire Career and have seen the general trend of getting a job. I am writing my view points on how a good bid should be or how you should look forward to  get a job and also good feedbacks. I would like to put forward 4 rules, that every freelancer should follow.

  1. Bid Seriously.
  2. Do a Research of the task.
  3. Communicate very well with the provider.
  4. Stick to the timeline.

Bid Seriously

This is the golden rule. I have the habit of reading all the bids that is being placed on a particular job request. Of them 70% of the bids came with automated texts. People copy paste texts regarding the company profile, company description and data that is not relevant to the bid request. so while bidding take care of these.

  • Don’t use `copy pasted` texts in the bid request. For example  try to avoid using copy pasted texts like “we have qualified dedicated professionals. We know php joomla blah blah…”
  • Learn the behaviour of the provider by going through his previous works and payment strategies.
  • Read the bid carefully. If you don’t understand try to leave it at the moment itself. If you get something from the bid, then try to bid reasonably by sending a message to the provider along with the bid. You can say like ” I read it carefully , i understand it. We can use so and so”. Trust me the providers look for the quality of bid, how much serious we are.
  • Avoid spelling mistakes while bidding. This will not help to boost you up but the spelling mistakes can cause a negative impact to you.

Research

Do a research regarding the bid request. Try to grab all the data required. For every bid you should do this. You should understand well and this will help you to give very good bid rates. This research will help you to get an idea about the project, complexity involved and eventually will help to make a decision on whether or not to bid on a job. Never bid on a job that you can’t do. I am saying this because i have done mistakes at the early stages and this reduced the number of works that i could have done. Google will be a very handy at this stage. So i would like to say `Google every bid`.

Communicate

This is very important. We should always be in communication with the provider either via text chatting or skype or gtalk or anyways they demand. Communication can be done in this fashion

  1. Before starting the work, just confirm the things you are going to do, this will help in achieving the output without any delay. Also the provider will be very much appreciate your efforts to understanding his requirements and working accordingly.
  2. During the work always update him whenever  you achieve some goals or progress in the project. This updates will help you to prove yourself  as a good programmer or freelancer to him. Eventually this will help to get you good feedbacks even if you can’t complete the project due to some dependency issue within the application or due to some other reasons.
  3. Before getting a job there is an interview phase and if some provider opened chat with you, at that point of time you can impress him by showing some of the works that you did.
  4. Most of the providers care about the communication.

Stick to the deadlines

  1. Make it as a habit. Otherwise you are going to get negative feedbacks and probably that may be the end of your career. You should take care of this during the bidding stage itself.
  2. Ask for renewal of the deadline. You can ask for the renewal of deadline, if you have achieved significant progress in the project and the provider is very much satisfied with your work.

PS : Everything that posted here is from my experience, its always better to develop a style that is unique.