Created
April 3, 2012 12:44
-
-
Save utgarda/2291690 to your computer and use it in GitHub Desktop.
CoffeeScript + jQuery tutorials: Evil Twins hunt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.publishPost = -> | |
userId = window.fbUserId | |
post = | |
caption: "Evil Twins Hunt" | |
message: "Found an app to check FB for presence of Evil | |
Twins from the Evil Parallel Universe. Be watchful, tovarisch! | |
( And yeah, I also learned how to access FB info and publish | |
feed items from code, which is cool. )" | |
link: "http://coffeequery.blogspot.com/2012/04/hunting-evil-twins.html" | |
FB.api "/me/feed", 'post', post |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
reverse = (s) -> | |
if s.length < 2 then s else reverse(s[1..-1]) + s[0] | |
getEvilTwinInfo = (myinfo, callback)-> | |
myinfo.trimmedEmail = myinfo.email.replace /@.+/, "" | |
reversed = for key, value of myinfo | |
"\"#{reverse (String) value}\"" | |
search = (i = 0) -> | |
if i < reversed.length | |
FB.api '/search', {q:reversed[i],type:'user'}, (resp) -> | |
len = resp.data.length | |
if len | |
callback resp.data[ Math.floor Math.random() * len ] | |
else | |
search i+1 | |
else | |
callback null | |
search() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.fillTable = fillTable = (table, content) -> | |
table.empty() | |
for key, value of content | |
table.append "<tr><td>#{key}</td><td>#{value}</td></tr>" | |
window.getMyInfo = getMyInfo = (callback) -> | |
FB.api '/me', | |
{fields:['id','first_name','last_name','email']}, | |
callback | |
window.showMyProfile = -> | |
window.getMyInfo (resp) -> | |
window.fillTable $j("#myinfo"), resp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment