Skip to content

Instantly share code, notes, and snippets.

@utgarda
Created April 3, 2012 12:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save utgarda/2291690 to your computer and use it in GitHub Desktop.
Save utgarda/2291690 to your computer and use it in GitHub Desktop.
CoffeeScript + jQuery tutorials: Evil Twins hunt
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
$j('#query').click ->
getMyInfo (resp) ->
fillTable $j("#myinfo"), resp
getEvilTwinInfo resp, (twinResp) ->
if twinResp
fillTable $j('#twininfo'), twinResp
else
$j('#no_twin_msg').show()
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()
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