Skip to content

Instantly share code, notes, and snippets.

$(xml).find("enclosure").each(function(i) {
console.log( $(this).attr('url') ); // note that I'm using $(this) and not i
});
$(xml).find("enclosure").each(function(i) {
console.log( i.attr('url') ); // -> TypeError: i.attr is not a function
});
<section>
<enclosure url="a" />
<other_tag>
<enclosure url="b" />
</other_tag>
</section>
// xml document
var xml = ('<section> ' +
' <enclosure url="a"/> ' +
' <other_tag> ' +
' <enclosure url="b"/>' +
' </other_tag> ' +
'</section> ' )
$(xml).find("enclosure").each(function(i) {
console.log( i.attr('url') );
bookListItem = $('<li book-id=' + id + '><a href="book.html"><h2>' + title + '</h2><p>' + realText + '</p></a></li>');
bookListItem.click(function(){
book_id = $(this).attr("book-id");
localStorage.setItem("id", book_id);
});
// good code
getJSON("https://librivox.org/api/feed/audiobooks/title/^" + input + "?&format=json",
function(url_request) {
url_request.response // -> Object { books: Array[50] }
});
// bad code
var url_request = getJSON("https://librivox.org/api/feed/audiobooks/title/^" + input + "?&format=json");
url_request.response // -> null
@ahirschberg
ahirschberg / llist.c
Created January 16, 2015 19:43
Sam's C Linked List implementation
#include <stdlib.h>
#include <stdio.h>
struct listnode {
int head;
struct listnode *tail;
};
struct listnode *cons(int data, struct listnode *list) {
struct listnode *newlist = malloc(sizeof (struct listnode));
def get_random_number
8 ## <-- number was chosen at random
end
@ahirschberg
ahirschberg / lsp3.rb
Created January 13, 2015 01:02
Liskov Substitution Principal example 3
# Implementation 3
class Base
def get_number
raise NotImplementedError
end
end