VIM : Enable syntax highlighting for other file extensisons

Couple of days back i came to know about JavaScript code modules. Such files have an extension of .jsm and are not highlighted in Vim by default. Running the command

set filetype=javascript everytime is not the best way to do things.

So, now we just need to check if the file extension is .jsm and then run the set filetype command.

Adding the following lines to ~/.vimrc should do the trick

au BufNewFile,BufRead *.jsm set filetype=javascript

Note: that we should have the following lines in our .vimrc file

syntax on
filetype on

If you want to know more about au,BufNewFile,BufRead type :help [command] in your vim and that should give all that’s required.

Creating a list rotator using about 10 lines of mootools code :)

Well recently i had to design a list rotator and use mootools to create the effect. Did some thinking and got a simple logic to do so . Remove the first element, get the list and append the data of the first element to the list. Well so it rotates and the effect looks cool. Here is a working demo of the script and yeah the HTML, CSS and JavaScript has been written below.

Demo Here

The HTML

    <ul id="rotate">
        <li>"Courage is the discovery that you may not win, and trying when you know you can lose."</li>
        <li>If you only do what you know you can do- you never do very much.</li>
        <li>There are no failures - just experiences and your reactions to them.</li>
        <li>Being deeply loved by someone gives you strength, while loving someone deeply gives you courage.</li>
        <li>Time goes by so fast, people go in and out of your life. You must never miss the opportunity to tell these people how much they mean to you.</li>
        <li>It's kind of fun to do the impossible.</li>
        <li>Live as if you were to die tomorrow. Learn as if you were to live forever.</li>
        <li>Design is not the narrow application of formal skills, it is a way of thinking</li>
        <li>Good design goes to heaven; bad design goes everywhere</li>
        <li>Designers are meant to be loved, not to be understood</li>
    </ul>

The Css

        #rotate{width:400px; height:320px; overflow:hidden;}
        #rotate li{display:block; padding:10px 20px; margin:5px; border-bottom:1px dotted #ccc; list-style-type:none; height:50px; overflow:hidden; font-size:14px;}

The Javasccript

    window.addEvent('domready', function() {
        function rotateList(){
            first=document.getElement("ul#rotate > li");
            text = first.get('html');
            first.set('morph', {duration:1000 , transition: 'linear'});
            first.morph({opacity:0,height:0,marginTop:0,marginBottom:0,paddingTop:0,paddingBottom:0,"background-color":"#FFD"});
            (function(){first.dispose()}).delay(1000);
            var newli=document.createElement("li");
            newli.innerHTML=text;
            document.getElementById("rotate").appendChild(newli);
        }
        interval = setInterval(rotateList, 5000);
    });

Well and if we want the list to rotate the other way round, remove the last element and add it to the top . We can take a look at the js snippet below.

JavaScript for the list to rotate other ways

        function rotateList(){
            first=$$("#rotate li");
            lastli=first[first.length-1];
            text=lastli.innerHTML;
            lastli.dispose();
            var newli=document.createElement("li");
            newli.innerHTML=text;
            newli.set('styles',{
                opacity:0,
                height:0,
                marginTop:0,
                marginBottom:0,
                paddingTop:0,
                paddingBottom:0
                });

            var inserted = document.getElementById("rotate").insertBefore(newli, first[0]);
            inserted.morph({height:30,marginTop:5,marginBottom:5,paddingTop:0,paddingBottom:10});
            (function(){inserted.fade('in')}).delay(500);
        }

         interval = setInterval(rotateList, 2000);

Click here to check the Demo

Well and if u are interested in some more javascript awesomeness check out the following posts:

Right Click menu, Awesomeness

Nifty navigation effect using jQuery and CSS

Any issues use the comment box below

Right click menu, awesomeness

If you have not seen this effect in action, i recommend you to visit akismet.com and right click on their logo, else here is a Demo that i made. I’ve got to say seeing this in the akismet site was quite inspiring. Well, isn’t it a cool effect and I have got to say they have used this in the best way possible.

If it is “How” that has been hitting you, i have included a snippet of the HTML and Javascript below.

The HTML

 <div id="about-me">Image<br /> <h1>Shashabooey!</h1></div>
 <div id="logo">A.Vi.Nash</div>

The CSS

#about-me{display:none;opacity:0;}

