Tuesday, May 8, 2012

Backbone passing value to views

var view = new SentenceView({model: sentence}); var rendered = this.template(this.options.model.toJSON());

Tuesday, May 1, 2012

Deleteting All Facebook friend programmatically using fb graph api, mobile fb site, & jQuery + firequery

$.ajax({
  url: "https://graph.facebook.com/me/friends?access_token=AAAAAAITEghMBABoxQhYsFHaMdnQJgJ1BoDbedvjJdadnwsNPJlZBrQcO0n1FUDg68UZCSJZAtV4rorKr1iOBchJSkLiXY2Gizgz8CdsyyyMmPeG6uvX", // get this at http://developers.facebook.com/docs/reference/api/ take the Friends link and replace it.
  success: function(data) {
    console.log(data)
        jQuery.each(data.data, function() {
            $("input[name=friend_id]").val(this.id)
            $("form:first").serialize()
            $.ajax({
                url: "http://m.facebook.com/a/removefriend.php",
                data: $("form:first").serialize(),
                type: "post"
            })
        });
  },
  dataType: "json"
});
 
Use the fb mobile page (where we have confirm delete friend button) to execute this script.

We need firebug & firequery to jquerify this page before we can execute this script.

Basically, this script will fetch your friend id from the fb graph api & submit the confirm delete friend form using each friend id that it fetched.

Tuesday, April 17, 2012

backbone collection view example

//MODEL
var Appointment = Backbone.Model.extend({});

var AppointmentList = Backbone.Collection.extend({
  model: Appointment
});

//VIEWS
var AppointmentView = Backbone.View.extend({
  template: _.template('">' +
                        '<%= title %>' +
                        'x'),
  

  render: function(){
    this.$el.html(this.template(this.model.toJSON()));
    return this;
  }
});

//APPLICATION.JS
var AppointmentListView = Backbone.View.extend({
  render: function(){
    this.collection.forEach(this.addOne, this);
  },
  addOne: function(model){
    var appointmentView = new AppointmentView({model: model})
    appointmentView.render()
    this.$el.append(appointmentView.el)
  }
});

Backbone Basic

var Appointment = Backbone.Model.extend({});
var appointment = new Appointment();
appointment.set('title', 'My knee hurts');
var AppointmentView = Backbone.View.extend({
  render: function(){
    $(this.el).html('
  • ' + this.model.get('title') + '
  • '); } }); var appointmentView = new AppointmentView({model: appointment}); appointmentView; appointmentView.render() $('#app').html(appointmentView.el);

    Monday, March 19, 2012

    Comparison between ruby if and unless


    1.9.2-p290 :035 > unless false
    1.9.2-p290 :036?>   puts 'a'
    1.9.2-p290 :037?>   else
    1.9.2-p290 :038 >     puts 'b'
    1.9.2-p290 :039?>   end
    a
     => nil
    1.9.2-p290 :040 > if false
    1.9.2-p290 :041?>   puts 'a'
    1.9.2-p290 :042?>   else
    1.9.2-p290 :043 >     puts 'b'
    1.9.2-p290 :044?>   end
    b