Skip to content

Instantly share code, notes, and snippets.

View veryeasily's full-sized avatar
🦌

lju veryeasily

🦌
  • Portland
  • 12:19 (UTC -07:00)
View GitHub Profile
@veryeasily
veryeasily / defineGetters.js
Last active December 31, 2015 20:39
This is a quick write up using underscore to create getters from a JSON object. A good use case is when the object is a response from an endpoint.
function defineGetters (context, obj) {
this.get = {};
// we iterate over the object via underscore creating getter functions
_.each(obj, function (val, ind, list) {
this.get[ind] = function() {
return ( !_.isObject(val) || _.isArray(val) ? val : $.extend({}, val, true) );
};
}, this);
}
@veryeasily
veryeasily / gist:5640712
Created May 24, 2013 01:21
Here is this San Francisco topic search with additional logging to show that the whole object with tons of stuff is returned. Make sure to do CTRL-J to open up the console to see the log (of course)
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
</head>
<body>
<script>
var topic_id = '/en/san_francisco';
var service_url = 'https://www.googleapis.com/freebase/v1/topic';
var params = {};