Archive for the 'javascript' Category

19
Mar
11

rails 406 error code when using ajax


I kept receiving a 406 error code when trying to use ajax in a rails app. The problem was that in the request’s Accept header, text/javascript wasn’t included, and this caused the error.
Additionally, I think this may have had something to do with it:

– I was submitting a form when on a select’s onChange handler, by using:


this.form.submit();

I changed it to :


$("#myform").submit();

I’m not really sure if this influenced it in someway, but I said, if I’m still using jQuery to do things, better use it to do everything.

15
Mar
11

simple client side validations using validator


You can find here a nice comprehensive article on simplifying your client side form validations.

Add this to your page:



  $(document).ready(function() {
    $('#form_id').validator();
  });

and it will automatically validate your form when you try to submit it.

24
Oct
10

StackOverflow bookmarklets


Sometimes I like to see only the questions that are interesting for me. For this I made the following bookmarklets:

  1. Show only interesting questions:

    
    var elements = document.getElementsByTagName("div");
    for(var i = 0;i < elements.length;i++) {
      	var one = elements[i];
    	if(one.className != "question-summary narrow tagged-interesting" && one.id.match("^question-summary"))   {
    		one.style.display = "none";
      	}
    };
    void(0);
    
  2. Hide uninteresting questions

    
    var elements = document.getElementsByTagName("div");
    for(var i = 0;i < elements.length;i++){
      var one = elements[i];
      if(one.className == "question-summary narrow tagged-ignored")   {
         one.style.display = "none";
      }
    };
    void(0);
    

To make them work, add a new bookmark to your browser, and in the address bar, add:javascript: and the code of one of the bookmarklets.
HTH.

23
Jun
09

javascript documentation


Tonight, I had to write some JavaScript code, and I wanted to know what are some of the methods of nodes and other stuff. Because I didn’t want to be firebugging them I searched for online documentation.

I’ve found this : http://krook.org/jsdom/index-all.html. It seems complete as far as I can tell, it helped me accomplish what I needed to do.

12
Mar
09

i’m learning web development

In the past few weeks, I had many job offers. All of them were related to web design/web application development. Because my web skills are pretty much non-existent, I had to turn them down.

So, in an effort to become a better developer, I’m learning webpy as a web framework, and mootools as a javascript framework.

Because I don’t want to be reading books and tutorials related to building “web skills”, I decided to learn them by writing an application. I decided to write a microblogging application. Things are going somewhat well … I have a textarea that “resembles” the ones used in this kind of applications ( somewhat functional ). I still have a long way to go, and I’m pretty excited.

02
Mar
09

first class functions in programming languages


I first learned about first class functions in Javascript, and I really loved the possibility of doing something like this :


function x(a,fun) {
  for(var i = 0;i<a.length;i++) {
    fun(a[i]);
  }
}

x([1,2,3],function(x) {
    alert(x);
});

The possibility of passing whatever variable and using it as a function blew my mind 3 years ago. These days I use Javascript very little, I’m doing most of my coding in Java/Python/Ruby. We all know the deal about Java and first class functions ( sucks ). Ruby has lambdas and procs, which, in order to be executed, you must call the call method… so, there’s an extra step you have to make. The closest to Javascript syntax is Python, where you have a function like this :


def x(a,fun):
  for elem in a:
    fun(a)

def show(elem):
  print elem

# and you call it like this:
x([1,2,3],show)

Can your language do this? 🙂




Blog Stats

  • 221,522 hits