Skip to content

Instantly share code, notes, and snippets.

@dhchow
dhchow / gist:1707422
Created January 30, 2012 23:15
AutoSuggest.js
/**
This component suggests items in a drop-down list as the user types.
If an item is selected, the input box is populated, potentially with multiple entries.
Very similar to the Facebook geo targeting UI. Also listens for up and down keystrokes
to navigate the list.
new cotweet.components.AutoSuggest($element, options)
options = {
data: array of { } // Pre-loaded data
@dhchow
dhchow / tynt script (obfuscated).js
Created February 24, 2011 00:16
prettified script located at http://tcr.tynt.com/ti.js which hijacks copy and paste and modifies its contents
//v13 © 2010 Tynt
var Tynt = Tynt || [];
if (typeof Tynt.TIL == "undefined") {
(function () {
var Ka = function () {
var i = document,
m = i.body,
p = i.documentElement,
aa = eval("/*@cc_on!@*/false"),
ba = function (a, b) {
@dhchow
dhchow / JS Quiz
Created February 21, 2011 19:51
JS quiz: What does this method do?
function doesSomething(array){
var result = [];
for (var i = 0, l = array.length; i < l; i++){
var type = Object.prototype.toString.call(array[i]).split(' ').pop().split(']').shift().toLowerCase();
if (type) { flat = flat.concat(/^(array|collection|arguments|object)$/.test(type) ? doesSomething(array[i]) : array[i]); }
}
return result;
}
@dhchow
dhchow / output.po
Created January 7, 2011 21:20
Generated using xgettext command
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#: public/javascripts/cotweet/core/0_TimelineItem.js:18
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
@dhchow
dhchow / livequery-ex.js
Created December 29, 2010 22:27
livequery to dynamically add attributes to elements on creation
$('.pagination a').livequery(function() {
$(this).attr('data-remote', 'true')  
});
$.ajax({
url: 'ajax/test.html',
success: function(data) {
$('.result').html(data);
alert('Load was performed.');
},
failure: function(data){
}
});
<% if flash[:error].present? %>
<h3><%= flash[:error] %></h3>
<% else %>
<div id="fb-root"></div>
<div id="error-message"></div>
<script type="text/javascript" src="http://connect.facebook.net/en_US/all.js"></script>
<script type="text/javascript">
window.fbAsyncInit = function() {
FB.init({
appId : "<%= Facebook::CONFIG['app_id'] %>",
@facebook_me_response = {"id" => "222222"}
@facebook_page_response = {"id" => Factory.next(:medium_id).to_s, "name" => Factory.next(:medium_username), "fan_count" => 22.to_s}
@facebook_accounts_response = [{"id" => @facebook_page_response['id'], "access_token" => "tokenz"}]
Koala::Facebook::OAuth.any_instance.stubs('get_access_token_info').returns({'access_token' => 'token'})
Koala::Facebook::GraphAPI.any_instance.stubs('get_object').with('me').returns(@facebook_me_response)
Koala::Facebook::GraphAPI.any_instance.stubs('get_object').with(@facebook_page_response['id']).returns(@facebook_page_response)
Koala::Facebook::GraphAPI.any_instance.stubs('get_connections').with('me', 'accounts').returns(@facebook_accounts_response)