The Javascript

                $(document).ready(function () {

                $("#logo").bind('contextmenu',function(e){
                    e.returnValue= false;
                    return false;
                }).bind('contextmenu',function(e){
                    setTimeout('$("#about-me").fadeIn().animate({height:"280px",opacity:1},400)',400);
                        e.PreventDefault();
                        });
                $("#about-me").bind('click',function(e){
                    $(this).animate({height:"0px",opacity:0},400);
                    });
                });

Check out the Demo here

Do try this effect, and do share what more awesome things you’ve done using this effect.

Don’t focus on me, Dim others. Cool effect via CSS3 or jQuery

In this effect, instead of the element in focus having some changes, rest of the elements go DIM or have a decreased opacity so that the elements outstands. Here is a Demo and a basic code for the effect can be found below

The HTML

		<div id="navigation">
			<ul>
				<li><a href="http://blog.avinash.com.np">Home</a></li>
				<li><a href="#">About</a></li>
				<li><a href="#">Contact</a></li>
				<li><a href="#">Details</a></li>
				<li><a href="#">Feedback</a></li>
			</ul>
		</div>

The CSS

            #navigation{
                border-bottom:1px solid #777;
				color:#000;
				height:31px;
				font-family:ubuntu;
			}
			#navigation ul{
				list-style-type:none;
				margin:0px;
				padding:0px;
				margin:0px 3px;
			}
			#navigation ul li{
				display:inline-block;
				margin:3px 0px;
				height:23px;
				text-align:center;
                border-right:1px solid #777;
			}
			#navigation ul li a{
                font-family:'Artifika',arial,serif;
				padding:0px 20px;
				margin:0px 10px;
				color:#000;
                text-decoration:none;
                text-shadow:1px 1px 1px #ccc;
            }

Using jQuery for the Effect

			$(document).ready(function () {
			$("div#navigation ul li a").hover(function()
            {
                $("div#navigation ul li a").stop().animate({opacity:0.2},400);
                $(this).stop().animate({opacity:1},1);
			},
			function(){
                $("div#navigation ul li a").stop().animate({opacity:1},400);
				});

			});

Using CSS3 Transistions

The CSS Rules will have to be changed accordingly.

	#navigation ul li a{
                font-family:'Artifika',arial,serif;
				padding:0px 20px;
				margin:0px 10px;
				color:#000;
                text-decoration:none;
                text-shadow:1px 1px 1px #ccc;
                -webkit-transition: opacity 1s ease-in-out;
                -moz-transition: opacity 1s ease-in-out;
                -o-transition: opacity 1s ease-in-out;
                -ms-transition: opacity 1s ease-in-out;
                transition: opacity 1s ease-in-out;
            }
            #navigation ul:hover > li a {opacity:0.2;}
            #navigation ul:hover > li a:hover {border-bottom:2px solid #c21; opacity:1;}

Using this simple technique a very classy effect can be created

Some more navigation techniques can be found here and here (lavalamp effect)

Nifty navigation effect using jQuery and CSS

Designing navigation is one of the most important part of the web development cycle. It becomes more important because each site requires its own type of navigation and not to forget, people do like to see something different in their website.

Here’s an example of the navigation in action

To start with, the only tricky part in this navigation is the movement of the background. It’s actually all background-position magic. Who knew one property could be used in so many ways to create so many more effects

The HTML

		<div id="navigation">
			<ul>
				<li><a href="http://blog.avinash.com.np">Home</a></li>
				<li><a href="#">About Us</a></li>
				<li><a href="#">Contact</a></li>
				<li><a href="#">Details</a></li>
				<li><a href="#">Feedback</a></li>
			</ul>
		</div>

The CSS

		#navigation{
				color:#000;
				width:250px;
				font-family: 'Artifika', arial, serif;
				font-size:16px;
			}
			#navigation ul{
				list-style-type:none;
				margin:0px;
				padding:0px;
			}
			#navigation ul li{
				display:block;
				background:#eee;
				text-align:right;
				margin-bottom:2px;
			}
			#navigation ul li a{
				display:inline-block;
				padding:2px 7px 2px 25px;
				background:url(nifty-navigation-bg.jpg) no-repeat;
				background-position:0px 0px;
				color:#000;
				text-decoration:none;
			}

