Showing posts with label javascript. Show all posts
Showing posts with label javascript. Show all posts

Wednesday, January 27, 2010

Because if you weren't supposed to abuse the api it wouldn't start with a

Of course, I mean really!

Let me say I have little sympathy with hackers from an ethical, sociological, or philosophical perspective (that's a gross exaggeration, I mean ewww, but to explicate the matter would be an even more gross waste of time)

But when it doesn't hurt, or waste people's time, or screw with peoples stuff, etc., why not tae things apart and then put them together in different ways so you can take it apart again, and so on, and so forth, and thus I decided to conduct a reflection upon the window object of javascript.

Since my sign off would be far too down at the bottom of the page let me sign off before the mark, because I can. So take it to your head, take it to your heart and remember Rand rocks. Goodnight Folks!

And God Bless.

Tuesday, October 20, 2009

Because the hand that feeds tastes good

Indeed!
Even when it's your own... But that's another story...
and here's Nine Inch Nails!!

And now for something completely different...

Twitter has been good to me, more or less. By providing a new platform for my largely nonsensical rants, twitter has been feeding followers and readers into the maw of my endless ambition, and on my end I have been mildly abusive to it. Not really, but pretending in that vein, I have mildly abused the twitter api to draw out and play with the vaguely relevant json data from my twitter feed and that of others.

What do I mean? Nothing really, I actually was going to write something quite meaningful today, but..

Anywho, these are some example twitter api calls:

http://twitter.com/statuses/[followers|friends|user_timeline]/[screen-name].[format (ie, xml, atom, json, etc.)]

in addition you can throw in GET arguments like page=# and count=# or callback=function for the json format in particular.

Thus to call the third page of therandshow twitter feed in json with 20 results per page and send it to a callback called karl do thus:

http://twitter.com/statuses/user_timeline/therandshow.json?count=20&page=3&callback=karl
(note: you must have already declared a function named karl to callback to, else the Karl's won't come home no matter how hard you call)

Now you might say to yourself: "Hey this seems vaguely useful, but how can I waste that usefulness while helping to strain twitter's resources until it's inevitable implosion?"

Glad you asked Jim, not so glad you asked Sally.

Here's a sample use (and let me credit jquery for making this example within the reach of my immense laziness), and by sample I mean something I did to kill time and decided to half-justify by putting onto the web - behold twitter results displayed by day!

Dun-dun-dun!!!


<html>
<head>
<title>Abusing Twitter Every Day</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
<script type="text/javascript">
function twitterCallback2(twits) {
twittier = [{date:0,tweets:[]}];
j=0;

for(i=0; i < twits.length;i++) {
settable = new Date();
settable.setTime(Date.parse(twits[i].created_at));
if(twittier[j].date==0) {
twittier[j].date = settable;
twittier[j].tweets.push(twits[i]);
dte =Date(twittier[j].date);
}
else if(twittier[j].date.getDay()!=settable.getDay()) {
j++;
twittier.push({date:settable,tweets:[twits[i]]});
}
else {
twittier[j].tweets.push(twits[i]);
}
}
str="";
for(i=0; i < twittier.length;i++) {
str += "<div><h2>"+twittier[i].date+"</h2>";
for(j=0; j < twittier[i].tweets.length;j++) {
for(k in twittier[i].tweets[j]) {
if(k!='user') {
str+= "<p>"+k+" : "+twittier[i].tweets[j][k]+"</p>";
}
else {
/* if you want for some reason to also display the your own user object */
str+= "<p>"+k+" : "+twittier[i].tweets[j][k].toSource()+"</p>";

}
}
// str+= "<pre>"+twittier[i].tweets[j].toSource().replace(/,/g,",\n")+"</pre>";
}
str+= "</div>";
}
$("#holder").append(str);
}
</script>
</head>
<body>
<div id="holder">
</div>
<script type="text/javascript" src="http://twitter.com/statuses/user_timeline/therandshow.json?count=100&page=1&callback=twitterCallback2"></script>
<script type="text/javascript" src="http://twitter.com/statuses/user_timeline/therandshow.json?count=100&page=2&callback=twitterCallback2"></script>
<script type="text/javascript" src="http://twitter.com/statuses/user_timeline/therandshow.json?count=100&page=3&callback=twitterCallback2"></script>
<script type="text/javascript" src="http://twitter.com/statuses/user_timeline/therandshow.json?count=100&page=4&callback=twitterCallback2"></script>
<script type="text/javascript" src="http://twitter.com/statuses/user_timeline/therandshow.json?count=100&page=5&callback=twitterCallback2"></script>
<script type="text/javascript" src="http://twitter.com/statuses/user_timeline/therandshow.json?count=100&page=6&callback=twitterCallback2"></script>
<script type="text/javascript" src="http://twitter.com/statuses/user_timeline/therandshow.json?count=100&page=7&callback=twitterCallback2"></script>
</body>
</html>



and so there it is. Rather random and vaguely cool, n'est pas? Just like my random evocation of my 3 years of middle school French.

So take it to your head, take it to your heart and remember Rand rocks. Goodnight Folks!

And God Bless.

Wednesday, August 12, 2009

How to turn a Facebook Friends List into a CSV

So here's a little something for some people who like to use things that are not nothing but rather are something, a how-to if you will, to translate a Facebook friends list into a CSV:

Facebook, it is designed to let you keep in contact with people.
Yet as most know it is not the end all of human interaction. Despite this
fact, the makers of Facebook have not made it easy to take the contact
information in Facebook and get it out.


However, where there is a will there is a way. Actually there are
many ways. Indeed there are many tools you could use for this purpose,
from the Facebook API to a Greasemonkey script. But when it comes to ad
hoc manipulation of random websites with a minimum of fuss, and perhaps
a little leeway timewise, my tool of choice is Firebug.


And thus here is a function one can put into the Firebug console and
then execute for gathering all the Facebook contact info from a My
Friends page into a CSV file (or actually a new window which can be
saved as a text file and will then become a CSV), which can be easily
imported to your email client or even phone.


NOTE: it's been a little while since I've worked on this code,
and there might be some flaws in it. No guarentee.




function fbcontactexport() {
items = document.getElementsByClassName('UIObjectListing');
datastr = "name, group1, group2, cellphone, landphone";
for(i=0; i < items.length; i++) {
datastr += "\n";
names = items[i].getElementsByClassName('UIObjectListing_Title');
if(names.length > 0) {
datastr += names[0].childNodes[0].nodeValue;
}
datastr += ",";
subtitle = items[i].getElementsByClassName('UIObjectListing_Subtitle')[0].childNodes;
if(subtitle.length>0) {
datastr += subtitle[0].nodeValue;
datastr += ",";
}
else {
datastr += ',,';
}
subtext = items[i].getElementsByClassName('UIObjectListing_Subtext')[0].childNodes;
if(subtext.length > 0) {
datastr += subtext[0].nodeValue;
datastr += ",";
}
else {
datastr += ',,';
}
cellNum = items[i].getElementsByClassName('FriendsPage_PhonebookCell');
if(cellNum.length > 0) {
datastr += cellNum[0].childNodes[1].nodeValue;
datastr += ",";
}
else {
datastr += ',,';
}
landNum = items[i].getElementsByClassName('FriendsPage_PhonebookLand');
if(landNum.length>0) {
datastr += landNum[0].childNodes[1].nodeValue;
}
else {
datastr += ',';
}
}
nwind = window.open();
nwind.document.write(datastr);
return datastr;
}


One limitation (or at least one big and notable one) though, this only gathers the contacts from a single page in your My Friends
list which, if you have several pages of Friends, means you'll have to
run this script several times. Could it be otherwise? Yes, yes it could.
There are more sophisticated tools as I mentioned (or rather more
appropriate tools as Firebug is amazingly sophisticated for its
primary purpose, that is debugging Javascript). It is likely possible
that a more powerful Firebug script could be written that'll open up
the new pages of friends lists and grab those pages, etc. But this is
a not bad function, and building it just about exceeded my interest in
the subject, so I'll leave it as is for now, or until curiosity strikes
me again like a hurricane.


So take it to your head, take it to your heart and remember Rand
rocks.


Goodnight Folks!


And God Bless.