The Javascript

		$(document).ready(function () {
				$("div#navigation ul li").hover(function(){
					var a=$(this).find('a:first');
					_width=a.width()+32;
					a.stop().animate({"background-position" : _width+"px 0px"},200);
				},
				function(){
					var a=$(this).find('a:first');
					a.stop().animate({"background-position" : "0px 0px"},200);
				});

Well, that’s one simple method to get the effect. If any other methods are available, do let me know.

If this was not enough, here’s another navigation effect, one of my favourite the Lavalamp effect

A picture is worth a thousand words

Morning Freshness

The right temperament, four years of engineering

Disclaimer : This article is a compilation of my say about four years of college, things that i wish people told me, things that people told me and helped me make a difference and yeah, of course things that i want to say :). It would also be a a lot biased towards computer engineering (obvious reasons).

College is a lot different than school, a lot lot different. Full freedom, no teachers, bunking classes is regular, going classes is a once in a while thing, friends are family, family is now a phone call away. Yeah, I know howmuch fun college is but on a seious note we should never forget the primary reason we joined the college,

First year of College

  • Make Friends, lots and lots of them.
  • Find people who share a similar interst you have and if you are not sure about your interests, make sure by the end of this year.
  • Learn the habit of learning
  • Do what you think is interesting, and don’t feel shy to share it with the world.Check this video, really inspiring.
  • Classes are important but not more than exams. By the end of first year it would be obvious that studying 2 days before the exam is more than enough.

Second year of College

  • This is the most important year of college.
  • Data Structures is very important, learn it, love it and don’t forget.
  • Take part in programming competitions, online contests.
  • Try to be a part of an open source project, try to submit a patch for one or too, it maybe used, maynot be, but the best part is you’d learn.
  • If you don’t understand in class then very good, neither did we, but ask a couple of questions to the faculty just to confirm if it is a period worth bunking.
  • Toward the end of this year, apply for training or some project (in a reputed university). Try out for Google Summer of Code, or maybe apply to an open source project for a summer intern.
  • And yeah, the most important have fun, try going out everyday, move around. Nothing is better than a cup of chai with friends @galla.

Third year of College

  • Now, this is when things start warming up and you start to feel the pressure.
  • CAT CAT everywhere, not a TIGER to see .. haha . I can’t say when do you go for an MBA but i can surely say don’t go for one if you are really interested in Computers ( Other Department people, just replace with whatsover is the alternate .).
  • One point is very clear, programming or writing programs is a kid’s job, but writing the perfect program, with the most optimized algorithm is what is awesome.
  • Learn algorithms, if you have been participating in online competitons then you must know how interesting it is.
  • Once again, towards the end take on a project, work on it, have fun. If u had contributed to some open source project before and have continued, most chances are you would be very close to the team by now, so you have a whole world of opportunities in front of you.
  • If furthur study is what you wish to do next, its high time you give GRE, TOEFL … and all those 3 Letter words :-P

Final year ( The End, that’s what i’m talking about)

  • Take up a project that you would love to work on, and seminar something that you’ve wanted to learn or try.
  • Have Fun, a lot of fun.
  • Placement is just another thing, dont’ worry.
  • Once again, Have FUN!

An Important Issue :

Recently, I was also thinking that why do most of the tech startups or the awesome ideas that totally change the world come from some place on the other side of the globe. If they can why not someone in India? No, it’s really hard to. Why? It’s because the way we are taught, the way colleges run. Colleges are just making the next lot of engineers, they are not making thinkers, not innovators. But, again, it doesn’t mean we can’t. It’s high time we take a shift in paradigm, try to do some interesting stuff in college, mix it with all the awesome fun we are having.

That’s all for now. I’ve a lot, seriously a lot to say. Any issues or suggestions, pop up a comment below.

CSS Sprites – What? Why? and How?

I had this article on the pipeline for quite too long and right when i was in the middle of it, i found the best article (http://css-tricks.com/css-sprites/)that says exactly what i wanted to, but in a much better way. So, why waste energy writing an article that has already been :).

Other awesome articles regarding CSS Sprites

Have Fun!

Yup! the countdown has begun

The Beta is really great, the response is awesome. The system does crash at times (amd64), but hope that will be taken care of by the final release. All in all, seems worth the wait !

The next version of Ubuntu is coming soon

The Previous page, Next page dilemma

I don’t know why i never thought of this but recently, i just landed to a random page of a blog. Now, i wanted to see some older posts but there were two links “Next Page” and “Previous Page” . Frankly speaking this is a little too confusing because in one way, i had to go to the next page but then, if it was according to posts and dates then i had to go to the previous page.

I think it would be better to have links like Previous posts and then Newer posts. Wouldn’t it ???

Is it just me or is it really confusing ?